elk搭建参见上篇文章:docker-composer 搭建elk (单机版)
1, 修改elasticsearch.yml, 新增配置xpack.security.enabled: true;此时elasticsearch.yml内容为
cluster.name: "docker-cluster"
network.host: 0.0.0.0
xpack.security.enabled: true
2, 重启服务 docker restart elasticsearch
3, 重启服务后进入容器 docker exec -it elasticsearch bash
在容器中执行命令 bin/elasticsearch-certutil cert -out config/elastic-certificates.p12 -pass ""
./bin/elasticsearch-certutil cert -out config/elastic-certificates.p12 -pass ""
chmod 777 ./config/elastic-certificates.p12
4, 退出容器,再次修改配置文件elasticsearch.yml;将elasticsearch.yml修改为
elasticsearch.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.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
5, 重新进入容器 docker exec -it elasticsearch bash;然后执行命令自动生成用户&密码。
./bin/elasticsearch-setup-passwords auto
执行命令后,账号&密码信息会自动输出到终端,复制妥善保管!!!
也可以执行 ./bin/elasticsearch-setup-passwords interactive 命令来手动设置密码,个人不推荐。看个人喜好了,各有千秋~
6, 在 Kibana 中配置基于角色的访问控制 (RBAC)
修改配置 kibana.yml
kibana.yml
# Default Kibana configuration for docker target
server.host: '0.0.0.0'
server.shutdownTimeout: '5s'
elasticsearch.hosts: ['http://elasticsearch:9200']
monitoring.ui.container.elasticsearch.enabled: true
xpack.encryptedSavedObjects.encryptionKey: ef2bfdcceb27722656fee2e71eb5e5db
xpack.reporting.encryptionKey: 404abca505da2b346a4d8d77c9854096
xpack.security.encryptionKey: 7403865d389c333564d4f0dac5e69383
elasticsearch.username: "kibana"
elasticsearch.password: "you password" #修改为前面生成的密码或者你设置的密码
7, 修改logstash配置
logstash.yml
http.host: "0.0.0.0"
xpack.monitoring.elasticsearch.hosts: [ "http://elasticsearch:9200" ]
xpack.monitoring.enabled: true
xpack.monitoring.elasticsearch.username: "logstash_system"
xpack.monitoring.elasticsearch.password: "you password" #修改为前面生成的密码或者你设置的密码
注意!!此时logstash依然无法上报日志的,还需要修改对应的conf配置文件,但是要先在kibana后台添加对应账号权限!!!
注意!!此时logstash依然无法上报日志的,还需要修改对应的conf配置文件,但是要先在kibana后台添加对应账号权限!!!
注意!!此时logstash依然无法上报日志的,还需要修改对应的conf配置文件,但是要先在kibana后台添加对应账号权限!!!
用前面生成的elastic账号登录IP:5601后台。
7.1 创建logstash-write角色
1名称logstash-write可以自定义, 左下角索引位置piao-1* ,piao-2*要和后面的配置文件里面的索引一致。
点击左下角 创建角色即可。
7.2 创建用户
7.3 修改piao-one.conf和piao-two.conf配置
在output里面加入上面添加的账户&密码
...上面内容忽略
output {
if [type] == "piao_1" {
elasticsearch {
hosts => ["elasticsearch:9200"]
index => "piao-1-%{+YYYY.MM.dd}"
user => "logstash_admin_1"
password => "you password" #你上面设置的密码
}
}
以上所有内容修改完成之后,重启服务;
docker-compose -f docker-compose.yml restart
网友评论