编写docker-compose.yml
version: '3' services: # elasticsearch elasticsearch:
image: elasticsearch:7.5.0
container_name: elasticsearch # docker启动后的名称
privileged: true
# restart: always #出现异常自动重启
ports:
- 9200:9200
- 9300:9300
environment:
cluster.name: elasticsearch # es 名称
ES_JAVA_OPTS: "-Xmx512m -Xms512m"
volumes:
- ./elasticsearch/plugins:/usr/share/elasticsearch/plugins
启动
docker-compose up
启动出现错误,提示虚拟内存设置过低
elasticsearch | ERROR: [1] bootstrap checks failed
elasticsearch | [1]: max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144]
elasticsearch | [2020-01-28T04:57:00,139][INFO ][o.e.n.Node ] [5jRVKcB] stopping ...
elasticsearch | [2020-01-28T04:57:00,206][INFO ][o.e.n.Node ] [5jRVKcB] stopped
elasticsearch | [2020-01-28T04:57:00,206][INFO ][o.e.n.Node ] [5jRVKcB] closing ...
elasticsearch | [2020-01-28T04:57:00,230][INFO ][o.e.n.Node ] [5jRVKcB] closed
elasticsearch | [2020-01-28T04:57:00,232][INFO ][o.e.x.m.p.NativeController] [5jRVKcB] Native controller process has stopped - no new native processes can be started
elasticsearch exited with code 78
查看max_map_count
cat /proc/sys/vm/max_map_count
65530
设置max_map_count
[root@wang ElasticSearch]# sysctl -w vm.max_map_count=262144
vm.max_map_count = 262144
再次启动
提示
elasticsearch | ERROR: [1] bootstrap checks failed
elasticsearch | [1]: the default discovery settings are unsuitable for production use; at least one of [discovery.seed_hosts, discovery.seed_providers, cluster.initial_master_nodes] must be configured
解决:
在docker-compose.yml的environment添加
discovery.type: single-node
再次启动,正常
访问http://49.235.47.130:9200
{
"name" : "5jRVKcB",
"cluster_name" : "elasticsearch",
"cluster_uuid" : "FgMWVTfCTjazmef9TQqpqA",
"version" : {
"number" : "6.8.6",
"build_flavor" : "default",
"build_type" : "docker",
"build_hash" : "3d9f765",
"build_date" : "2019-12-13T17:11:52.013738Z",
"build_snapshot" : false,
"lucene_version" : "7.7.2",
"minimum_wire_compatibility_version" : "5.6.0",
"minimum_index_compatibility_version" : "5.0.0"
},
"tagline" : "You Know, for Search"
}
安装成功
完整的docker-compose.yml
version: '3'
services:
# elasticsearch
elasticsearch:
image: elasticsearch:7.5.0
container_name: elasticsearch # docker启动后的名称
privileged: true
# restart: always #出现异常自动重启
ports:
- 9200:9200
- 9300:9300
environment:
cluster.name: elasticsearch # es 名称
ES_JAVA_OPTS: "-Xmx512m -Xms512m"
discovery.type: single-node
volumes:
- ./elasticsearch/plugins:/usr/share/elasticsearch/plugins
参考文档:
https://www.elastic.co/guide/en/elasticsearch/reference/7.0/docker.html#docker-cli-run-prod-mode