Docker相关开发环境安装( 五 )


无镜像包,pull
docker search elasticsearch:7.9.3
docker pull elasticsearch:7.9.3
1.3.创建宿主机文件夹与容器映射
mkdir -p /data/elasticsearch/configmkdir -p /data/elasticsearch/datamkdir -p /data/elasticsearch/logsmkdir -p /data/elasticsearch/plugins
.yml 文件
# 可访问IPhttp.host: 0.0.0.0# 跨域http.cors.enabled: truehttp.cors.allow-origin: "*"http.cors.allow-headers: Authorization# 安全功能xpack.security.enabled: false
在宿主机宿主机文件夹给予权限
sudo chown -R 1000:1000 /data/elasticsearch
1.4.运行镜像命令
docker run -d--restart=always --name es \-e ES_JAVA_OPTS="-Xms512m -Xmx512m" \-e "discovery.type=single-node" \-v /data/elasticsearch/config/elasticsearch.yml:/usr/share/elasticsearch/config/elasticsearch.yml \-v /data/elasticsearch/data:/usr/share/elasticsearch/data \-v /data/elasticsearch/logs:/usr/share/elasticsearch/logs \-v /data/elasticsearch/plugins:/usr/share/elasticsearch/plugins \--privileged \--network es-net \-p 9200:9200 \-p 9300:9300 \elasticsearch:7.9.3
命令解释:
1.5.测试访问
:9200/
如下显示则成功:
{"name" : "793680b1ef20","cluster_name" : "elasticsearch","cluster_uuid" : "nvJbqediRJiXz-rT3s_QYg","version" : {"number" : "7.17.7","build_flavor" : "default","build_type" : "docker","build_hash" : "78dcaaa8cee33438b91eca7f5c7f56a70fec9e80","build_date" : "2022-10-17T15:29:54.167373105Z","build_snapshot" : false,"lucene_version" : "8.11.1","minimum_wire_compatibility_version" : "6.8.0","minimum_index_compatibility_version" : "6.0.0-beta1"},"tagline" : "You Know, for Search"}
1.6.配置 TLS 安全功能 1.6.1、在 .yml 中添加如下配置
# 安全功能xpack.security.enabled: truexpack.security.transport.ssl.enabled: true
1.6.2、重启服务
systemctl restart elasticsearch
1.6.3、设置密码
# 进入容器docker exec -it es /bin/bash# 生成密码/usr/share/elasticsearch/bin/elasticsearch-setup-passwords interactive
1.6.4、验证
浏览器直接访问:9200,会出现输入用户名、密码的弹窗,
输入和自己设置的密码后,才能看到信息;
账号:elastic 密码:自己设置的
1.6.5、修改密码
下面的示例为将的密码设置为""
curl -H "Content-Type:application/json" -XPOST -u elastic 'http://127.0.0.1:9200/_xpack/security/user/elastic/_password' -d '{ "password" : "123456" }'
*如果密码忘了怎么办?如何重置密码?
1、修改.yml 配置,将身份验证相关配置屏蔽掉;
2、重启ES,查看下索引,发现多了一个.-7索引,将其删除
3、到此就回到ES没有设置密码的阶段了,如果想重新设置密码,请从第一步开始
2、安装
可视化工具,必须要和es版本保持一致
2.1.拉取镜像
docker pull kibana:7.9.3
2.2.创建宿主机文件夹与容器映射
mkdir -p /data/kibana/config
.yml 文件
## ** THIS IS AN AUTO-GENERATED FILE **## Default Kibana configuration for docker targetserver.name: kibanaserver.host: "0"elasticsearch.hosts: [ "http://elasticsearch:9200" ]monitoring.ui.container.elasticsearch.enabled:true
2.2.运行镜像命令
docker run -d --restart=always --name kibana \-e ELASTICSEARCH_HOSTS=http://es:9200 \-v /data/kibana/config:/usr/share/kibana/config \--network=es-net \-p 5601:5601\kibana:7.9.3
2.3.测试访问
:5601/
2.3.4.给设置账号密码
第1步:配置账号密码,在.yml配置文件中添加以下内容 。命令:vi /.yml