docker单机部署es集群
pull镜像
docker pull docker. elastic. co/elasticsearch/elasticsearch:7. 4. 2
配置文件
cluster. name: "es-docker-cluster"
network. host: 0. 0. 0. 0
node. master: true
network. publish_host: 192. 168. 1. 101
discovery. seed_hosts: [ "192.168.1.101:9301" , "192.168.1.101:9302" ]
transport. tcp. port: 9300
transport. profiles. default. port: 9300
cluster. initial_master_nodes: [ "es01" , "es02" , "es03" ]
docker run - p 9200:9200 - p 9300:9300 -- name="es01" - e ES_JAVA_OPTS="-Xms512m -Xmx512m" - e node. name="es01" - v path/elasticsearch. yml:/ usr/share/elasticsearch/config/elasticsearch. yml docker. elastic. co/elasticsearch/elasticsearch:7. 4. 2
docker run - p 9201:9200 - p 9301:9301 -- name="es02" - e ES_JAVA_OPTS="-Xms512m -Xmx512m" - e node. name="es02" - v path/elasticsearch. yml:/ usr/share/elasticsearch/config/elasticsearch. yml docker. elastic. co/elasticsearch/elasticsearch:7. 4. 2
docker run - p 9202:9200 - p 9302:9302 -- name="es03" - e ES_JAVA_OPTS="-Xms512m -Xmx512m" - e node. name="es03" - v path/elasticsearch. yml:/ usr/share/elasticsearch/config/elasticsearch. yml docker. elastic. co/elasticsearch/elasticsearch:7. 4. 2
启动 命令
docker run -p 9200 :9200 -p 9300 :9300 --name= "es01" -e ES_JAVA_OPTS = "-Xms512m -Xmx512m" -e node.name= "es01" -v path/elasticsearch.yml:/usr/share/elasticsearch/config/elasticsearch.yml docker.elastic.co/elasticsearch/elasticsearch:7.4.2
docker run -p 9201 :9200 -p 9301 :9301 --name= "es02" -e ES_JAVA_OPTS = "-Xms512m -Xmx512m" -e node.name= "es02" -v path/elasticsearch.yml:/usr/share/elasticsearch/config/elasticsearch.yml docker.elastic.co/elasticsearch/elasticsearch:7.4.2
docker run -p 9202 :9200 -p 9302 :9302 --name= "es03" -e ES_JAVA_OPTS = "-Xms512m -Xmx512m" -e node.name= "es03" -v path/elasticsearch.yml:/usr/share/elasticsearch/config/elasticsearch.yml docker.elastic.co/elasticsearch/elasticsearch:7.4.2
开放端口
systemctl start firewalld
firewall-cmd --zone= public --add-port= 1935 /tcp --permanent
--zone
--add-port= 1935 /tcp
--permanent
firewall-cmd --reload
netstat -ntlp //查看当前所有tcp端口·
netstat -ntulp | grep 1935 //查看所有1935端口使用情况
遇到的报错
Elasticsearch master not discovered yet, this node has not previously joined a bootstrapped ( v7+) cluster
transport.profiles.default.port: 9301
测试
curl -XGET 'http://192.168.1.101:9200/_cat/nodes?v'
curl -XPUT '192.168.1.101:9200/accounts/person/1?pretty' -H 'content-Type:application/json' -d '
{
"user": "张三",
"title": "⼯程师",
"desc": "数据库管理"
}'
curl -X PUT '192.168.1.101:9200/accounts/person/2?pretty' -H 'content-Type:application/json' -d '
{
"user": "赵四",
"title": "设计师",
"desc": "UI设计"
}'
curl -X GET '192.168.1.101:9200/accounts/person/_search?pretty'