1.環境準備
三臺機器:
10.1.3.12
10.1.3.13
10.1.3.14
操作系統:CentOS7
java環境:jdk8
es版本:elasticsearch-7.17.4
下載鏈接:https://www.elastic.co/downloads/past-releases/elasticsearch-7-17-4
2.部署步驟
(1)創建用戶
因為es腳本不允許root用戶啟動,因此需要為es單獨創建用戶
#新增es用戶
useradd es
#為es用戶設置密碼
passwd es
(2)下載解壓
#將下載好的elasticsearch-7.17.4-linux-x86_64.tar.gz安裝包上傳至服務器es用戶根目錄下
tar -zxvf elasticsearch-7.17.4-linux-x86_64.tar.gz
mv elasticsearch-7.17.4 elasticsearch
#修改es文件目錄的用戶和用戶組為es
chown -R es:es /home/es/elasticsearch
(3)創建es的data目錄
cd /home/es/elasticsearch
mkdir data
chown -R es:es /home/es/elasticsearch/data
(4)修改第一個節點的es配置文件
主要修改如下幾處配置:
cluster.name:集群的名稱,集群中所有節點的 cluster.name 的值必須要相同。
node.name:集群中每個Elasticsearch的節點名稱,不可以重復。
path.data:設置存放Elasticsearch索引文件數據的路徑。
path.logs:設置存放日志文件的路徑。
network.host:Elasticsearch綁定的IP,外界可以通過這個IP訪問到當前Elasticsearch節點,配置當前系統的IP。
http.port:當前啟動Elasticsearch的端口號,默認 9200 ,可以修改
discovery.seed_hosts:配置所有Elasticsearch節點綁定的IP地址。
cluster.initial_master_nodes:配置那些節點可以有資格被選為主節點。
# ---------------------------------- Cluster -----------------------------------
# Use a descriptive name for your cluster:
#設置集群名稱
cluster.name: my-application
# ------------------------------------ Node ------------------------------------
# Use a descriptive name for the node:
#設置節點名稱,不同節點名稱不可相同
node.name: node-1
# ----------------------------------- Paths ------------------------------------
# Path to directory where to store the data (separate multiple locations by comma):
#設置es的數據存儲目錄
path.data: /home/es/elasticsearch/data
# Path to log files:
#設置es的日志存儲目錄
path.logs: /home/es/elasticsearch/logs
# ---------------------------------- Network -----------------------------------
#
# By default Elasticsearch is only accessible on localhost. Set a different
# address here to expose this node on the network:
#節點的ip地址,也可以定義為host名稱但前提是hosts文件已配置
network.host: 10.1.3.12
# By default Elasticsearch listens for HTTP traffic on the first free port it
# finds starting at 9200. Set a specific HTTP port here:
#設置http端口,默認是9200,是對外提供服務的端口
http.port: 9201
# --------------------------------- Discovery ----------------------------------
#
# Pass an initial list of hosts to perform discovery when this node is started:
# The default list of hosts is ["127.0.0.1", "[::1]"]
#節點發現,并指定transport.tcp.port為9300
discovery.seed_hosts: ["10.1.3.12:9300", "10.1.3.13:9300","10.1.3.14:9300"]
#
# Bootstrap the cluster using an initial set of master-eligible nodes:
#初始化集群時需要此配置來選舉master節點
cluster.initial_master_nodes: ["node-1", "node-2", "node-3"]
(5)另外兩臺節點的es配置
把第一臺配置好的es文件夾復制到另外兩臺機器中,再做一些簡單的修改就可以了
scp -r /home/es/elasticsearch es@10.1.3.13:/home/es/
scp -r /home/es/elasticsearch es@10.1.3.14:/home/es/
分別在兩臺機器中修改yml配置文件:
#10.1.3.13節點
node.name: node-2
network.host: 10.1.3.13
#10.1.3.14節點
node.name: node-3
network.host: 10.1.3.14
(6)分別修改3臺機器的配置文件(不修改啟動es時會報錯)
在/etc/security/limits.conf 尾部添加
es soft nofile 65536
es hard nofile 65536
在 /etc/security/limits.d/20-nproc.conf尾部添加
es soft nofile 65536
es hard nofile 65536
* hard nproc 4096
在改/etc/sysctl.conf 尾部添加
vm.max_map_count=655360
重新加載
sysctl -p
(7)啟動elasticsearch集群
用es用戶,分別在三臺機器上啟動Elasticsearch,啟動過程中建議單個機器啟動成功后在啟動另一臺。
cd /home/es/elasticsearch
#前端啟動
./bin/elasticsearch
#后臺啟動并使用-p將進程ID記錄在文件中,也可不加-p參數
./bin/elasticsearch -d -p pid
(8)測試集群是否正常啟動
http://10.1.3.12:9201
(9)安裝安全認證組件x-pack
cd /home/es/elasticsearch
./bin/elasticsearch-certutil ca
依次輸入回車(文件使用默認名),密碼
(10)節點分發證書
LS需要X.509證書(X.509 證書是一個數字證書,它使用 X.509 公有密鑰基礎設施標準將公有密鑰與證書中包含的身份相關聯。X.509 證書由一家名為證書頒發機構 (CA) 的可信實體頒發。CA 持有一個或多個名為 CA 證書的特殊證書,它使用這種證書來頒發 X.509 證書。只有證書頒發機構才有權訪問 CA 證書)才能對與之通信的應用程序執行加密和身份驗證。 為了使節點之間的通信真正安全,必須對證書進行驗證。
在Elasticsearch集群中驗證證書真實性的推薦方法是信任簽署證書的證書頒發機構(CA)。
這樣,只需要使用由同一CA簽名的證書,即可自動允許該節點加入集群。
./bin/elasticsearch-certutil cert --ca elastic-stack-ca.p12 #依次輸入上一個步驟的密碼。回車(文件使用默認名),密碼(建議與上一步密碼相同)
./bin/elasticsearch-keystore add xpack.security.transport.ssl.keystore.secure_password #并輸入第一步輸入的密碼
./bin/elasticsearch-keystore add xpack.security.transport.ssl.truststore.secure_password #并輸入第一步輸入的密碼
(11)多節點配置
將生成的elastic-certificates.p12、elastic-stack-ca.p12文件mv到config目錄下,并連同elasticsearch.keystore 文件 scp到其他節點的config目錄中
scp elastic-certificates.p12 elasticsearch.keystore elastic-stack-ca.p12 es@10.1.3.13:/home/es/elasticsearch/config/
scp elastic-certificates.p12 elasticsearch.keystore elastic-stack-ca.p12 es@10.1.3.14:/home/es/elasticsearch/config/
(12)修改各節點的yml配置文件
在elasticsearch/config/elasticsearch.yml中增加一下配置,啟用x-pack安全組件,啟用ssl加密通信,并且配置認證證書
# ---------------------------------- Security ----------------------------------
xpack.security.enabled: true
xpack.security.transport.ssl.enabled: true
xpack.security.transport.ssl.verification_mode: certificate
xpack.security.transport.ssl.keystore.path: elastic-certificates.p12
xpack.security.transport.ssl.truststore.path: elastic-certificates.p12
配置修改完成后,重啟es服務,重啟成功后
http://10.1.3.12:9201 會彈出一個輸入框,讓我們輸入賬號和密碼
(13)密碼設置
通過設置訪問密碼,這是elastic用戶和其他一些系統內置用戶的密碼
#手動輸入密碼
./bin/elasticsearch-setup-passwords interactive
#自動生成密碼,切記要復制保存
./bin/elasticsearch-setup-passwords auto
注意在執行該命令前一定要確保elasticsearch.yml里discovery.seed_hosts和cluster.initial_master_nodes節點都正常運行,否則出現錯誤:ERROR: Failed to set password for user [apm_system]
(14)驗證
參考鏈接:
https://blog.csdn.net/zhuchunyan_aijia/article/details/122809902
http://dljz.nicethemes.cn/news/show-309589.html
https://blog.csdn.net/Jo_Andy/article/details/123203217
https://blog.csdn.net/yongpole/article/details/82795215(解決elasticsearch:Exception BindTransportException[Failed to bind to [9300-9400]])
http://t.zoukankan.com/chong-zuo3322-p-13387706.html