Elasticsearch登陆认证
Elasticsearch 单节点登录认证
1.在 elasticsearch.yml 中添加如下配置
# 配置X-Pack
http.cors.enabled: true
http.cors.allow-origin: "*"
http.cors.allow-headers: Authorization
xpack.security.enabled: true
xpack.security.transport.ssl.enabled: true
需要重启es
2.设置密码
cd /home/es/elasticsearch-7.8.1
./bin/elasticsearch-setup-passwords interactive -u 'http://192.168.88.110:7920'
Elasticsearch 集群节点登录认证
1.0 启动三台es
./bin/elasticsearch -d
#查看 master 节点 curl http://192.168.88.110:7920/_cat/master 1.1执行命令激活xpack**
curl -H "Content-Type:application/json" -XPOST http://192.168.88.110:7920/_xpack/license/start_trial?acknowledge=true 1.2es开启xpack
设置密码,在master设置,node节点可以同步该用户名/密码
xpack.security.enabled: true 到此为止完成xpack集群,目前无SSL。
2.使用SSL
2.1master节点创建证书
#进入elasticsearch-7.8.1 cd /home/es/elasticsearch/ #生成CA证书【CA证书:elastic-stack-ca.p12】 ./bin/elasticsearch-certutil ca #保存elastic-stack-ca.p12路径并输入密码(123456) Please enter the desired output file [elastic-stack-ca.p12]: #指定证书文件名直接回车为默认 Enter password for elastic-stack-ca.p12 : #输入证书密码
#创建证书私钥 ./bin/elasticsearch-certutil cert --ca elastic-stack-ca.p12 #保存elastic-certificates.p12路径并输入密码(123456) #将上面生成的两个文件拷贝到elastic的config目录下 Enter password for CA (elastic-stack-ca.p12) : #上边设置ca的密码 我自己设置的:123456 Please enter the desired output file [elastic-certificates.p12]: #私钥的文件名,回车默认 Enter password for elastic-certificates.p12 : #私钥密码 123456
#如果是root用户创建的,即需要修改权限,建议都用es用户创建 chmod 664 elastic-certificates.p12 chmod 664 elastic-stack-ca.p12 #将生成的2个文件都移动到config文件夹中 mkdir xpack mv elastic-* ./xpack
#传证书和私钥到其他节点[需要输入当前用户的密码:我的是123456] cd xpack scp elastic-* wsy2:$PWD scp elastic-* wsy3:$PWD
- 修改配置文件elasticsearch.yml
[root@wsy1 elasticsearch-7.8.1]# cd /export/server/es/elasticsearch-6.5.4/config/ [root@wsy1 config]# vi elasticsearch.yml #补充:tcp端口,集群内部通讯使用 transport.tcp.port: 9300 #节点配置【默认,在生产中可以修改】 node.master: true #有成为主节点的资格,建议3的倍数 node.data: true #存储数据 #node.ingest: true #可以针对海量请求时进行负载均衡 #防止脑裂问题,官方推荐【N/2 +1】,其中N是具有master资格的节点的数量(我们的情况是3,因此这个参数设置为2 #discovery.zen.minimum_master_nodes: 2 #添加xpack认证参数【修改证书路径】 xpack.security.enabled: true xpack.security.transport.ssl.enabled: true xpack.security.transport.ssl.verification_mode: certificate # 证书认证级别 xpack.security.transport.ssl.keystore.path: /home/es/elasticsearch/elastic-certificates.p12 xpack.security.transport.ssl.truststore.path: /home/es/elasticsearch/elastic-certificates.p12 #
- 各个节点为 xpack.security.transport 添加密码,每个节点都执行这两个命令【我这里123456】
./bin/elasticsearch-keystore add xpack.security.transport.ssl.keystore.secure_password ./bin/elasticsearch-keystore add xpack.security.transport.ssl.truststore.secure_password
- 查看集群状态(也可以通过kibana或者其他工具查看)
http://192.168.88.111:7920/_cluster/health curl -u elastic:123456 -XGET 192.168.88.110:7920/_cat/health?v
- 启动elasticsearch
cd /export/server/es/elasticsearch-6.5.4/bin ./elasticsearch -d #后台启动 elasticsearch
- 设置加密密码【一个节点加密就行】【我全部弄的1234567】
./bin/elasticsearch-setup-passwords interactive
- logstash增加访问es集群的用户及密码
user => "elastic" # 注意:这里演示使用超级账号,安全起见最好是使用自定义的账号,并授予该用户创建索引的权限,具体看下方地址 password => "1234567" # 密码是上面步骤设置的
- elasticsearch-head访问es集群的用户及密码
elasticsearch-head插件此时再去访问有安全认证的es集群时,会发现无法进行查看,打开控制台可以看到报错:401 unauthorized
解决办法是修改elasticsearch.yml文件,增加以下配置。
#配置elasticsearch-head访问es集群的用户及密码 #http.cors.allow-headers: Authorization,content-type http.cors.allow-headers: Authorization,X-Requested-With,Content-Length,Content-Type #http://192.168.88.111:9100/?auth_user=elastic&auth_password=1234567 http://wsy1:9100/?auth_user=elastic&auth_password=changeme 修改三台es节点,然后重新启动,再次url+认证信息方式可以正常访问es集群。
http://192.168.88.111:9100/?auth_user=elkstack&auth_password=1234567
- Kibana组件访问带有安全认证的Elasticsearch集群
配置文件kibana.yml中需要加入以下配置
elasticsearch.username: "kibana" # 注意:此处不用超级账号elastic,而是使用kibana跟es连接的账号kibana elasticsearch.password: "1234567" 然后重启kibana,再次访问的话就就需要输入上述账号密码才能登陆访问了
不一样的地方:
在Management下面的Kibana最后出现一个Security,有User和Role
方便kibana多用户创建及角色权限控制
ES X-pack 过时
现象:
{
"error": {
"root_cause": [
{
"type": "security_exception",
"reason": "current license is non-compliant for [security]",
"license.expired.feature": "security",
"suppressed": [
{
"type": "security_exception",
"reason": "current license is non-compliant for [security]",
"license.expired.feature": "security"
}
]
}
],
"type": "security_exception",
"reason": "current license is non-compliant for [security]",
"license.expired.feature": "security",
"suppressed": [
{
"type": "security_exception",
"reason": "current license is non-compliant for [security]",
"license.expired.feature": "security"
}
]
},
"status": 403
}
6.3版本以后,Elastic Stack的默认发行版中包含基本(免费)层功能。无需许可证注册。
只需要降级到基础版本即可
可以在kibana执行:
POST /_license/start_basic?acknowledge=true
或者[记得替换 elasticsearch 为ip]
curl -XPOST "http://elasticsearch:9200/_license/start_basic?acknowledge=true"
例:
[elastic@node01 bin]$ curl -u elastic:123456 -XPOST "http://node01:7920/_license/start_basic?acknowledge=true"
{"acknowledged":true,"basic_was_started":true}[elastic@node01 bin]$ ll
__EOF__

本文链接:https://www.cnblogs.com/ChloeAilian/p/15513737.html
关于博主:评论和私信会在第一时间回复。或者直接私信我。
版权声明:本博客所有文章除特别声明外,均采用 BY-NC-SA 许可协议。转载请注明出处!
声援博主:如果您觉得文章对您有帮助,可以点击文章右下角【推荐】一下。您的鼓励是博主的最大动力!
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
· 没有源码,如何修改代码逻辑?
· 全程不用写代码,我用AI程序员写了一个飞机大战
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 记一次.NET内存居高不下排查解决与启示
· DeepSeek 开源周回顾「GitHub 热点速览」
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了