1. 程式人生 > >Elasticsearch叢集啟動關閉重啟操作

Elasticsearch叢集啟動關閉重啟操作

ES叢集如果節點較多,在重啟,關閉,啟動等操作的時候,需要一個一個操作,非常麻煩,下面提供一種方式,可以通過指令碼的方式,在一臺節點上操作即可:

一、配置節點之間免密碼登入;

具體配置方法,請百度搜索下就有了。

二、建立一下指令碼完成操作:

  1. 叢集啟動
    在elasticsearch安裝目錄下建立elasticstart.sh檔案,內容如下:

!/bin/bash

ssh 100.100.37.26 /home/elasticsearch/bin/service/elasticsearch start
ssh 100.100.37.27 /home/elasticsearch/bin/service/elasticsearch start
ssh 100.100.37.28 /home/elasticsearch/bin/service/elasticsearch start
ssh 100.100.37.29 /home/elasticsearch/bin/service/elasticsearch start
ssh 100.100.37.30 /home/elasticsearch/bin/service/elasticsearch start
ssh 100.100.37.31 /home/elasticsearch/bin/service/elasticsearch start
ssh 100.100.37.32 /home/elasticsearch/bin/service/elasticsearch start
ssh 100.100.37.33 /home/elasticsearch/bin/service/elasticsearch start

程式碼說明:
ssh 100.100.37.26表示ssh方式登陸到伺服器,/home/elasticsearch/bin/service/elasticsearch start 表示啟動ES節點服務。叢集裡面有幾個節點,需要都在此指令碼中添上。

建立完指令碼後,切換到檔案目錄,執行elasticstart.sh 啟動所有節點。

  1. 叢集重啟
    重啟操作與啟動操作步驟一致,重啟檔案內容如下:

ssh 100.100.37.26 /home/elasticsearch/bin/service/elasticsearch restart
ssh 100.100.37.27 /home/elasticsearch/bin/service/elasticsearch restart
ssh 100.100.37.28 /home/elasticsearch/bin/service/elasticsearch restart
ssh 100.100.37.29 /home/elasticsearch/bin/service/elasticsearch restart
ssh 100.100.37.30 /home/elasticsearch/bin/service/elasticsearch restart
ssh 100.100.37.31 /home/elasticsearch/bin/service/elasticsearch restart
ssh 100.100.37.32 /home/elasticsearch/bin/service/elasticsearch restart
ssh 100.100.37.33 /home/elasticsearch/bin/service/elasticsearch restart

  1. 叢集關閉
    關閉操作與啟動操作步驟一致,檔案內容如下:

!/bin/bash

ssh 100.100.37.26 /home/elasticsearch/bin/service/elasticsearch stop
ssh 100.100.37.27 /home/elasticsearch/bin/service/elasticsearch stop
ssh 100.100.37.28 /home/elasticsearch/bin/service/elasticsearch stop
ssh 100.100.37.29 /home/elasticsearch/bin/service/elasticsearch stop
ssh 100.100.37.30 /home/elasticsearch/bin/service/elasticsearch stop
ssh 100.100.37.31 /home/elasticsearch/bin/service/elasticsearch stop
ssh 100.100.37.32 /home/elasticsearch/bin/service/elasticsearch stop
ssh 100.100.37.33 /home/elasticsearch/bin/service/elasticsearch stop