ELK —— xpack 安全验证

ELK xpack 安全验证


参考教程


简介

  • 使用基本许可证时,默认情况下禁用 Elasticsearch 安全功能。启用 Elasticsearch 安全功能可启用基本身份验证,以便您可以使用用户名和密码身份验证运行本地集群。

  • 对于生产模式集群,最低安全方案是不够的 。如果您的集群有多个节点,您必须启用最低安全性,然后 在节点之间配置传输层安全性 (TLS)。

  • 配置传输层安全性 (TLS)。传输层处理集群中节点之间的所有内部通信。

  • 传输层依赖于双向 TLS 来加密和验证节点。正确应用 TLS 可确保恶意节点无法加入集群并与其他节点交换数据。虽然在 HTTP 层实现用户名和密码认证对于保护本地集群很有用,但节点之间的通信安全需要 TLS。

【注意】踩过的坑

1、
ES 安全 配置顺序,先启动 xpack 安全验证 与 TLS (传输层安全性),然后配置 TLS,使集群之间可以通信,接着再为内置用户配置密码(生产模式下的配置顺序)。

[注]: 如果您的集群有多个节点,那么您必须在节点之间配置 TLS。如果您不启用 TLS,生产模式(它可以通过非环回地址加入集群,则认为它处于生产模式。)集群将不会启动。
所以集群是生产模式的情况,需要添加以下两个参数,集群才可以启动。
xpack.security.enabled: true
xpack.security.transport.ssl.enabled: true

2、
注意,kibana web界面登录时使用的 elastic 用户,而不是 kibana-system 用户名。权限问题,kibana-system 默认无权访问。

3、
重置用户密码时,由于启动了 xpack 安全验证,head 访问需要用户名和密码,将 http.cors.allow-headers: Authorization,X-Requested-With , Content-Length,Content-Type 加入ES 配置,url 中使用用户名和密码登录访问( http://172.25.9.2:9100/?auth_user=user&auth_password=password )。

4、
忘记用户密码需要重置,禁用 xpack 安全验证,head 删除存放密码索引(不是必须用 head ,只是个人认为这个来的快),ES集群重新设置密码 有提到。删除后,重新启用 xpack 安全验证,再重新设置密码即可。


实验

主机应用 版本
server1 (172.25.9.1)Elasticsearch (7.13.2)、Logstash (7.13.2)、Kibana (7.13.2)
server2 (172.25.9.2)Elasticsearch (7.13.2)、head (v5.0.0)
server3 (172.25.9.3)Elasticsearch (7.13.2)
# server1 :
# 配置传输层安全性 (TLS)。传输层处理集群中节点之间的所有内部通信。
## 使用该elasticsearch-certutil工具为您的集群生成 CA
cd /usr/share/elasticsearch
./bin/elasticsearch-certutil ca
## 为您的节点生成证书和私钥。--ca <ca_file>  用于签署证书的 CA 文件的名称
./bin/elasticsearch-certutil cert --ca elastic-stack-ca.p12

# 拷贝证书到集群中的其它节点,文件拥有者改为 elasticsearch
cp elastic-certificates.p12 /etc/elasticsearch/
chown elasticsearch /etc/elasticsearch/elastic-certificates.p12 
scp /etc/elasticsearch/elastic-certificates.p12 server2:/etc/elasticsearch/
scp /etc/elasticsearch/elastic-certificates.p12 server3:/etc/elasticsearch/

# ES 配置
vim /etc/elasticsearch/elasticsearch.yml
……
xpack.security.enabled: true
xpack.security.transport.ssl.enabled: true
xpack.security.transport.ssl.verification_mode: certificate
xpack.security.transport.ssl.client_authentication: required
xpack.security.transport.ssl.keystore.path: /etc/elasticsearch/elastic-certificates.p12
xpack.security.transport.ssl.truststore.path: /etc/elasticsearch/elastic-certificates.p12
……
# head 访问
http.cors.allow-headers: Authorization,X-Requested-With,Content-Length,Content-Type

# server2、server3:
# 文件拥有者改为 elasticsearch
chown elasticsearch /etc/elasticsearch/elastic-certificates.p12 
# ES 配置
vim /etc/elasticsearch/elasticsearch.yml
……
xpack.security.enabled: true
xpack.security.transport.ssl.enabled: true
xpack.security.transport.ssl.verification_mode: certificate
xpack.security.transport.ssl.client_authentication: required
xpack.security.transport.ssl.keystore.path: /etc/elasticsearch/elastic-certificates.p12
xpack.security.transport.ssl.truststore.path: /etc/elasticsearch/elastic-certificates.p12

# server1、server2、server3:
# 重启 ES 服务
systemctl restart elasticsearch.service

# head 访问:
http://172.25.9.2:9100/?auth_user=elastic&auth_password=westos

# server1:
# 内置用户生成密码,自定义。(ES 自己随机定义 将 interactive ->  auto)
./bin/elasticsearch-setup-passwords interactive
# kibana 配置
vim /etc/kibana/kibana.yml
……
elasticsearch.username: "kibana_system"
elasticsearch.password: "westos"
……

# 重启
systemctl restart kibana.service

#  logstash 访问 ES:

vim /etc/logstash/conf.d/apache.conf
input {
	file {
		path => "/var/log/httpd/access_log"
		start_position => "beginning"
	}
}
filter {
	grok {
		match => { "message" => "%{HTTPD_COMBINEDLOG}" }
	}
}
output {
	stdout {}
	elasticsearch {
		hosts => ["172.25.9.1:9200"]
		index => "apachelog-%{+yyyy.MM.dd}"
		user => "elastic"
		password => "westos"
	}
}

# logstash 采集 httpd 访问成功日志。成功则 logstash 访问 ES 成功。
/usr/share/logstash/bin/logstash -f /etc/logstash/conf.d/apache.conf 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值