ES7集羣安裝、配置、卸載

最新下載地址:https://www.elastic.co/cn/downloads/past-releases#elasticsearch

可選版本下載地址:https://www.elastic.co/downloads/past-releases

一、Linux系統參數設置:

文件句柄
vi /etc/security/limits.conf
* soft nofile 65536
* hard nofile 65536
* soft nproc 2048
* hard nproc 4096
#我選擇鎖住swapping因此需要在這個配置文件下再增加兩行代碼
* soft memlock unlimited
* hard memlock unlimited

虛擬內存設置
max_map_count定義了進程能擁有的最多內存區域
vi /etc/sysctl.conf
vm.max_map_count=655360
fs.file-max=655360

/sbin/sysctl -p

二、RPM安裝方式:

rpm -ivh elasticsearch-7.3.2-x86_64.rpm

2.1、啓動

#開機啓動
systemctl enable elasticsearch
systemctl start elasticsearch
systemctl status elasticsearch

如果配置的日誌目錄,和data目錄爲root權限,需要設置爲es的權限
chown -R elasticsearch:elasticsearch /home/elasticsearch/log
chown -R elasticsearch:elasticsearch /home/elasticsearch/data

2.2、卸載

[root@slave1 elasticsearch]# rpm -qa | grep elasticsearch
elasticsearch-7.1.1-1.x86_64
[root@slave1 elasticsearch]# rpm -e --nodeps elasticsearch-7.1.1-1.x86_64
Stopping elasticsearch service... OK
warning: file /var/run/elasticsearch: remove failed: No such file or directory
warning: /etc/elasticsearch/elasticsearch.yml saved as /etc/elasticsearch/elasticsearch.yml.rpmsave
Deleting log directory... OK

三、tar包安裝方式

tar -zxvf elasticsearch-7.3.2-linux-x86_64.tar.gz 

cd elasticsearch-7.3.2/

3.1、目錄結構說明

bin :腳本文件,包括 ES 啓動 & 安裝插件等等

config : elasticsearch.yml(ES 配置文件)、jvm.options(JVM 配置文件)、日誌配置文件等等

JDK : 內置的 JDK,JAVA_VERSION="12.0.2"

lib : 類庫

logs : 日誌文件

modules : ES 所有模塊,包括 X-pack 等

plugins : ES 已經安裝的插件。默認沒有插件

3.2、修改配置文件

vi config/elasticsearch.yml 
cluster.name: lanwon-es-cluster
node.name: node-1
node.master: true
node.data: true
#node.attr.rack: r1
path.data: /elasticsearch/data
path.logs: /elasticsearch/log
bootstrap.memory_lock: true
network.host: 172.16.14.184
http.port: 9200
transport.tcp.port: 9300
discovery.seed_hosts: ["172.16.14.184:9300","172.16.14.185:9300","172.16.14.186:9300"]
cluster.initial_master_nodes: ["172.16.14.184:9300", "172.16.14.185:9300","172.16.14.186:9300"]
#gateway.recover_after_nodes: 3
#action.destructive_requires_name: true
cluster.routing.allocation.cluster_concurrent_rebalance: 32
cluster.routing.allocation.node_concurrent_recoveries: 32
cluster.routing.allocation.node_initial_primaries_recoveries: 32
http.cors.enabled: true
http.cors.allow-origin: "*"
discovery.zen.minimum_master_nodes: 2
bootstrap.mlockall: true


cluster.name: lanwon-es-cluster
node.name: node-2
node.master: true
node.data: true
#node.attr.rack: r1
path.data: /elasticsearch/data
path.logs: /elasticsearch/log
bootstrap.memory_lock: true
network.host: 172.16.14.185
http.port: 9200
transport.tcp.port: 9300
discovery.seed_hosts: ["172.16.14.184:9300","172.16.14.185:9300","172.16.14.186:9300"]
cluster.initial_master_nodes: ["172.16.14.184:9300","172.16.14.185:9300","172.16.14.186:9300"]
#gateway.recover_after_nodes: 3
#action.destructive_requires_name: true
cluster.routing.allocation.cluster_concurrent_rebalance: 32
cluster.routing.allocation.node_concurrent_recoveries: 32
cluster.routing.allocation.node_initial_primaries_recoveries: 32
http.cors.enabled: true
http.cors.allow-origin: "*"
discovery.zen.minimum_master_nodes: 2
bootstrap.mlockall: true

