2.修改配置文件 節點1: cat elasticsearch-7.8.0/config/elasticsearch.yml cluster.name: cluster-rongda #節點名稱 node.name: node_1 #ip地址 network.host: 192.168.215.98 #是不是有資格主節點,是否作為數據計算的節點 node.master: true node.data: true http.port: 9200 transport.tcp.port: 9300 # head 插件需要這打開這兩個配置 http.cors.allow-origin: "*" http.cors.enabled: true http.max_content_length: 200mb #es7.x 之后新增的配置,初始化一個新的集群時需要此配置來選舉master【有幾個節點就寫幾個節點的IP地址】 cluster.initial_master_nodes: ["192.168.215.98","192.168.215.99"] #es7.x 之后新增的配置,節點發現 discovery.seed_hosts: ["192.168.215.98","192.168.215.99"] gateway.recover_after_nodes: 2 network.tcp.keep_alive: true network.tcp.no_delay: true transport.tcp.compress: true #集群內同時啟動的數據任務個數,默認是2個 cluster.routing.allocation.cluster_concurrent_rebalance: 16 #添加或刪除節點及負載均衡時並發恢復的線程個數,默認4個 cluster.routing.allocation.node_concurrent_recoveries: 16 #初始化數據恢復時,並發恢復線程的個數,默認4個 cluster.routing.allocation.node_initial_primaries_recoveries: 16 節點2: cat elasticsearch-7.8.0/config/elasticsearch.yml #集群名稱 cluster.name: cluster-rongda #節點名稱 node.name: node_2 #ip地址 network.host: 192.168.215.99 #是不是有資格主節點,是否作為數據計算的節點 node.master: true node.data: true http.port: 9200 transport.tcp.port: 9300 # head 插件需要這打開這兩個配置 http.cors.allow-origin: "*" http.cors.enabled: true http.max_content_length: 200mb #es7.x 之后新增的配置,初始化一個新的集群時需要此配置來選舉master【有幾個節點就寫幾個節點的IP地址】 cluster.initial_master_nodes: ["192.168.215.98","192.168.215.99"] #es7.x 之后新增的配置,節點發現 discovery.seed_hosts: ["192.168.215.98","192.168.215.99"] gateway.recover_after_nodes: 2 network.tcp.keep_alive: true network.tcp.no_delay: true transport.tcp.compress: true #集群內同時啟動的數據任務個數,默認是2個 cluster.routing.allocation.cluster_concurrent_rebalance: 16 #添加或刪除節點及負載均衡時並發恢復的線程個數,默認4個 cluster.routing.allocation.node_concurrent_recoveries: 16 #初始化數據恢復時,並發恢復線程的個數,默認4個 cluster.routing.allocation.node_initial_primaries_recoveries: 16 節點3: cat elasticsearch-7.8.0/config/elasticsearch.yml #集群名稱 cluster.name: cluster-rongda #節點名稱 node.name: node_3 #ip地址 network.host: 192.168.254.201 #是不是有資格主節點,是否作為數據計算的節點 node.master: true node.data: true http.port: 9200 transport.tcp.port: 9300 # head 插件需要這打開這兩個配置 http.cors.allow-origin: "*" http.cors.enabled: true http.max_content_length: 200mb #es7.x 之后新增的配置,初始化一個新的集群時需要此配置來選舉master【有幾個節點就寫幾個節點的IP地址】 cluster.initial_master_nodes: ["192.168.254.102","192.168.254.200","192.168.254.201"] #es7.x 之后新增的配置,節點發現 discovery.seed_hosts: ["192.168.254.102","192.168.254.200","192.168.254.201"] gateway.recover_after_nodes: 2 network.tcp.keep_alive: true network.tcp.no_delay: true transport.tcp.compress: true #集群內同時啟動的數據任務個數,默認是2個 cluster.routing.allocation.cluster_concurrent_rebalance: 16 #添加或刪除節點及負載均衡時並發恢復的線程個數,默認4個 cluster.routing.allocation.node_concurrent_recoveries: 16 #初始化數據恢復時,並發恢復線程的個數,默認4個 cluster.routing.allocation.node_initial_primaries_recoveries: 16 3.啟動 1)//注意,因為elasticsearch有安全限制,不允許root啟動,當腳本啟動失敗時,需要創建普通用戶,再通過授權命令將elasticsearch目錄的屬主更為普通用戶。 useradd es chown -R es.es /home/rongda/elasticsearch-7.8.0 2)//注意:修改連接數 vim /etc/security/limits.conf * soft nproc 4096 * hard nproc 4096 3)切換到普通用戶的身份進行啟動 su - es 放前台啟動:/home/rongda/elasticsearch-7.8.0/bin/elasticsearch 放后台啟動:/home/rongda/elasticsearch-7.8.0/bin/elasticsearch -d 4)注意觀察啟動日志 tail -f /home/rongda/elasticsearch-7.8.0/logs/cluster XXX.log 4.測試 1)檢查端口是否存在 netstat -lntp | grep elasticsearch 2)檢查集群的狀態是否正常 a.在命令行檢查 curl http://192.168.254.200:9200/_cluster/health?pretty=true 檢查是否是green的狀態 curl http://192.168.254.200:9200/_cat/nodes 檢查節點數有幾個,誰是主節點 b.在瀏覽器進行訪問,可以知道誰是主節點【帶*的是主節點】 http://192.168.254.102:9200/_cat/nodes 5.開啟集群認證狀態 1)為 ES 集群創建節點認證中心 ,生成證書 (直接回車,設置空密碼) $ ./bin/elasticsearch-certutil ca 一路回車完成后會生成一個文件:elastic-stack-ca.p12 $ ./bin/elasticsearch-certutil cert --ca ./elastic-stack-ca.p12 直接回車。默認會生成文件 elastic-certificates.p12。 將這個兩個文件拷貝到另一個節點上,###若使用SCP傳到另一個節點的話 注意目錄文件的身份,是es不是root ============================================================================================================================== 中間會讓輸入路徑跟密碼,路徑可以不輸,直接回車,但是密碼我們還是回車生成。完成后會生成一個文件:elastic-stack-ca.p12 默認文件會在 ES 根目錄產生,名為 elastic-stack-ca.p12。 然后可以將文件 elastic-stack-ca.p12 復制到每個 ES 節點的根目錄下。 2)為集群中的每個節點創建證書和私鑰(每個節點都要執行以下內容)生成證書和密鑰。(直接回車,設置空密碼) $ ./bin/elasticsearch-certutil cert --ca ./elastic-stack-ca.p12 可以設置密碼,也可以直接回車。默認會生成文件 elastic-certificates.p12。 ============================================================================================================================================= 3)將生成的文件復制到配置文件目錄下: $ mv ./elastic-stack-ca.p12 ./config/ $ mv ./elastic-certificates.p12 ./config/ 4)開啟ES 配置文件的認證參數,修改配置文件(去掉#) 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 如果之前節點證書設置了密碼,將密碼添加到 keystore (上面我設置的都是空密碼,所以這一步我不需要執行) 5)設定密碼 $ ./bin/elasticsearch-keystore add xpack.security.transport.ssl.keystore.secure_password 密碼:為空 $ ./bin/elasticsearch-keystore add xpack.security.transport.ssl.truststore.secure_password 密碼:為空 跟前面的輸入保持一致 6)重啟ES集群 ps -ef | grep elasticsearch kill 進程ID號 重啟:./bin/elasticsearch -d 7)設定驗證密碼 $ ./bin/elasticsearch-setup-passwords interactive (如果報錯,刪除data,重啟es,再執行) 設置內置用戶密碼 (設置完,直接就可以通過用戶和密碼訪問集群了) curl http://192.168.10.150:9200/_cat/nodes -u username:passwords 查看集群節點:http://192.168.10.150:9200/_cat/nodes?v 驗證集群磁盤分配情況:http://192.168.10.150:9200/_cat/allocation?v 驗證集群健康狀況:http://192.168.10.150:9200/_cat/health?v 查看集群的索引數: http://192.168.10.150:9200/_cat/indices?v