基于Docker方式实现Elasticsearch集群

采用docker容器,搭建两个es集群,可根据步骤自行扩展n+集群

1、创建es挂载目录
cd /usr/local
mkdir -p es/config
2、创建es存放数据目录
cd es
mkdir data1
mkdir data2
mkdir data3
3、关联ip
firewall-cmd --add-port=9300/tcp
firewall-cmd --add-port=9301/tcp
4.创建ik分词器插件目录
mkdir  plugins1
mkdir  plugins2
5、上传es配置文件
通过FTP工具上传至服务器 /usr/local/es/config 目录 es1.yml/es2.yml

#es1.yml
cluster.name: elasticsearch-cluster
node.name: es-node1
network.bind_host: 0.0.0.0
network.publish_host: 192.168.10.180
http.port: 9200
transport.tcp.port: 9300
http.cors.enabled: true
http.cors.allow-origin: "*"
node.master: true 
node.data: true  
discovery.zen.ping.unicast.hosts: ["192.168.10.180:9300","192.168.10.180:9301"]
discovery.zen.minimum_master_nodes: 1

#es2.yml
cluster.name: elasticsearch-cluster
node.name: es-node2
network.bind_host: 0.0.0.0
network.publish_host: 192.168.10.180
http.port: 9201
transport.tcp.port: 9301
http.cors.enabled: true
http.cors.allow-origin: "*"
node.master: true 
node.data: true  
discovery.zen.ping.unicast.hosts: ["192.168.10.180:9300","192.168.10.180:9301"]
discovery.zen.minimum_master_nodes: 1
6、启动es

启动容器1:

docker run -e ES_JAVA_OPTS="-Xms256m -Xmx256m" -d  -p 9200:9200 -p 9300:9300 -p 5601:5601 -v /usr/local/es/config/es1.yml:/usr/share/elasticsearch/config/elasticsearch.yml  -v /usr/local/es/plugins1:/usr/share/elasticsearch/plugins    -v /usr/local/es/data1:/usr/share/elasticsearch/data --name ES01 elasticsearch

启动容器2:

docker run -e ES_JAVA_OPTS="-Xms256m -Xmx256m" -d -p 9201:9201 -p 9301:9301 -v /usr/local/es/config/es2.yml:/usr/share/elasticsearch/config/elasticsearch.yml  -v /usr/local/es/plugins2:/usr/share/elasticsearch/plugins    -v /usr/local/es/data2:/usr/share/elasticsearch/data --name ES02 elasticsearch
7、测试集群效果
http://192.168.10.180:9200/_cat/nodes?pretty
posted @ 2019-08-12 21:56  niceyoo  阅读(...)  评论(... 编辑 收藏