编写docker-compose.yml文件
version: "2"
services:
demoes1:
image: elastic/elasticsearch:6.3.1
container_name: demoes1
restart: unless-stopped
environment:
- "ES_JAVA_OPTS=-Xms5g -Xmx5g"
ulimits:
memlock:
soft: -1
hard: -1
nofile:
soft: 65536
hard: 65536
ports:
- "9200:9200"
- "9300:9300"
volumes:
- /home/es/config/es1.yml:/usr/share/elasticsearch/config/elasticsearch.yml:ro
- /home/es/data1:/usr/share/elasticsearch/data
networks:
- demo-es
demoes2:
image: elastic/elasticsearch:6.3.1
container_name: demoes2
restart: unless-stopped
environment:
- "ES_JAVA_OPTS=-Xms5g -Xmx5g"
ulimits:
memlock:
soft: -1
hard: -1
nofile:
soft: 65536
hard: 65536
ports:
- "9201:9200"
- "9301:9300"
volumes:
- /home/es/config/es2.yml:/usr/share/elasticsearch/config/elasticsearch.yml:ro
- /home/es/data2:/usr/share/elasticsearch/data
networks:
- demo-es
demoes3:
image: elastic/elasticsearch:6.3.1
container_name: demoes3
restart: unless-stopped
environment:
- "ES_JAVA_OPTS=-Xms5g -Xmx5g"
ulimits:
memlock:
soft: -1
hard: -1
nofile:
soft: 65536
hard: 65536
ports:
- "9202:9200"
- "9302:9300"
volumes:
- /home/es/config/es3.yml:/usr/share/elasticsearch/config/elasticsearch.yml:ro
- /home/es/data3:/usr/share/elasticsearch/data
networks:
- demo-es
demokibana:
image: elastic/kibana:6.3.1
container_name: demokibana
restart: unless-stopped
ports:
- 5601:5601
environment:
ELASTICSEARCH_URL: http://demoes1:9200
ELASTICSEARCH_HOSTS: http://demoes1:9200
networks:
- demo-es
networks:
demo-es:
driver: bridge
2、编写配置文件
es1.yml
cluster.name: elasticsearch-cluster
node.name: demoes1
node.master: true
node.data: true
network.host: 0.0.0.0
http.port: 9200
transport.tcp.port: 9300
http.cors.enabled: true
http.cors.allow-origin: "*"
discovery.zen.ping.unicast.hosts: ["demoes1:9300", "demoes2:9300", "demoes3:9300"]
discovery.zen.minimum_master_nodes: 2
discovery.zen.ping_timeout: 5s
bootstrap.memory_lock: true
action.destructive_requires_name: true
es2.yml
cluster.name: elasticsearch-cluster
node.name: demoes2
node.master: true
node.data: true
network.host: demoes2
http.port: 9200
transport.tcp.port: 9300
http.cors.enabled: true
http.cors.allow-origin: "*"
discovery.zen.ping.unicast.hosts: ["demoes1:9300", "demoes2:9300", "demoes3:9300"]
discovery.zen.minimum_master_nodes: 2
discovery.zen.ping_timeout: 5s
bootstrap.memory_lock: true
action.destructive_requires_name: true
es3.yml
cluster.name: elasticsearch-cluster
node.name: demoes3
node.master: false
node.data: true
network.host: demoes3
http.port: 9200
transport.tcp.port: 9300
http.cors.enabled: true
http.cors.allow-origin: "*"
discovery.zen.ping.unicast.hosts: ["demoes1:9300", "demoes2:9300", "demoes3:9300"]
discovery.zen.minimum_master_nodes: 2
discovery.zen.ping_timeout: 5s
bootstrap.memory_lock: true
action.destructive_requires_name: true
4、配置文件说明
#集群名称
cluster.name: elasticsearch-cluster
#节点名称
node.name: demoes1
#是否是主节点
node.master: true
节点数据
node.data: true
#设置 host 为 0.0.0.0 ,即可启用该物理机器所有网卡网络访问
#也可以用下面配置文件替代
#network.bind_host: 0.0.0.0 //绑定网络(访问)
#network.publish_host: 192.168.137.128(或者hckjes1) //公共集群网络(集群连接)
network.host: lcyes1
#设置对外服务的http端口,默认为9200。
http.port: 9200
#设置节点间交互的tcp端口,默认是9300。
transport.tcp.port: 9300
#是否使用http协议对外提供服务,默认为true,开启。
http.cors.enabled: true
#是否可以跨域访问,*表示可以支持所有
http.cors.allow-origin: "*"
#设置集群中master节点的初始列表,可以通过这些节点来自动发现新加入集群的节点。
discovery.zen.ping.unicast.hosts: ["demoes1:9300", "demoes2:9300", "demoes3:9300"]
#设置这个参数来保证集群中的节点可以知道其它N个有master资格的节点。默认为1,对于大的集群来说,可以设置大一点的值(2-4)
discovery.zen.minimum_master_nodes: 2
#设置集群中自动发现其它节点时ping连接超时时间,默认为3秒,对于比较差的网络环境可以高点的值来防止自动发现时出错。
discovery.zen.ping_timeout: 5s
#锁定物理内存地址,防止es内存被交换出去,也就是避免es使用swap交换分区,频繁的交换,会导致IOPS变高
bootstrap.memory_lock: true
#生产环境建议设置为true,删除索引库的时候必须显式指定,否则可能会误删索引库中的索引库
action.destructive_requires_name: true