0%

Elasticsearch集群部署

环境要求

# 检查vm.max_map_count设置,至少要求262144
grep vm.max_map_count /etc/sysctl.conf
vm.max_map_count=262144
# 在线设置
sysctl -w vm.max_map_count=262144
# ES的data目录需要设置rwx权限
chmod g+rwx /root/es/data

三台机器搭建集群

  • node1
docker run -d --name es --net host \
  -e node.name=es1 -e cluster.name=es-docker-cluster \
  -e discovery.seed_hosts=192.168.3.19,192.168.3.20 \
  -e cluster.initial_master_nodes=192.168.3.17,192.168.3.19,192.168.3.20 \
  -e network.publish_host=192.168.3.17 \
  -v /root/es/data:/usr/share/elasticsearch/data \
  elasticsearch:7.5.2
  • node2
docker run -d --name es --net host \
  -e node.name=es2 -e cluster.name=es-docker-cluster \
  -e discovery.seed_hosts=192.168.3.17,192.168.3.20 \
  -e cluster.initial_master_nodes=192.168.3.17,192.168.3.19,192.168.3.20 \
  -e network.publish_host=192.168.3.19 \
  -v /root/es/data:/usr/share/elasticsearch/data \
  elasticsearch:7.5.2 
  • node3
docker run -d --name es --net host \
  -e node.name=es3 -e cluster.name=es-docker-cluster \
  -e discovery.seed_hosts=192.168.3.17,192.168.3.19 \
  -e cluster.initial_master_nodes=192.168.3.17,192.168.3.19,192.168.3.20 \
  -e network.publish_host=192.168.3.20 \
  -v /root/es/data:/usr/share/elasticsearch/data \
  elasticsearch:7.5.2 

测试

[root@data2 es]# curl -X GET "localhost:9200/_cat/nodes?v&pretty"
ip           heap.percent ram.percent cpu load_1m load_5m load_15m node.role master name
192.168.3.17           20          98   1    0.07    0.07     0.05 dilm      *      es1
192.168.3.20           12          97   1    0.04    0.03     0.05 dilm      -      es3
192.168.3.19            9          93   1    0.01    0.04     0.05 dilm      -      es2
[root@data1 es]# curl 'localhost:9200/_cluster/health?pretty'
{
  "cluster_name" : "es-docker-cluster",
  "status" : "green",
  "timed_out" : false,
  "number_of_nodes" : 3,
  "number_of_data_nodes" : 3,
  "active_primary_shards" : 0,
  "active_shards" : 0,
  "relocating_shards" : 0,
  "initializing_shards" : 0,
  "unassigned_shards" : 0,
  "delayed_unassigned_shards" : 0,
  "number_of_pending_tasks" : 0,
  "number_of_in_flight_fetch" : 0,
  "task_max_waiting_in_queue_millis" : 0,
  "active_shards_percent_as_number" : 100.0
}