背景
如果服务器位于世界各地,但又需要通过filebeat传输日志到logstash分析,这时候为了保证数据的安全,在传输的时候使用加密是基本的要求。
一、创建自签名证书
创建certs证书目录
# mkdir /etc/logstash/certs
# cd /etc/logstash/certs
生成ca密钥
# openssl genrsa 2048 > ca.key
使用ca私钥建立ca证书
# openssl req -new -x509 -nodes -days 3650 -key ca.key -out ca.crt
生成服务器csr证书请求文件
# openssl req -newkey rsa:2048 -days 3650 -nodes -keyout server.key -out server.csr
使用ca证书与私钥签发服务器证书
# openssl x509 -req -in server.csr -days 3650 -CA ca.crt -CAkey ca.key -set_serial 01 > server.crt
目录下面的文件列表如下:
二、logstash 配置
打开文件
[root@elk ~]# vim /etc/logstash/conf.d/filebeat.conf
input {
beats {
port => 5044
ssl => true
ssl_certificate_authorities => [“/etc/logstash/certs/ca.crt”]
ssl_certificate => “/etc/logstash/certs/server.crt”
ssl_key => “/etc/logstash/certs/server.key”
ssl_verify_mode => “force_peer”
}
}
重启logstash 生效
systemctl restart logstash
三、filebeat 配置
将certs文件夹到/etc/filebeat下面
打开文件
[root@elk ~]# vim /etc/filebeat/filebeat.yml
修改 Logstash output 区段
—————————– Logstash output ——————————–
output.logstash:
# The Logstash hosts
hosts: [“domain:5044”]
# Optional SSL. By default is off.
# List of root certificates for HTTPS server verifications
ssl.certificate_authorities: [“/etc/filebeat/certs/ca.crt”]
# Certificate for SSL client authentication
ssl.certificate: “/etc/filebeat/certs/server.crt”
# Client Certificate Key
ssl.key: “/etc/filebeat/certs/server.key”
保存后重启filebeat:
systemctl restart filebeat