cluster.name: lanwon-es-cluster
node.name: node-3
node.master: true
node.data: true
#node.attr.rack: r1
path.data: /elasticsearch/data
path.logs: /elasticsearch/log
bootstrap.memory_lock: true
network.host: 172.16.14.186
http.port: 9200
transport.tcp.port: 9300
discovery.seed_hosts: ["172.16.14.184:9300","172.16.14.185:9300","172.16.14.186:9300"]
cluster.initial_master_nodes: ["172.16.14.184:9300","172.16.14.185:9300","172.16.14.186:9300"]
#gateway.recover_after_nodes: 3
#action.destructive_requires_name: true
cluster.routing.allocation.cluster_concurrent_rebalance: 32
cluster.routing.allocation.node_concurrent_recoveries: 32
cluster.routing.allocation.node_initial_primaries_recoveries: 32
http.cors.enabled: true
http.cors.allow-origin: "*"
discovery.zen.minimum_master_nodes: 2
bootstrap.mlockall: true

sudo chown -R qyyx:qyyx /elasticsearch/log
sudo chown -R qyyx:qyyx /elasticsearch/data

3.3、啓動

./bin/elasticsearch

3.4、tar包安裝設置開機啓動

sudo vi /etc/init.d/elasticsearch

#!/bin/sh
#chkconfig: 2345 80 05
#description: elasticsearch

export JAVA_HOME=/home/qyyx/tools/elasticsearch-7.3.2/jdk
export JAVA_BIN=/home/qyyx/tools/elasticsearch-7.3.2/jdk/bin
export PATH=$PATH:$JAVA_HOME/bin
export CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
export JAVA_HOME JAVA_BIN PATH CLASSPATH

case "$1" in
start)
    su qyyx<<!
    cd /home/qyyx/tools/elasticsearch-7.3.2
    ./bin/elasticsearch -d
!
    echo "elasticsearch startup"
    ;;
stop)
    es_pid=`ps aux|grep elasticsearch | grep -v 'grep elasticsearch' | awk '{print $2}'`
    kill -9 $es_pid
    echo "elasticsearch stopped"
    ;;
restart)
    es_pid=`ps aux|grep elasticsearch | grep -v 'grep elasticsearch' | awk '{print $2}'`
    kill -9 $es_pid
    echo "elasticsearch stopped"
    su qyyx<<!
    cd /home/qyyx/tools/elasticsearch-7.3.2
    ./bin/elasticsearch -d
!
    echo "elasticsearch startup"
    ;;
*)
    echo "start|stop|restart"
    ;;
esac

exit $?

保存退出,賦予執行權限
chmod +x elasticsearch

sudo chmod +x /etc/init.d/elasticsearch

3.5、添加到開機啓動任務

sudo chkconfig --add /etc/init.d/elasticsearch

如果不設置開機啓動的話,也可以使用service elasticsearch start/stop/restart來操作

 

 

集羣配置:

修改/config下的elasticsearch.yml

集羣名稱,必須一致,
cluster.name:elasticsearch

節點名稱,不可以一樣,這裏按照node-1、node-2、node-3進行命名
node.name:node-1

path.data=/home/elasticsearch/data
path.log=/home/elasticsearch/log
注意:需要進行配置,如果使用默認配置是很危險的。當es被卸載,數據和日誌將完全丟失。可以根據具體環境將數據目錄和日誌目錄保存到其他路徑下以確保數據和日誌完整、安全。

discovery.seed_hosts: ["192.168.171.173:9301", "192.168.0.171:9301","192.168.0.174:9301"]
cluster.initial_master_nodes: ["192.168.171.173:9301", "192.168.0.171:9301","192.168.0.174:9301"]

把 bootstrap.memory_lock: false 註釋放開
是否鎖住內存。因爲當jvm開始swapping時es的效率會降低,配置爲true時要允許elasticsearch的進程可以鎖住內存,同時一定要保證機器有足夠的內存分配給es。如果不熟悉機器所處環境,建議配置爲false。

添加 bootstrap.system_call_filter: false
Centos6不支持SecComp,而es5.2.0版本默認bootstrap.system_call_filter爲true
禁用:在elasticsearch.yml中配置bootstrap.system_call_filter爲false,注意要在Memory的後面配置該選項。

network.host: 192.168.171.173 
是本機ip,一般我們會使用192.168.1.55這種,這裏用的虛擬機所以是10.9.39.13
http.port: 9200 設置端口爲9200
transport.port: 9301

