ES开启认证 本文章总结经验进步

Elasticsearch开启 安全认证详细步骤

Elasticsearch搭建环境

问题描述
解决步骤
一、生成证书:
二、生成秘钥
三、将凭证迁移到指定目录
四、凭证移动至每一台集群下面
五、修改配置文件(每一台es都需要添加)
六、在各个节点上添加密码(每一台es都需要操作)
七、逐个启动节点
八、设置密码
九、浏览器查看9200端口
十、es-head访问认证的es

Elasticsearch开启安全认证详细步骤
Elasticsearch搭建环境

Elasticsearch版本号:7.1.1
服务器版本: CentOS 7.4

一、生成证书:

输入./bin/elasticsearch-certutil ca

​ 碰到第一个直接回车,不用管
​ 碰到第二个输入密码,例如123456


[cjpt@localhost elasticsearch-7.3.2]$ ./bin/elasticsearch-certutil ca
This tool assists you in the generation of X.509 certificates and certificate
signing requests for use with SSL/TLS in the Elastic stack.

The 'ca' mode generates a new 'certificate authority'
This will create a new X.509 certificate and private key that can be used
to sign certificate when running in 'cert' mode.

Use the 'ca-dn' option if you wish to configure the 'distinguished name'
of the certificate authority

By default the 'ca' mode produces a single PKCS#12 output file which holds:
    * The CA certificate
    * The CA's private key

If you elect to generate PEM format certificates (the -pem option), then the output will
be a zip file containing individual files for the CA certificate and private key

Please enter the desired output file [elastic-stack-ca.p12]: 【不用管,直接回车】
Enter password for elastic-stack-ca.p12 : 【输入密码】
[cjpt@localhost elasticsearch-7.3.2]$ ll
总用量 1888
......(省略其他文件)
-rw-------.  1 cjpt cjpt    2524 419 16:28 elastic-stack-ca.p12


完成后会生成一个文件:elastic-stack-ca.p12

二、生成秘钥

./bin/elasticsearch-certutil cert --ca elastic-stack-ca.p12

中间需要输入刚才设置的密码就直接输入就可以了,需要输入路径的地方不要输入地址,就直接回车,之后会生成一个文件:elastic-certificates.p12文件

三、将凭证迁移到指定目录

# 先创建目录
mkdir ./config/certificates
# 移动凭证至指定目录下
mv ./elastic-certificates.p12 ./config/certificates/
# 赋值权限,不然会出问题
chmod 777 ./config/certificates/elastic-certificates.p12
不做这个操作  启动会报异常  没有权限读取
chown -R 【ES用户】 [安装目录]/config/certificates/elastic-stack-ca.p12
chown -R 【ES用户】 [安装目录]/config/elasticsearch.keystore
  

四、凭证移动至每一台集群下面 切记最后操作master 节点

此处省略各种scp,就是把elastic-certificates.p12这个文件移动到每一个es安装目录的相同路径下

五、修改配置文件(每一台es都需要添加)

vim ./config/elasticsearch.yml
# 输入如下的配置

# 跨域
http.cors.enabled: true
http.cors.allow-origin: "*"
http.cors.allow-headers: Authorization,X-Requested-With,Content-Type,Content-Length

xpack.security.enabled: true
xpack.security.authc.accept_default_password: true
xpack.security.transport.ssl.enabled: true
xpack.security.transport.ssl.verification_mode: certificate
xpack.security.transport.ssl.keystore.path: 【es的安装路径】/config/certificates/elastic-certificates.p12
xpack.security.transport.ssl.truststore.path: 【es的安装路径】/config/certificates/elastic-certificates.p12

六、在各个节点上添加密码(每一台es都需要操作)

./bin/elasticsearch-keystore add xpack.security.transport.ssl.keystore.secure_password

输入密码:第一步中设置的密码,例如本样例中的123456

./bin/elasticsearch-keystore add xpack.security.transport.ssl.truststore.secure_password

七、逐个启动节点 然后启动

kill -9  pid 
./bin/elasticsearch -d

八、设置密码 此处要重复输入刚刚设置的密码,有一个错误 ,则失败,要重新操作输入

./bin/elasticsearch-setup-passwords  interactive

九、浏览器查看9200端口

因为我是一台机器上装的集群,所以使用9200端口

访问地址为:http://【ip】:9200
在这里插入图片描述

十、es-head访问认证的es

但是此方法显然不支持带认证的es
所以此处需要带上账户名和密码:
http://192.168.31.160:9201/?auth_user=elastic&auth_password=123456

此文章 转载该用户的基础上,增加了自己所犯的问题记录,如有问题欢迎指正
原文链接:https://blog.csdn.net/hhf799954772/article/details/115870012

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值