一、安裝第一個ElasticSearch(主節點)
1、創建es用戶,啟動es不能使用root用戶
useradd es
passwd es12
root用戶進入/home/es目錄下
2、獲取ElasticSearch安裝包
wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-6.1.2.tar.gz
3、解壓、改名(方便集群時區別另一個ES)
tar xf elasticsearch-6.1.2.tar.gz
mv elasticsearch-6.1.2.tar.gz elasticsearch-node212
4、修改配置文件
vi elasticsearch-node2/config/elasticsearch.yml1
修改內容如下:
cluster.name: my-application 各節點此名稱必須一致
node.name: node-2 節點名稱,不能與其他節點相同
network.host: ***.***.***.*** 自己的服務器IP
http.port: **** 訪問端口
transport.tcp.port: **** 集群各節點間的通訊端口
discovery.zen.ping.unicast.hosts: ["主節點IP:通訊端口","輔節點IP:通訊端口"] 123456
文件最后追加以下內容,以便連接head顯示健康值(注意每行代碼前面不要有空格)
http.cors.enabled: true
http.cors.allow-origin: "*"12
5、啟動
sh elasticsearch-node2/bin/elasticsearch1
[2018-01-24T15:36:41,990][INFO ][o.e.n.Node ] [KMyyO-3] started
[2018-01-24T15:36:41,997][INFO ][o.e.g.GatewayService ] [KMyyO-3] recovered [0] indices into cluster_state12
啟動成功,瀏覽器中輸入 IP:訪問端口
網頁顯示以下內容,說明部署成功
{
"name" : "node-2",
"cluster_name" : "my-application",
"cluster_uuid" : "j2aJ7CsRSuSo0G8Bgky2Ww",
"version" : {
"number" : "6.1.2",
"build_hash" : "5b1fea5",
"build_date" : "2018-01-10T02:35:59.208Z",
"build_snapshot" : false,
"lucene_version" : "7.1.0",
"minimum_wire_compatibility_version" : "5.6.0",
"minimum_index_compatibility_version" : "5.0.0"
},
"tagline" : "You Know, for Search"
}123456789101112131415
6、報錯及其處理
【類型一】
Caused by: java.lang.RuntimeException: can not run elasticsearch as root1
該問題是因為運行es不能使用root用戶,因此要切換es用戶再次啟動
chown -R es:es elasticsearch-node2/
su - es
sh elasticsearch-node2/bin/elasticsearch123
【類型二】
max file descriptors [4096] for elasticsearch process is too low, increase to at least [65536]1
解決方法,換回root用戶,修改配置文件
vi /etc/security/limits.conf
#在最后面追加下面內容
es hard nofile 65536
es soft nofile 655361234
【類型三】
max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144]1
解決方法,換回root用戶,修改配置文件
vi /etc/sysctl.conf
#在最后面追加下面內容
vm.max_map_count=655360
#執行命令:
sysctl -p12345
二、安裝第二個ElasticSearch(輔節點)
安裝方法與第一個一致,注意修改配置文件
root用戶進入/home/es目錄下
1、解壓、改名
tar xf elasticsearch-6.1.2.tar.gz
mv elasticsearch-6.1.2.tar.gz elasticsearch-node312
2、修改配置文件
vi elasticsearch-node3/config/elasticsearch.yml1
修改內容如下:
cluster.name: my-application 各節點此名稱必須一致
node.name: node-3 節點名稱,不能與其他節點相同
network.host: ***.***.***.*** 自己的服務器IP
http.port: **** 訪問端口(注意不要與第一個端口重復)
transport.tcp.port: **** 集群各節點間的通訊端口(注意不要與第一個端口重復)
discovery.zen.ping.unicast.hosts: ["主節點IP:通訊端口","輔節點IP:通訊端口"]123456
文件最后同樣追加下面代碼
http.cors.enabled: true
http.cors.allow-origin: "*"12
3.啟動
sh elasticsearch-node3/bin/elasticsearch1
瀏覽器,瀏覽器中輸入 IP:訪問端口
網頁顯示以下內容,說明第二個部署成功
{
"name" : "node-3",
"cluster_name" : "my-application",
"cluster_uuid" : "j2aJ7CsRSuSo0G8Bgky2Ww",
"version" : {
"number" : "6.1.2",
"build_hash" : "5b1fea5",
"build_date" : "2018-01-10T02:35:59.208Z",
"build_snapshot" : false,
"lucene_version" : "7.1.0",
"minimum_wire_compatibility_version" : "5.6.0",
"minimum_index_compatibility_version" : "5.0.0"
},
"tagline" : "You Know, for Search"
}123456789101112131415
三、安裝Elasticsearch-head插件
1、安裝head插件之前需要安裝node.js
curl -sL https://rpm.nodesource.com/setup_8.x | bash -
yum install -y nodejs12
安裝完成后執行命令查看node與npm版本
[root@host]# node -v
v8.12.0
[root@host]# npm -v
6.4.1
12345
2、從git獲取head插件
wget https://github.com/mobz/elasticsearch-head/archive/master.zip1
3、解壓安裝包(可以改名,方便操作)
unzip master.zip
mv elasticsearch-head-master/ head12
4、修改配置文件
vi head/Gruntfile.js1
更改head端口號
connect: {
server: {
options: {
port: ****, 改為head訪問端口
base: '.',
keepalive: true
}
}
}
12345678910
vi head/_site/app.js 1
更改head鏈接地址
init: function(parent) {
this._super();
this.prefs = services.Preferences.instance();
this.base_uri = this.config.base_uri || this.prefs.get("app-base_uri") || "http://主節點IP:訪問端口";
12345
5、啟動head
nohup npm run start > ../head.log 2>&1 &1
6、瀏覽器登錄head
URL輸入服務器IP:head訪問端口
鏈接地址輸如主節點的訪問地址
7、安裝head常見錯誤
【類型一】啟動成功,但是網頁不能訪問
解決方法
關閉服務器防火牆
service iptables stop
【類型二】集群健康值未連接
在elasticsearch.yml里追加下列代碼(注意代碼前面不要有空格)
http.cors.enabled: truehttp.cors.allow-origin: "*"
問:為什么es節點用node2、node3?
答:因為之前用node1搭建了一套未集群的ES,所以后面集群就用2和3了。
---------------------------------------------
推薦閱讀: