1. 准备目录
mkdir -p /elk/elasticsearch
mkdir -p /elk/elasticsearch/data
mkdir -p /elk/elasticsearch/plugin
mkdir -p /elk/kibana
cd /elk
chmod 777 -R elasticsearch
chmod 777 -R kibana
2. 创建docker-compose.yml
version: "3.1"
# 服务配置
services:
elasticsearch:
container_name: elasticsearch-8.8.1
image: docker.elastic.co/elasticsearch/elasticsearch:8.8.1
# 用来给容器root权限(不安全)可移除
privileged: true
# 在linux里ulimit命令可以对shell生成的进程的资源进行限制
ulimits:
memlock:
soft: -1
hard: -1
environment:
- "ES_JAVA_OPTS=-Xms1024m -Xmx1024m"
- "http.host=0.0.0.0"
- "node.name=elastic01"
- "cluster.name=cluster_elasticsearch"
- "discovery.type=single-node"
- "ELASTIC_PASSWORD=123456"
ports:
- "9200:9200"
- "9300:9300"
volumes:
# - ./elasticsearch/config:/usr/share/elasticsearch/config
- ./elasticsearch/data:/usr/share/elasticsearch/data
- ./elasticsearch/plugin:/usr/share/elasticsearch/plugins
networks:
- elastic_net
kibana:
container_name: kibana-8.8.1
image: docker.elastic.co/kibana/kibana:8.8.1
ports:
- "5601:5601"
#volumes:
# - ./kibana/config:/usr/share/kibana/config
networks:
- elastic_net
# 网络配置
networks:
elastic_net:
driver: bridge
3. 复制es、kibana配置文件
cd /elk
docker-compose up -d
docker cp elasticsearch-8.8.1:/usr/share/elasticsearch/config ./elasticsearch
docker cp kibana-8.8.1:/usr/share/kibana/config ./kibana
cd /elk/elasticsearch
chmod 777 -R config
cd /elk/kibana
chmod 777 -R config
4. 修改配置文件
elasticsearch.yml
cluster.name: "cluster_elasticsearch"
network.host: 0.0.0.0
node.name: "elastic01"
# 以单一节点模式启动
discovery.type: single-node
# 是否支持跨域
http.cors.enabled: true
# # 表示支持所有域名
http.cors.allow-origin: "*"
# # 内存交换的选项,官网建议为true
bootstrap.memory_lock: true
kibana.yml
i18n.locale: zh-CN
server.host: "0.0.0.0"
server.shutdownTimeout: "5s"
# 这里的 elasticsearch:9200 使用了容器内连
elasticsearch.hosts: [ "http://elasticsearch:9200" ]
monitoring.ui.container.elasticsearch.enabled: true
5. 调整docker-compose.yml
启动原配置文件中的注释
volumes:
- ./elasticsearch/config:/usr/share/elasticsearch/config
volumes:
- ./kibana/config:/usr/share/kibana/config
6. 重启容器
cd /elk
docker-compose up -d
7. 重置密码
重置kibana用户elastic和kibana_system密码
# 上面设置了密码为123456,如果需要重置,重置后需同步文件配置
# docker exec -it elasticsearch-8.8.1 /usr/share/elasticsearch/bin/elasticsearch-reset-password -uelastic
docker exec -it elasticsearch-8.8.1 /usr/share/elasticsearch/bin/elasticsearch-reset-password -ukibana_system
# kibana重置密码输出
[root@VM-8-5-centos es]# docker exec -it elasticsearch-8.8.1 /usr/share/elasticsearch/bin/elasticsearch-reset-password -ukibana_system
WARNING: Owner of file [/usr/share/elasticsearch/config/users] used to be [root], but now is [elasticsearch]
WARNING: Owner of file [/usr/share/elasticsearch/config/users_roles] used to be [root], but now is [elasticsearch]
This tool will reset the password of the [kibana_system] user to an autogenerated value.
The password will be printed in the console.
Please confirm that you would like to continue [y/N]y
Password for the [kibana_system] user successfully reset.
New value: JdxBr0Cf_1TlQbO3G5FK
其中密码为: JdxBr0Cf_1TlQbO3G5FK
8. 将kibana_system密码配置到kibana中
elasticsearch.username: kibana_system
elasticsearch.password: JdxBr0Cf_1TlQbO3G5FK
9. 访问
重启容器
cd /elk
docker-compose stop
docker-compose up -d
10. 测试访问
访问测试
查看es状态 http://ip:9200
查看kibana页面http://xx:5601
,使用elastic和前面的密码进行登录
# 如果需要验证码,则验证码获取
docker exec -it kibana-8.8.1 /usr/share/kibana/bin/kibana-verification-code