xiaoming728

xiaoming728

Docker部署Elasticsearch集群

Docker部署Elasticsearch集群

1、下载镜像

docker pull elasticsearch:7.6.2

2、配置参数

创建3个节点目录

mkdir -p /home/docker/elasticsearch/node0/config
mkdir -p /home/docker/elasticsearch/node1/config
mkdir -p /home/docker/elasticsearch/node2/config

添加节点1配置文件

vi /home/docker/elasticsearch/node0/config/elasticsearch.yml

将下面内容复制到配置文件中保存

cluster.name: docker-cluster

node.name: es-node0
node.master: true
node.data: true

path.data: /usr/share/elasticsearch/data
path.logs: /usr/share/elasticsearch/logs

network.bind_host: 0.0.0.0
network.publish_host: 192.168.8.129

http.port: 9200
transport.tcp.port: 9300

http.cors.enabled: true
http.cors.allow-origin: "*"

discovery.zen.ping.unicast.hosts: ["192.168.8.129:9300","192.168.8.129:9301","192.168.8.129:9302"]
discovery.zen.minimum_master_nodes: 2

添加节点2配置文件

vi /home/docker/elasticsearch/node1/config/elasticsearch.yml

将下面内容复制到配置文件中保存

cluster.name: docker-cluster

node.name: es-node1
node.master: true
node.data: true

path.data: /usr/share/elasticsearch/data
path.logs: /usr/share/elasticsearch/logs

network.bind_host: 0.0.0.0
network.publish_host: 192.168.8.129

http.port: 9201
transport.tcp.port: 9301

http.cors.enabled: true
http.cors.allow-origin: "*"

discovery.zen.ping.unicast.hosts: ["192.168.8.129:9300","192.168.8.129:9301","192.168.8.129:9302"]
discovery.zen.minimum_master_nodes: 2

添加节点3配置文件

vi /home/docker/elasticsearch/node2/config/elasticsearch.yml

将下面内容复制到配置文件中保存

cluster.name: docker-cluster

node.name: es-node2
node.master: true
node.data: true

path.data: /usr/share/elasticsearch/data
path.logs: /usr/share/elasticsearch/logs

network.bind_host: 0.0.0.0
network.publish_host: 192.168.8.129

http.port: 9202
transport.tcp.port: 9302

http.cors.enabled: true
http.cors.allow-origin: "*"

discovery.zen.ping.unicast.hosts: ["192.168.8.129:9300","192.168.8.129:9301","192.168.8.129:9302"]
discovery.zen.minimum_master_nodes: 2

3、安装镜像

docker run -d -p 9200:9200 -p 9300:9300 \
-v /home/docker/elasticsearch/node0/config/elasticsearch.yml:/usr/share/elasticsearch/config/elasticsearch.yml \
-v /home/docker/elasticsearch/node0/data:/usr/share/elasticsearch/data \
-v /home/docker/elasticsearch/node0/logs:/usr/share/elasticsearch/logs \
-e ES_JAVA_OPTS="-Xms2g -Xmx2g" \
--name elasticsearch-node0 \
elasticsearch:7.6.2
docker run -d -p 9201:9201 -p 9301:9301 \
-v /home/docker/elasticsearch/node1/config/elasticsearch.yml:/usr/share/elasticsearch/config/elasticsearch.yml \
-v /home/docker/elasticsearch/node1/data:/usr/share/elasticsearch/data \
-v /home/docker/elasticsearch/node1/logs:/usr/share/elasticsearch/logs \
-e ES_JAVA_OPTS="-Xms2g -Xmx2g" \
--name elasticsearch-node1 \
elasticsearch:7.6.2
docker run -d -p 9202:9202 -p 9302:9302 \
-v /home/docker/elasticsearch/node2/config/elasticsearch.yml:/usr/share/elasticsearch/config/elasticsearch.yml \
-v /home/docker/elasticsearch/node2/data:/usr/share/elasticsearch/data \
-v /home/docker/elasticsearch/node2/logs:/usr/share/elasticsearch/logs \
-e ES_JAVA_OPTS="-Xms2g -Xmx2g" \
--name elasticsearch-node2 \
elasticsearch:7.6.2

4、验证安装

镜像安装完成后访问:http://192.168.8.129:9200/_cat/nodes?pretty 查看集群情况