elasticsearch设置账号和密码

1、es安装,挂载路径根据实际情况修改

复制代码
docker run -d --restart always \
--name es \
-e "ES_JAVA_OPTS=-Xms512m -Xmx512m" \
-e "discovery.type=single-node" \
-e "TZ=Asia/Shanghai" \
-v /mnt/data/efk/es/data:/usr/share/elasticsearch/data \
-v /home/clouduser/cxb/efk/account-efk/es-plugins:/usr/share/elasticsearch/plugins \
-v /home/clouduser/cxb/efk/account-efk/es-config/elastic-certificates.p12:/usr/share/elasticsearch/config/elastic-certificates.p12 \
-v /home/clouduser/cxb/efk/account-efk/es-config/elasticsearch.yml:/usr/share/elasticsearch/config/elasticsearch.yml \
--network docker-common-net \
-p 9200:9200 \
-p 9300:9300 \
elasticsearch:8.6.0

2、生成证书

复制代码
#进入es容器
docker exec -it es /bin/bash

# 生成ca
./bin/elasticsearch-certutil ca

注:两个红方框位置直接回车

3、生成cert证书

复制代码
# 再生成cert
./bin/elasticsearch-certutil cert --ca elastic-stack-ca.p12

注:前两个红框直接回车,第三个红框可以直接回车,也可以输入证书密码

4、查看证书

复制代码
# 查看两个证书
ls

5、退出容器

复制代码
exit

6、拷贝es容器的证书

或者直接拷贝到宿主机,通过挂载的方式挂载进去。

复制代码
# 进入es的config文件夹
mkdir -p /data/es/single/config && cd /data/es/single/config
 
# 拷贝容器证书
docker cp es:/usr/share/elasticsearch/elastic-certificates.p12 ./
 
# 授权证书
chmod 777 elastic-certificates.p12

7、添加配置文档

复制代码
vi elasticsearch.yml

network.host: 0.0.0.0
xpack.security.enabled: true
xpack.security.transport.ssl.enabled: true
xpack.security.transport.ssl.keystore.type: PKCS12
xpack.security.transport.ssl.verification_mode: certificate
xpack.security.transport.ssl.keystore.path: /usr/share/elasticsearch/config/elastic-certificates.p12
xpack.security.transport.ssl.truststore.path: /usr/share/elasticsearch/config/elastic-certificates.p12
xpack.security.transport.ssl.truststore.type: PKCS12
 
xpack.security.audit.enabled: true

修改docker-compon.yml

复制代码
# 进入文件目录
cd /data/es/single
 
# 添加两行
- /data/es/single/config/elastic-certificates.p12:/usr/share/elasticsearch/config/elastic-certificates.p12
- /data/es/single/config/elasticsearch.yml:/usr/share/elasticsearch/config/elasticsearch.yml

目前青田实际的yml文件:通过挂载的方式实现的上面两个步骤

复制代码
cluster.name: "docker-cluster"
network.host: 0.0.0.0
xpack.security.enabled: true
xpack.security.transport.ssl.enabled: true
xpack.security.transport.ssl.keystore.type: PKCS12
xpack.security.transport.ssl.verification_mode: certificate
xpack.security.transport.ssl.keystore.path: /usr/share/elasticsearch/config/elastic-certificates.p12
xpack.security.transport.ssl.truststore.path: /usr/share/elasticsearch/config/elastic-certificates.p12
xpack.security.transport.ssl.truststore.type: PKCS12
 
xpack.security.audit.enabled: true

8、设置es账号、密码

复制代码
# 进入es容器
docker exec -it es /bin/bash
 
# 设置密码(账号默认为 elastic)
./bin/elasticsearch-setup-passwords interactive

注:密码可设置为同一个密码,容易记住

9、给kibana设置账目密码

/home/clouduser/cxb/efk/account-efk/kibana/kibana.yml

复制代码
i18n.locale: zh-CN
server.host: "0.0.0.0"
server.shutdownTimeout: "5s"
elasticsearch.hosts: [ "http://es:9200" ]
elasticsearch.username: "root"
elasticsearch.password: "1q*********"

1,FATAL Error: [config validation of [elasticsearch].username]: value of "elastic" is forbidden. This is a superuser account that cannot write to system indices that Kibana needs to function. Use a service account token instead.

界面会显示:Kibana server is not ready yet.

这是因为es 不允许使用elastic用户登录kibana

所以这里需要创建一个自定义用户

进入es容器,docker exec -it es bash,执行bin/elasticsearch-users useradd test

添加了用户,并需要给这个用户添加角色不然会报错

角色授权

bin/elasticsearch-users roles -a superuser test

bin/elasticsearch-users roles -a kibana_system test

相关推荐
洛森唛4 小时前
Elasticsearch DSL 查询语法大全:从入门到精通
后端·elasticsearch
字节跳动数据平台8 小时前
代码量减少 70%、GPU 利用率达 95%:火山引擎多模态数据湖如何释放模思智能的算法生产力
大数据
得物技术10 小时前
深入剖析Spark UI界面:参数与界面详解|得物技术
大数据·后端·spark
武子康11 小时前
大数据-238 离线数仓 - 广告业务 Hive分析实战:ADS 点击率、购买率与 Top100 排名避坑
大数据·后端·apache hive
武子康1 天前
大数据-237 离线数仓 - Hive 广告业务实战:ODS→DWD 事件解析、广告明细与转化分析落地
大数据·后端·apache hive
大大大大晴天1 天前
Flink生产问题排障-Kryo serializer scala extensions are not available
大数据·flink
Elasticsearch2 天前
如何使用 Agent Builder 排查 Kubernetes Pod 重启和 OOMKilled 事件
elasticsearch
Elasticsearch3 天前
通用表达式语言 ( CEL ): CEL 输入如何改进 Elastic Agent 集成中的数据收集
elasticsearch
武子康3 天前
大数据-236 离线数仓 - 会员指标验证、DataX 导出与广告业务 ODS/DWD/ADS 全流程
大数据·后端·apache hive
武子康4 天前
大数据-235 离线数仓 - 实战:Flume+HDFS+Hive 搭建 ODS/DWD/DWS/ADS 会员分析链路
大数据·后端·apache hive