elasticsearch:8.1.0
1. 创建network
docker network create es-net
2. 启动容器es
docker run -d --name es -p 9200:9200 -p 9300:9300 -e "discovery.type=single-node" -e ES_JAVA_OPTS="-Xms64m -Xmx512m" -v es-date:/usr/share/elasticsearch/data -v es-plugins:/usr/share/elasticsearch/plugins --network es-net elasticsearch:8.1.0
-m :设置容器使用内存最大值;
-d :后台运行容器,并返回容器ID;
--name : 容器命名;
-p :端口映射 第一个端口是宿主机端口,第二个端口是容器端口;
-v : 把es的配置文件映射到宿主机的指定目录了;
--net/--network :桥接名,这个需要提前创建,加到同一个网络桥接里的容器可以互相通过容器名ping通;
--restart : 容器重启模式;
-e :设置环境变量;
elasticsearch:8.1.0 :如果只是写elasticsearch,tag就是latest;
3. 将配置文件elasticsearch.yml从容器中复制到宿主机
docker cp es:/usr/share/elasticsearch/config/elasticsearch.yml ./elasticsearch.yml
4. 修改elasticsearch.yml
cluster.name: "docker-cluster"
network.host: 0.0.0.0
# 配置远程访问
http.host: 0.0.0.0
# 因为elasticsearch与elasticsearch-head工具是前后端分离项目,所以需要处理跨域问题
http.cors.enabled: true
http.cors.allow-origin: "*"
# 开启账户密码验证
http.cors.allow-headers: Authorization,X-Requested-With,Content-Length,Content-Type
xpack.security.enabled: true
xpack.security.transport.ssl.enabled: true
5. 将修改后的文件覆盖到容器内
docker cp ./elasticsearch.yml es:/usr/share/elasticsearch/config/elasticsearch.yml
6. 重启elasticsearch
docker restart es
7. 设置用户名密码
设置elastic,apm_system,kibana,kibana_system,logstash_system,beats_system,remote_monitoring_user 这些用户的密码文章来源:https://www.toymoban.com/news/detail-826704.html
docker exec -it es elasticsearch-setup-passwords interactive
elasticsearch@882e202cff35:~$ elasticsearch-setup-passwords interactive
******************************************************************************
Note: The 'elasticsearch-setup-passwords' tool has been deprecated. This command will be removed in a future release.
******************************************************************************
Initiating the setup of passwords for reserved users elastic,apm_system,kibana,kibana_system,logstash_system,beats_system,remote_monitoring_user.
You will be prompted to enter passwords as the process progresses.
Please confirm that you would like to continue [y/N]y
Enter password for [elastic]:
Reenter password for [elastic]:
Enter password for [apm_system]:
Reenter password for [apm_system]:
Enter password for [kibana_system]:
Reenter password for [kibana_system]:
Enter password for [logstash_system]:
Reenter password for [logstash_system]:
Enter password for [beats_system]:
Reenter password for [beats_system]:
Enter password for [remote_monitoring_user]:
Reenter password for [remote_monitoring_user]:
Changed password for user [apm_system]
Changed password for user [kibana_system]
Changed password for user [kibana]
Changed password for user [logstash_system]
Changed password for user [beats_system]
Changed password for user [remote_monitoring_user]
Changed password for user [elastic]
kibana:8.1.0
1. 启动容器
docker run -d --name kibana -e ELASTICSEARCH_HOSTS=http://es:9200 --network=es-net -p 5601:5601 kibana:8.1.0
2. 将配置文件 kibana.yml 从容器中复制到宿主机
docker cp kibana:/usr/share/kibana/config/kibana.yml ./kibana.yml
3. 修改kibana.yml
server.name: kibana
# kibana的主机地址 0.0.0.0可表示监听所有IP
server.host: "0.0.0.0"
# kibana访问es的URL
elasticsearch.hosts: [ "http://es:9200" ]
elasticsearch.username: 'kibana'
elasticsearch.password: '123456'
# 显示登陆页面
xpack.monitoring.ui.container.elasticsearch.enabled: true
# 语言
i18n.locale: "zh-CN"
4. 将修改后的文件覆盖到容器内
docker cp ./kibana.yml kibana:/usr/share/kibana/config/kibana.yml
5. 重启kibana
docker restart kibana
6. 访问:http://ip:5601/app/kibana/home
文章来源地址https://www.toymoban.com/news/detail-826704.html
到了这里,关于docker 启动 elasticsearch|kibana的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!