Docker-compose实例 Elasticsearch

Docker运行Elasticsearch

Elasticsearch

创建文件夹

1
2
mkdir /usr/local/elasticsearch/{config,data,log} -pv
chown 1000:1000 /usr/local/elasticsearch/* -R

创建配置文件 主

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
vim /usr/local/elasticsearch/config/es.yml

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


network.bind_host: 0.0.0.0
network.publish_host: 192.168.1.241
http.port: 9200
transport.tcp.port: 9300
http.cors.enabled: true
http.cors.allow-origin: "*"

discovery.zen.ping.unicast.hosts: ["es-master:9300", "es-node1:9300", "es-node2:9300"]
discovery.zen.minimum_master_nodes: 2
discovery.zen.ping_timeout: 5s

bootstrap.memory_lock: true
action.destructive_requires_name: true
cluster.initial_master_nodes: ["es-master"]

#ingest.geoip.downloader.enabled: false

docker-compose.yml

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
version: '3'
services:
es-master:
image: harbor:59001/library/elasticsearch:7.6.2
container_name: es-master
environment:
- "ES_JAVA_OPTS=-Xms4096m -Xmx4096m"
ulimits:
memlock:
soft: -1
hard: -1
nofile:
soft: 65536
hard: 65536
restart: always
volumes:
- /usr/local/elasticsearch/config/es.yml:/usr/share/elasticsearch/config/elasticsearch.yml:ro
- /usr/local/elasticsearch/data:/usr/share/elasticsearch/data:rw
- /usr/local/elasticsearch/log:/usr/share/elasticsearch/log:rw
ports:
- 9200:9200
- 9300:9300
: # 设置容器 hosts
- "es-master:192.168.1.241"
- "es-node1:192.168.1.250"
- "es-node2:192.168.1.171"

创建配置文件 从

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
vim /usr/local/elasticsearch/config/es.yml

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

network.bind_host: 0.0.0.0
network.publish_host: 192.168.1.250
http.port: 9200
transport.tcp.port: 9300
http.cors.enabled: true
http.cors.allow-origin: "*"

discovery.zen.ping.unicast.hosts: ["es-master:9300", "es-node1:9300", "es-node2:9300"]
discovery.zen.minimum_master_nodes: 2
discovery.zen.ping_timeout: 5s

bootstrap.memory_lock: true
action.destructive_requires_name: true
cluster.initial_master_nodes: ["es-master"]

docker-compose.yml

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
version: '3'
services:
es-master:
image: 192.168.1.63:59001/library/elasticsearch:7.6.2
container_name: es-node2
environment:
- "ES_JAVA_OPTS=-Xms4096m -Xmx4096m"
restart: always
ulimits:
memlock:
soft: -1
hard: -1
nofile:
soft: 65536
hard: 65536
volumes:
- /usr/local/elasticsearch/config/es.yml:/usr/share/elasticsearch/config/elasticsearch.yml:ro
- /usr/local/elasticsearch/data:/usr/share/elasticsearch/data:rw
- /usr/local/elasticsearch/log:/usr/share/elasticsearch/log:rw
ports:
- 9200:9200
- 9300:9300
extra_hosts: # 设置容器 hosts
- "es-master:192.168.1.241"
- "es-node1:192.168.1.250"
- "es-node2:192.168.1.171"