docker pull elasticsearch:7.16.2
## 创建 network - 保证容器间可以通过用户名互通,需要为 bridge 类型
docker create network create es-net
## 查看状态
$ docker network ls
NETWORK ID NAME DRIVER SCOPE
6233d0b22df2 bridge bridge local
291fb99e4cdb es-net bridge local
120afa0b6f00 host host local
abcb9a8e42e6 none null local
## 创建目录
mkdir -p docker/es/{node1,node2,node3}/{data,config,plugins}
## 赋权
find ./ -name data -exec chmod 777 {} +
## 💀 指定系统max_map_count
vim /etc/sysctl.conf
# 添加
vm.max_map_count=262144
# 刷新配置
/sbin/sysctl -p
或
sysctl -w vm.max_map_count=262144
可以再容器运行时指定环境变量的方式增加配置,参考
$ vim docker/es/node1/config/elasticsearch.yml
# ------------------- start ----------------------------
http.host: 0.0.0.0
# 集群名称 - 同集群相同
cluster.name: es-test
# 节点名称 - 同集群唯一
node.name: node-1
# 是否可为主节点
node.master: true
# 是否保存数据节点
node.data: true
# 指定网络地址 - 为运行的容器名
network.host: node1
# 节点主机 - 为 network.host
discovery.zen.ping.unicast.hosts: ["node1", "node2", "node3"]
# 选举的主节点 - 为 node.name
cluster.initial_master_nodes: ["node-1"]
# 主节点数量
discovery.zen.minimum_master_nodes: 1
# ------------------ end -----------------------------
$ vim docker/es/node2/config/elasticsearch.yml
# ------------------- start ----------------------------
http.host: 0.0.0.0
# 集群名称 - 同集群相同
cluster.name: es-test
# 节点名称 - 同集群唯一
node.name: node-2
# 是否可为主节点
node.master: true
# 是否保存数据节点
node.data: true
# 指定网络地址 - 为运行的容器名
network.host: node2
# 节点主机 - 为 network.host
discovery.zen.ping.unicast.hosts: ["node1", "node2", "node3"]
# 选举的主节点 - 为 node.name
cluster.initial_master_nodes: ["node-1"]
# 主节点数量
discovery.zen.minimum_master_nodes: 1
# ------------------ end -----------------------------
docker run -d \
--name node1 \
--network=es-net \
--restart=always \
-p 9200:9200 \
-p 9300:9300 \
-e ES_JAVA_OPTS="-Xms256m -Xmx256m" \
-v ~/docker/es/node1/config/elasticsearch.yml:/usr/share/elasticsearch/config/elasticsearch.yml \
-v ~/docker/es/node1/data:/usr/share/elasticsearch/data \
-v ~/docker/es/node1/plugins:/usr/share/elasticsearch/plugins \
elasticsearch:7.16.2
docker run -d \
--name node2 \
--network=es-net \
--restart=always \
-p 9201:9200 \
-p 9301:9300 \
-e ES_JAVA_OPTS="-Xms256m -Xmx256m" \
-v ~/docker/es/node2/config/elasticsearch.yml:/usr/share/elasticsearch/config/elasticsearch.yml \
-v ~/docker/es/node2/data:/usr/share/elasticsearch/data \
-v ~/docker/es/node2/plugins:/usr/share/elasticsearch/plugins \
elasticsearch:7.16.2
docker run -d \
--name node3 \
--network=es-net \
--restart=always \
-p 9202:9200 \
-p 9302:9300 \
-e ES_JAVA_OPTS="-Xms256m -Xmx256m" \
-v ~/docker/es/node3/config/elasticsearch.yml:/usr/share/elasticsearch/config/elasticsearch.yml \
-v ~/docker/es/node3/data:/usr/share/elasticsearch/data \
-v ~/docker/es/node3/plugins:/usr/share/elasticsearch/plugins \
elasticsearch:7.16.2
$ curl http://127.0.0.1:9200/_cat/nodes\?v
ip heap.percent ram.percent cpu load_1m load_5m load_15m node.role master name
172.19.0.7 42 48 5 3.22 1.15 0.69 cdfhilmrstw * node-1
172.19.0.6 50 48 5 3.22 1.15 0.69 cdfhilmrstw - node-2
172.19.0.5 36 48 5 3.22 1.15 0.69 cdfhilmrstw - node-3
$ curl http://10.211.55.8:9200/_cluster/health\?pretty
{
"cluster_name" : "es-test",
"status" : "red",
"timed_out" : false,
"number_of_nodes" : 3,
"number_of_data_nodes" : 3,
"active_primary_shards" : 4,
"active_shards" : 10,
"relocating_shards" : 0,
"initializing_shards" : 0,
"unassigned_shards" : 2,
"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" : 83.33333333333334
}
## 1. 创建目录
## 创建目录
mkdir -p docker/es/node4/{data,config,plugins}
## 赋权
chmod 777 docker/es/node4/data
## 2. 增加配置文件
vim docker/es/node4/config/elasticsearch.yml
# ------------------- start ----------------------------
http.host: 0.0.0.0
cluster.name: es-test
# 💀
node.name: node-4
# ^^^^^^
# 是否可为主节点
node.master: true
# 是否保存数据节点
node.data: true
# 💀
network.host: node4
# ^^^^^
# 节点主机 - 为 network.host , 【好像不用修改也可以添加成功】
discovery.zen.ping.unicast.hosts: ["node1", "node2", "node3"]
cluster.initial_master_nodes: ["node-1"]
discovery.zen.minimum_master_nodes: 1
# ------------------ end -----------------------------
## 3. 运行实例
docker run -d \
--name node4 \
--network=es-net \
--restart=always \
-p 9203:9200 \
-p 9303:9300 \
-e ES_JAVA_OPTS="-Xms256m -Xmx256m" \
-v ~/docker/es/node4/config/elasticsearch.yml:/usr/share/elasticsearch/config/elasticsearch.yml \
-v ~/docker/es/node4/data:/usr/share/elasticsearch/data \
-v ~/docker/es/node4/plugins:/usr/share/elasticsearch/plugins \
elasticsearch:7.16.2
## 4. 查看状态
$ curl http://127.0.0.1:9200/_cat/nodes\?v
ip heap.percent ram.percent cpu load_1m load_5m load_15m node.role master name
172.19.0.7 64 74 2 0.41 0.57 0.60 cdfhilmrstw * node-1
172.19.0.6 39 74 2 0.41 0.57 0.60 cdfhilmrstw - node-2
172.19.0.5 68 74 2 0.41 0.57 0.60 cdfhilmrstw - node-3
172.19.0.2 62 74 2 0.41 0.57 0.60 cdfhilmrstw - node-4
## 5. 添加成功
6.1 Elasticsearch(一)Docker搭建ES集群
Chat
解决Elasticsearch集群 master_not_discovered_exception 异常
windows入门Elasticsearch7.10(es)之3:本地集群搭建
Elasticsearch: Max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144]