這裏需要配置多個,爲了演示非同一IP段,所以IP段不同
因爲我們搭建了3臺服務器用於演示,所以此處爲三個服務器配置的network.host地址,
discovery.zen.ping.unicast.hosts: [“10.9.39.13”, “10.9.104.184”, “10.9.104.185”]

master集羣中最小的master數量,集羣都是過半投票制,所以3臺服務器設置2個master節點,如果19臺服務器可以設置5個master節點,因爲設置的是最小master節點數量防止宕機過多。
#在Elasticsearch7.0版本已被移除,配置無效
#爲了避免腦裂,集羣的最少節點數量爲,集羣的總節點數量除以2加一
discovery.zen.minimum_master_nodes: 2

http.cors.enabled: true
http.cors.allow-origin: "*"

測試

查看集羣主從分配

http://192.168.0.160:9200/_cat/nodes?v

ip            heap.percent ram.percent cpu load_1m load_5m load_15m node.role master name
192.168.0.160           35          97   0    0.04    0.23     0.22 di        -      node-3
192.168.0.160           15          97   0    0.04    0.23     0.22 dim       *      node-1
192.168.0.160           31          97   0    0.04    0.23     0.22 di        -      node-2

查看集羣狀態

http://192.168.0.160:9200/_cluster/health?pretty

{
  "cluster_name": "my-application",
  "status": "green",
  "timed_out": false,
  "number_of_nodes": 3,
  "number_of_data_nodes": 3,
  "active_primary_shards": 0,
  "active_shards": 0,
  "relocating_shards": 0,
  "initializing_shards": 0,
  "unassigned_shards": 0,
  "delayed_unassigned_shards": 0,
  "number_of_pending_tasks": 0,
  "number_of_in_flight_fetch": 0,
  "task_max_waiting_in_queue_millis": 0,
  "active_shards_percent_as_number": 100.0
}

所有配置詳解:

elasticsearch7.0配置文件詳解 此文件不是集羣生成所用到的文件,只是給大家講解ES7配置文件的詳細說明

vim /usr/local/elasticsearch-7.0.0/config/elasticsearch.yml
cluster.name: ES-Cluster
#ES集羣名稱,同一個集羣內的所有節點集羣名稱必須保持一致

node.name: ES-master-10.150.55.94
#ES集羣內的節點名稱,同一個集羣內的節點名稱要具備唯一性

node.master: true
#允許節點是否可以成爲一個master節點,ES是默認集羣中的第一臺機器成爲master,如果這臺機器停止就會重新選舉

node.data: false
#允許該節點存儲索引數據(默認開啓)
#關於Elasticsearch節點的角色功能詳解,請看:https://www.dockerc.com/elasticsearch-master-or-data/

path.data: /data/ES-Cluster/master/ES-master-10.150.55.94/data1,/data/ES-Cluster/master/ES-master-10.150.55.94/data2
#ES是搜索引擎,會創建文檔,建立索引,此路徑是索引的存放目錄,如果我們的日誌數據較爲龐大,那麼索引所佔用的磁盤空間也是不可小覷的
#這個路徑建議是專門的存儲系統,如果不是存儲系統,最好也要有冗餘能力的磁盤,此目錄還要對elasticsearch的運行用戶有寫入權限
#path可以指定多個存儲位置,分散存儲,有助於性能提升,以至於怎麼分散存儲請看詳解https://www.dockerc.com/elk-theory-elasticsearch/

path.logs: /data/ES-Cluster/master/ES-master-10.150.55.94/logs
#elasticsearch專門的日誌存儲位置,生產環境中建議elasticsearch配置文件與elasticsearch日誌分開存儲

bootstrap.memory_lock: true
#在ES運行起來後鎖定ES所能使用的堆內存大小,鎖定內存大小一般爲可用內存的一半左右;鎖定內存後就不會使用交換分區
#如果不打開此項,當系統物理內存空間不足,ES將使用交換分區,ES如果使用交換分區,那麼ES的性能將會變得很差

network.host: 10.150.55.94
#es綁定地址,支持IPv4及IPv6,默認綁定127.0.0.1;es的HTTP端口和集羣通信端口就會監聽在此地址上

network.tcp.no_delay: true
#是否啓用tcp無延遲,true爲啓用tcp不延遲,默認爲false啓用tcp延遲

