安装步骤:
一、容器编排脚本
在你的目录新建个文件夹 创建 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"
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
二、容器映射目录配置
2.1 挂在卷 同步配置
# 启动服务
docker-compose up -d
# 在docker-compose 目录中,执行容器文件拷贝到宿主机
# 1.创建 kibana 映射目录
# 2.拷贝 elasticsearch 配置
# 3.拷贝 kibana 配置
mkdir kibana
docker cp elasticsearch-8.8.1:/usr/share/elasticsearch/config ./elasticsearch/config
docker cp kibana-8.8.1:/usr/share/kibana/config ./kibana/config
2.2 elasticsearch配置
# 集群节点名称
node.name: "elastic01"
# 设置集群名称为elasticsearch
cluster.name: "cluster_elasticsearch"
# 网络访问限制
network.host: 0.0.0.0
# 以单一节点模式启动
discovery.type: single-node
# 是否支持跨域
http.cors.enabled: true
# 表示支持所有域名
http.cors.allow-origin: "*"
# 内存交换的选项,官网建议为true
bootstrap.memory_lock: true
# 修改安全配置 关闭 证书校验
xpack.security.http.ssl:
enabled: false
xpack.security.transport.ssl:
enabled: false
2.3 kibana配置
# Default Kibana configuration for docker target
i18n.locale: zh-CN
server.host: "0.0.0.0"
server.shutdownTimeout: "5s"
elasticsearch.hosts: [ "http://elasticsearch:9200" ]
monitoring.ui.container.elasticsearch.enabled: true
#此处为新生成的kibana账号和密码
elasticsearch.username: "kibana_system"
elasticsearch.password: "Wgnm5flBNMi*xQW5yHww"
2.4 重启服务加载配置
# 1\. 首先放开 docker-compose.yml 中的注释
- ./elasticsearch/config:/usr/share/elasticsearch/config
- ./kibana/config:/usr/share/kibana/config
# 2\. 更新容器
docker-compose up -d
# 3.访问地址:
elastic:http://localhost:9200
kibana:http://localhost:5601
三、访问elasticsearch
重置 elastic 用户密码
# 重置 elastic 用户密码
docker exec -it elasticsearch-8.8.1 /usr/share/elasticsearch/bin/elasticsearch-reset-password -uelastic
# 提示如下 输入 y:
This tool will reset the password of the [elastic] user to an autogenerated value.
The password will be printed in the console.
Please confirm that you would like to continue [y/N]
# 输入后显示结果 xxxxxx 即为密码
Password for the [elastic] user successfully reset.
New value: xxxxxx
4.3 密码kibana重置
# 重置 kibana_system 用户密码
docker exec -it elasticsearch-8.8.1 /usr/share/elasticsearch/bin/elasticsearch-reset-password -ukibana_system
# 提示如下 输入 y:
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]
# 输入后显示结果 xxxxxx 即为密码
Password for the [kibana_system] user successfully reset.
New value: xxxxxx
4.4 提示输入验证码
# 验证码获取
docker exec -it kibana-8.8.1 /usr/share/kibana/bin/kibana-verification-code
# 输入结果
Your verification code is: xxx xxx
本地测试账号密码
本地elasticSearch账号密码:
账号:elastic
密码:-KNVfdUof92By2WznPsi
本地kibana账号密码:
账号:kibana_system
密码:Wgnm5flBNMi*xQW5yHww