CentOS7下安裝elasticsearch5.6.3

一、安裝jdk,elasticsearch5.x版本之後須要的是1.8或以上java,下載對應版本jdk,上傳到服務器上html

執行命令解壓java

upload]# tar -zxvf jdk-8u171-linux-x64.tar.gznode

配置環境變量linux

vi /etc/profilebootstrap

在結尾處添加以下代碼,java目錄根據本身填寫情況定vim

JAVA_HOME=/usr/local/jdk1.8.0_171
JRE_HOME=/usr/local/jdk1.8.0_171/jre
CLASSPATH=$JAVA_HOME/lib:$JRE_HOME/lib:$CLASSPATH
PATH=$JAVA_HOME/bin:$JRE_HOME/bin:$PATH安全

保存退出,執行命令服務器

source /etc/profileapp

生效環境變量,測試java是否安裝成功cors

出現如圖顯示,jdk安裝成功

二、上傳elasticsearch包

解壓

tar -zxvf elasticsearch-5.6.3.tar.gz

移動到本身到本身的目錄

mv elasticsearch-5.6.3 /usr/local/

三、新建用戶組及用戶

elasticsearch不容許root用戶啓動服務,因此須要新建用戶及用戶組

groupadd elsearch

useradd esuser -g elsearch

進入es安裝目錄平級目錄,修改文件夾權限

cd /user/local

chown -R esuser:elsearch elasticsearch-5.6.3/

查看目錄權限

四、建立es數據文件夾和日誌文件夾

五、修改es配置文件

進入config目錄編輯elasticsearch.yml

vi elasticsearch.yml

# ======================== Elasticsearch Configuration =========================
#
# NOTE: Elasticsearch comes with reasonable defaults for most settings.
#       Before you set out to tweak and tune the configuration, make sure you
#       understand what are you trying to accomplish and the consequences.
#
# The primary way of configuring a node is via this file. This template lists
# the most important settings you may want to configure for a production cluster.
#
# Please consult the documentation for further information on configuration options:
# https://www.elastic.co/guide/en/elasticsearch/reference/index.html
#
# ---------------------------------- Cluster -----------------------------------
#
# Use a descriptive name for your cluster:
#
cluster.name: sengled-test-lg
#
# ------------------------------------ Node ------------------------------------
#
# Use a descriptive name for the node:
#
node.name: sengled-test-node2
#
# Add custom attributes to the node:
#
#node.attr.rack: r1
#
# ----------------------------------- Paths ------------------------------------
#
# Path to directory where to store the data (separate multiple locations by comma):
#
path.data: /usr/local/elasticsearch-5.6.3/data
#
# Path to log files:
#
path.logs: /usr/local/elasticsearch-5.6.3/logs
#
# ----------------------------------- Memory -----------------------------------
#
# Lock the memory on startup:
#
bootstrap.memory_lock: false
bootstrap.system_call_filter: false
#
# Make sure that the heap size is set to about half the memory available
# on the system and that the owner of the process is allowed to use this
# limit.
#
# Elasticsearch performs poorly when the system is swapping the memory.
#
# ---------------------------------- Network -----------------------------------
#
# Set the bind address to a specific IP (IPv4 or IPv6):
#
network.host: xxx.xxx.xxx.xxx
#
# Set a custom port for HTTP:
#
http.port: 9200
#
# For more information, consult the network module documentation.
#
# --------------------------------- Discovery ----------------------------------
#
# Pass an initial list of hosts to perform discovery when new node is started:
# The default list of hosts is ["127.0.0.1", "[::1]"]
#
#discovery.zen.ping.unicast.hosts: ["host1", "host2"]
#
# Prevent the "split brain" by configuring the majority of nodes (total number of master-eligible nodes / 2 + 1):
#
#discovery.zen.minimum_master_nodes: 3
#
# For more information, consult the zen discovery module documentation.
#
# ---------------------------------- Gateway -----------------------------------
#
# Block initial recovery after a full cluster restart until N nodes are started:
#
#gateway.recover_after_nodes: 3
#
# For more information, consult the gateway module documentation.
#
# ---------------------------------- Various -----------------------------------
#
# Require explicit names when deleting indices:
#
#action.destructive_requires_name: true

執行ES文件,進入到bin 目錄下執行 ./elasticsearch 命令就能夠了,執行 ./elasticesrarch -d 是後臺運行   

若是沒有什麼問題話,就能夠安全生成了;而後執行curl 'http://本身配置的IP地址:9200/' 命令,就出現下面的結果

啓動過程當中可能會出現問題

問題1.max file descriptors [4096] for elasticsearch process is too low, increase to at least [65536]

解決方法:

切到root 用戶:進入到security目錄下的limits.conf;執行命令 vim /etc/security/limits.conf 在文件的末尾添加下面的參數值:

                                    * soft nofile 65536

                                    * hard nofile 131072

                                    * soft nproc 2048

                                   * hard nproc 4096

                               前面的*符號必須帶上,而後從新啓動就能夠了。執行完成後可使用命令 ulimit -n 查看進程數

問題2.max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144]

解決方法:

最大虛擬內存過小
root用戶執行命令:
[root@localhost ~]# sysctl -w vm.max_map_count= 655360
 

ps:別的機器進行訪問時須要開放9200端口和9300端口,9200是http協議端口,9300是tcp協議端口,爲java client服務的。我這裏沒有單獨打開端口,只是關閉了防火強,CentOS7關閉防火牆和CentOS6不同,7的防火牆是firewalld的服務,執行命令

//臨時關閉
systemctl stop firewalld
//禁止開機啓動
systemctl disable firewalld
Removed symlink /etc/systemd/system/multi-user.target.wants/firewalld.service.
Removed symlink /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service.

 

集羣時須要添加一些配置,我搭了三個虛擬機作集羣,想cluster.name相同時發現並非集羣,在es配置文件中須要添加額外配置

discovery.zen.ping.unicast.hosts: ["xxx.xxx.xxx","xxx.xxx.xxx","xxx.xxx.xxx"]
discovery.zen.minimum_master_nodes: 3

解釋說明:
bootstrap.memory_lock: false  這是鎖定內存,在一篇調優文章中這個設置成true時會減小內存交換的消耗,這裏先設置成false
bootstrap.system_call_filter: false  這個配置設置true在CentOS6或以上時會出現錯誤, 由於Centos6不支持SecComp

cluster.name 集羣名字,同一個集羣中使用相同名字,單機就隨意 node.name: node-01 節點名字 node.master: 是否爲集羣的master機器 node.data: true 是否做爲數據節點 network.host: xxx.xxx.xxx.xxx 這個不用天然是配置ip地址的 http.port: 9200 端口號,不配置的話默認9200 discovery.zen.ping.unicast.hosts: [「xxx.xxx.xxx」,」xxx.xxx.xxx」,」xxx.xxx.xxx」] 這個就是配置集羣的時候要用的到了,[]中填上集羣中其餘集羣的ip的地址,若是是master的話請把全部salve的機器地址填上 discovery.zen.minimum_master_nodes: 2 關於這個值配置多少合適的話你們去搜一下,本身權衡一下集羣,這裏我用了3臺機器模擬集羣,因此填上2。 http.cors.enabled: true 這個參數的設置和下面一個配置就關於ip的訪問策略了,若是你發現其餘ip地址訪問不了就有能夠這參數沒有配置 http.cors.allow-origin: 「*」

相關文章
相關標籤/搜索