- 角色控制:允许用户自定义角色,并设定角色对于集群和索引的各种权限。这包括集群管理权限、集群监控权限、远程客户端连接权限
- 用户控制:可以创建具体用户,并赋予用户相应的某种角色或多种角色。通过用户和角色的设定,实现对用户权限的灵活配置,强化对索引数据的安全管理
1. 未加密前
[root@elk91 ~]# curl 10.0.0.91:9200/_cat/nodes?v
ip heap.percent ram.percent cpu load_1m load_5m load_15m node.role master name
10.0.0.92 78 66 0 0.01 0.02 0.03 cdfhilmrstw - elk92
10.0.0.93 44 47 1 0.02 0.02 0.01 cdfhilmrstw - elk93
10.0.0.91 54 68 1 0.22 0.17 0.12 cdfhilmrstw * elk91
[root@elk91 ~]#
2. 配置ES集群加密
2.1 生成证书文件
[root@elk91 ~]# /usr/share/elasticsearch/bin/elasticsearch-certutil cert --days 3650 -out /etc/elasticsearch/elastic-certificates.p12 -pass ""
2.2 同步证书文件到其他节点
[root@elk91 ~]# scp /etc/elasticsearch/elastic-certificates.p12 10.0.0.92:/etc/elasticsearch/
[root@elk91 ~]#
[root@elk91 ~]# scp /etc/elasticsearch/elastic-certificates.p12 10.0.0.93:/etc/elasticsearch/
2.3 修改ES集群的配置文件
[root@elk91 ~]# 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.keystore.path: elastic-certificates.p12
xpack.security.transport.ssl.truststore.path: elastic-certificates.p12
2.4 同步ES配置文件到其他节点,并修改权限
[root@elk91 ~]# scp /etc/elasticsearch/elasticsearch.yml 10.0.0.92:/etc/elasticsearch/
[root@elk91 ~]# scp /etc/elasticsearch/elasticsearch.yml 10.0.0.93:/etc/elasticsearch/
[root@elk91 ~]# chown elasticsearch:elasticsearch /etc/elasticsearch/elastic-certificates.p12
[root@elk92 ~]# chown elasticsearch:elasticsearch /etc/elasticsearch/elastic-certificates.p12
[root@elk93 ~]# chown elasticsearch:elasticsearch /etc/elasticsearch/elastic-certificates.p12
2.5 所有节点”滚动”重启ES集群
systemctl restart elasticsearch
2.6 测试访问发现 无法访问ES集群
{"error":{"root_cause":[{"type":"security_exception","reason":"missing authentication credentials for REST request [/_cat/nodes?v]","header":{"WWW-Authenticate":"Basic realm=\"security\" charset=\"UTF-8\""}}],"type":"security_exception","reason":"missing authentication credentials for REST request [/_cat/nodes?v]","header":{"WWW-Authenticate":"Basic realm=\"security\" charset=\"UTF-8\""}},"status":401}
2.7 生成随机密码 注意保存好!!!
/usr/share/elasticsearch/bin/elasticsearch-setup-passwords auto
下一步:Please confirm that you would like to continue [y/N]y
2.8 验证集群是否正常
curl -u elastic:password 10.0.0.91:9200/_cat/nodes?v
3. kibana连接加密集群 及kibana修改管理员密码
1 修改配置文件
[root@elk91 ~]# vim /etc/kibana/kibana.yml
...
elasticsearch.username: "kibana_system"
elasticsearch.password: "password"
2 重启kibana服务
[root@elk91 ~]# systemctl restart kibana
3 访问kibana的WebUI登录
以elastic用户登录
4 修改elastic的初始密码
依次点击: 当前用户(右上角),配置文件,输入旧密码和新密码即可。
为了方便起见,建议都设置为: 自己常用的密码(容易记)
5 验证密码是否生效
退出当前用户重新登录即可
4. filebeat写入数据到ES加密集群
1.编写配置文件
[root@elk91 ~]# cat /etc/filebeat/17-tco-es_tls.yml
filebeat.inputs:
- type: tcp
host: "0.0.0.0:9000"
output:
elasticsearch:
hosts:
- "http://10.0.0.91:9200"
- "http://10.0.0.92:9200"
- "http://10.0.0.93:9200"
index: "linux-tcp-%{+yyyy.MM.dd}"
username: elastic
password: "xxxxxx"
setup.ilm.enabled: false
setup.template.name: "linux-tcp"
setup.template.pattern: "linux-tcp*"
setup.template.overwrite: false
setup.template.settings:
index.number_of_shards: 5
index.number_of_replicas: 0
[root@elk91 ~]#
[root@elk91 ~]# filebeat -e -c /etc/filebeat/17-tco-es_tls.yml
2.发送测试数据
[root@elk93 ~]# echo www.81c8.cn. | nc 10.0.0.91 9000
3.kibana验证
5. logstash写入数据到ES加密集群
1.编写配置文件
[root@elk93 ~]# cat /etc/logstash/conf.d/12-tcp-es.conf
input {
tcp {
port => 8888
}
}
output {
elasticsearch{
hosts => [“10.0.0.91:9200″,”10.0.0.92:9200″,”10.0.0.93:9200”]
index => “wangerxiao-tcp-%{+yyyy.MM.dd}”
user => “elastic”
password => “xxxxxxxx”
}
}
[root@elk93 ~]#
[root@elk93 ~]# logstash -rf /etc/logstash/conf.d/12-tcp-es.conf
2.发送测试数据
[root@elk91 ~]# echo 66666666 | nc 10.0.0.93 8888
3.kibana验证