系统环境:
centos7.6
Docker version 20.10.5, build 55c4c88
案例:
使用docker-compose安装elasticsearch6.5.4
docker-compose.yml
version: "3.1"
services:
elasticsearch:
image: daocloud.io/library/elasticsearch:6.5.4 #仓库中的镜像名
restart: always #跟随docker的启动而启动
container_name: elasticsearch #自定义的镜像名
environment: #环境变量
- "ES_JAVA_OPTS=-Xms256m -Xmx256m" #设置jvm的初始内存,避免启动失败
volumes: #数据卷映射
- /opt/elasticsearch-docker/plugins:/usr/share/elasticsearch/plugins
- /opt/elasticsearch-docker/data:/usr/share/elasticsearch/data
ports: #服务端口
- 9200:9200
kibana:
image: daocloud.io/library/kibana:6.5.4
restart: always
container_name: kibana
ports:
- 5601:5601
environment:
- elasticsearch_url=http://elasticsearch:9200
#- "I18N_LOCALE=zh-CN" #当前版本不可用
depends_on:
- elasticsearch #kibana在elasticsearch启动之后再启动
Kibana将语言设置为中文
注:6.7以后系统支持中文
Kibana默认安装的是英文版的,修改语言只需要添加一行配置即可.在kibana.yml配置文件中添加一行配置
i18n.locale: "zh-CN"
然后手动重启kibana服务即可
docker restart kibana
解决docker挂载配置文件错误
如下报错
Caused by: java.nio.file.AccessDeniedException: /usr/share/elasticsearch/data/nodes
原因是宿主机的配置目录需要读写权限
/opt/elasticsearch-docker/data:/usr/share/elasticsearch/data
赋予它读写权限命令:
chmod 777 /opt/elasticsearch-docker/data
Docker 启动elasticsearch报内存不足解决
使用docker logs -f 容器ID 查看日志发现:
ERROR: [1] bootstrap checks failed
[1]: max virtual memory areas vm.max_map_count [65530] likely too low, increase to at least [262144]
[2]: 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
需要修改jvm.options文件
将初始化的内存改写为较小的值,以保证服务的正常启动
首先查找jvm.options文件位置
命令:
find / -name jvm.options
找到es对应 jvm.options
-Xms1g #改成512m
-Xmx1g #改成512m
或者设置
sysctl -w vm.max_map_count=262144
推荐在启动时设置初始内存大小
docker run的写法:docker run -e ES_JAVA_OPTS="-Xms256m -Xmx256m" -d -p 9200:9200 --name 容器名 镜像的标识|镜像名称
docker-compose的写法:
environment:
- "ES_JAVA_OPTS=-Xms256m -Xmx256m"
Q.E.D.