network.tcp.keep_alive: true
#是否啓用TCP保持活動狀態,默認爲true

network.tcp.reuse_address: true
#是否應該重複使用地址。默認true,在Windows機器上默認爲false

network.tcp.send_buffer_size: 128mb
#tcp發送緩衝區大小,默認不設置

network.tcp.receive_buffer_size: 128mb
#tcp接收緩衝區大小,默認不設置

transport.tcp.port: 9301
#設置集羣節點通信的TCP端口,默認就是9300

transport.tcp.compress: true
#設置是否壓縮TCP傳輸時的數據,默認爲false

http.max_content_length: 200mb
#設置http請求內容的最大容量,默認是100mb

http.cors.enabled: true
#是否開啓跨域訪問

http.cors.allow-origin: "*"
#開啓跨域訪問後的地址限制,*表示無限制

http.port: 9201
#定義ES對外調用的http端口,默認是9200

discovery.zen.ping.unicast.hosts: ["10.150.55.94:9301", "10.150.55.95:9301","10.150.30.246:9301"]    #在Elasticsearch7.0版本已被移除,配置錯誤
#寫入候選主節點的設備地址,來開啓服務時就可以被選爲主節點
#默認主機列表只有127.0.0.1和IPV6的本機迴環地址
#上面是書寫格式,discover意思爲發現,zen是判定集羣成員的協議,unicast是單播的意思,ES5.0版本之後只支持單播的方式來進行集羣間的通信,hosts爲主機
#總結下來就是:使用zen協議通過單播方式去發現集羣成員主機,在此建議將所有成員的節點名稱都寫進來,這樣就不用僅靠集羣名稱cluster.name來判別集羣關係了

discovery.zen.minimum_master_nodes: 2           #在Elasticsearch7.0版本已被移除,配置無效
#爲了避免腦裂,集羣的最少節點數量爲,集羣的總節點數量除以2加一

discovery.zen.fd.ping_timeout: 120s             #在Elasticsearch7.0版本已被移除,配置無效
#探測超時時間,默認是3秒,我們這裏填120秒是爲了防止網絡不好的時候ES集羣發生腦裂現象

discovery.zen.fd.ping_retries: 6                #在Elasticsearch7.0版本已被移除,配置無效
#探測次數,如果每次探測90秒,連續探測超過六次,則認爲節點該節點已脫離集羣,默認爲3次

discovery.zen.fd.ping_interval: 15s             #在Elasticsearch7.0版本已被移除,配置無效
#節點每隔15秒向master發送一次心跳,證明自己和master還存活,默認爲1秒太頻繁,

discovery.seed_hosts: ["10.150.55.94:9301", "10.150.55.95:9301","10.150.30.246:9301"]
#Elasticsearch7新增參數,寫入候選主節點的設備地址,來開啓服務時就可以被選爲主節點,由discovery.zen.ping.unicast.hosts:參數改變而來

cluster.initial_master_nodes: ["10.150.55.94:9301", "10.150.55.95:9301","10.150.30.246:9301"]
#Elasticsearch7新增參數,寫入候選主節點的設備地址,來開啓服務時就可以被選爲主節點

cluster.fault_detection.leader_check.interval: 15s 
#Elasticsearch7新增參數,設置每個節點在選中的主節點的檢查之間等待的時間。默認爲1秒

discovery.cluster_formation_warning_timeout: 30s 
#Elasticsearch7新增參數,啓動後30秒內,如果集羣未形成,那麼將會記錄一條警告信息,警告信息未master not fount開始,默認爲10秒

cluster.join.timeout: 30s
#Elasticsearch7新增參數,節點發送請求加入集羣后,在認爲請求失敗後,再次發送請求的等待時間,默認爲60秒

cluster.publish.timeout: 90s 
#Elasticsearch7新增參數,設置主節點等待每個集羣狀態完全更新後發佈到所有節點的時間,默認爲30秒

cluster.routing.allocation.cluster_concurrent_rebalance: 32
#集羣內同時啓動的數據任務個數,默認是2個

cluster.routing.allocation.node_concurrent_recoveries: 32
#添加或刪除節點及負載均衡時併發恢復的線程個數,默認4個

cluster.routing.allocation.node_initial_primaries_recoveries: 32
#初始化數據恢復時,併發恢復線程的個數,默認4個

https://www.cnblogs.com/lifengdi/archive/2019/09/16/11525648.html

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章