Docker部署Elasticsearch集群
docker-compose.yml方式
编写docker-compose,vi /data/es/docker-compose.yml
version: "3.7"
services:
es01:
image: "elasticsearch:7.10.1"
container_name: es01
ports:
- "9200:9200"
- "9300:9300"
environment:
node.name: es01
discovery.seed_hosts: es01,es02,es03
cluster.initial_master_nodes: es01,es02,es03
cluster.name: mycluster
ES_JAVA_OPTS: -Xms512m -Xmx512m
volumes:
- "es01:/usr/share/elasticsearch/data"
ulimits:
memlock:
soft: -1
hard: -1
es02:
image: "elasticsearch:7.10.1"
container_name: es02
ports:
- "9201:9200"
- "9301:9300"
environment:
node.name: es02
discovery.seed_hosts: es01,es02,es03
cluster.initial_master_nodes: es01,es02,es03
cluster.name: mycluster
ES_JAVA_OPTS: -Xms512m -Xmx512m
volumes:
- "es02:/usr/share/elasticsearch/data"
ulimits:
memlock:
soft: -1
hard: -1
es03:
image: "elasticsearch:7.10.1"
container_name: es03
ports:
- "9202:9200"
- "9302:9300"
environment:
node.name: es03
discovery.seed_hosts: es01,es02,es03
cluster.initial_master_nodes: es01,es02,es03
cluster.name: mycluster
ES_JAVA_OPTS: -Xms512m -Xmx512m
volumes:
- "es03:/usr/share/elasticsearch/data"
ulimits:
memlock:
soft: -1
hard: -1
kibana:
image: kibana:7.10.1
container_name: kibana
depends_on:
- es01
- es02
- es03
ports:
- "5601:5601"
- "9600:9600"
environment:
SERVERNAME: kibana
ELASTICSEARCH_HOSTS: '["http://es01:9200","http://es02:9200","http://es03:9200"]'
ES_JAVA_OPTS: -Xmx512m -Xms512m
volumes:
es01: {}
es02: {}
es03: {}
启动docker compose -f docker-compose2.yml up -d
[root@postgresql es]# docker compose -f docker-compose2.yml up -d
[+] Building 0.0s (0/0)
[+] Running 7/7
✔ Volume "es_es01" Created 0.0s
✔ Volume "es_es02" Created 0.0s
✔ Volume "es_es03" Created 0.0s
✔ Container es03 Started 0.6s
✔ Container es01 Started 0.6s
✔ Container es02 Started 0.6s
✔ Container kibana Started 1.1s
[root@postgresql es]#
更改kibana显示语言
和上篇文章一样的,不演示操作了
Elasticsearch安装分词器
和上篇文章一样的,不演示操作了
查看集群状态
查看集群健康状态,绿色,节点有3个
es01为主节点
把es01节点停止
docker stop es01
es01节点挂了,es02变成了主节点
创建索引
PUT mosnter
查看索引
查看分片情况
pri和rep是不会被分配在一个节点上的
如下可以看到在es01和es03节点上
我们将es03停止运行,模拟挂了
docker stop es03
再来查看啊分片情况
被分配到es01和es02节点上了
评论区