Elasticsearch伪集群部署和节点扩容
2018-05-29 本文已影响257人
玩玩风行啦
elasticsearch.jpg
确认集群discovery.zen.minimum_master_nodes修改生效后,修改每个节点配置文件config/elasticsearch.yml中discovery.zen.minimum_master_nodes为3,并依次重启所有节点即可。
概述
在一台物理机器上部署3个节点的Elasticsearch集群,然后平滑扩容至5个节点
部署过程
下载
wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-5.5.0.tar.gz
解压
tar xvf elasticsearch-5.5.0.tar.gz
复制解压后文件5份
cp -rf elasticsearch-5.5.0 es1
cp -rf elasticsearch-5.5.0 es2
cp -rf elasticsearch-5.5.0 es3
cp -rf elasticsearch-5.5.0 es4
cp -rf elasticsearch-5.5.0 es5
修改节点1配置
grep -v '^#' es1/config/elasticsearch.yml
cluster.name: AM
node.name: node-1
network.host: 10.86.0.105
http.port: 19201
transport.tcp.port: 19301
discovery.zen.ping.unicast.hosts: ["10.86.0.105:19301", "10.86.0.105:19302", "10.86.0.105:19303"]
discovery.zen.minimum_master_nodes: 2
修改节点2配置
grep -v '^#' es2/config/elasticsearch.yml
cluster.name: AM
node.name: node-2
network.host: 10.86.0.105
http.port: 19202
transport.tcp.port: 19302
discovery.zen.ping.unicast.hosts: ["10.86.0.105:19301", "10.86.0.105:19302", "10.86.0.105:19303"]
discovery.zen.minimum_master_nodes: 2
修改节点3配置
grep -v '^#' es3/config/elasticsearch.yml
cluster.name: AM
node.name: node-3
network.host: 10.86.0.105
http.port: 19203
transport.tcp.port: 19303
discovery.zen.ping.unicast.hosts: ["10.86.0.105:19301", "10.86.0.105:19302", "10.86.0.105:19303"]
discovery.zen.minimum_master_nodes: 2
依次启动3个节点
es1/bin/elasticsearch
es2/bin/elasticsearch
es3/bin/elasticsearch
使用api接口查询Elasticserch状态
http://10.86.0.105:19202/_cat/nodes?v=pretty
Snip20180529_15.png
使用api接口插入一条数据
curl -XPUT 'http://10.86.0.105:19201/blog/user/dilbert' -d '{ "name" : "Dilbert Brown" }'
{"_index":"blog","_type":"user","_id":"dilbert","_version":1,"result":"created","_shards":{"total":3,"successful":2,"failed":0},"created":true}
使用Elasticsearch Head Chrome插件查看集群索引状态
扩容过程
修改节点4配置
grep -v '^#' es4/config/elasticsearch.yml
cluster.name: AM
node.name: node-4
network.host: 10.86.0.105
http.port: 19204
transport.tcp.port: 19304
discovery.zen.ping.unicast.hosts: ["10.86.0.105:19301", "10.86.0.105:19302", "10.86.0.105:19303"]
discovery.zen.minimum_master_nodes: 2
修改节点5配置
grep -v '^#' es4/config/elasticsearch.yml
cluster.name: AM
node.name: node-5
network.host: 10.86.0.105
http.port: 19205
transport.tcp.port: 19305
discovery.zen.ping.unicast.hosts: ["10.86.0.105:19301", "10.86.0.105:19302", "10.86.0.105:19303"]
discovery.zen.minimum_master_nodes: 2
依次启动节点4和节点5
es4/bin/elasticsearch
es5/bin/elasticsearch
在master节点(此处为节点2)可看到日志输出如下:
[2018-05-29T14:35:22,151][WARN ][o.e.d.z.ElectMasterService] [node-2] value for setting "discovery.zen.minimum_master_nodes" is too low. This can result in data loss! Please set it to at least a quorum of master-eligible nodes (current value: [2], total number of master-eligible nodes used for publishing in this round: [4])
需要修改discovery.zen.minimum_master_nodes为(N/2)+1,以防止集群脑裂出现多个master节点。(之前3个节点,discovery.zen.minimum_master_nodes为2;扩容后节点数为5,discovery.zen.minimum_master_nodes需修改为3)
使用api接口修改discovery.zen.minimum_master_nodes
curl -XPUT 10.86.0.105:19201/_cluster/settings -d '{
"persistent" : {
"discovery.zen.minimum_master_nodes" : 3
}
}'
{"acknowledged":true,"persistent":{"discovery":{"zen":{"minimum_master_nodes":"3"}}},"transient":{}}
使用api接口查看确认修改生效
http://10.86.0.105:19201/_cluster/settings
Snip20180529_24.png
使用Elasticsearch Head Chrome插件查看集群索引变更为如下状态
确认集群discovery.zen.minimum_master_nodes修改生效后,修改每个节点配置文件config/elasticsearch.yml中discovery.zen.minimum_master_nodes为3,并依次重启所有节点即可。