CentOS上Filebeat安全设置指南
避免以root用户身份运行Filebeat,降低系统权限滥用风险。操作步骤如下:
filebeatuser):useradd -r -s /sbin/nologin filebeatuser # -r表示系统用户,-s禁止登录shell
/etc/systemd/system/filebeat.service),指定运行用户:[Service]
User=filebeatuser
Group=filebeatuser
systemctl daemon-reload
systemctl restart filebeat
加密Filebeat与Elasticsearch、Logstash等目标服务的通信,防止数据泄露。操作步骤如下:
# 生成CA私钥和自签名证书(有效期10年)
openssl genrsa -out ca.key 2048
openssl req -x509 -new -nodes -key ca.key -sha256 -days 3650 -out ca.crt -subj "/CN=Elastic CA"
# 生成Filebeat客户端私钥和证书签名请求(CSR)
openssl genrsa -out filebeat.key 2048
openssl req -new -key filebeat.key -out filebeat.csr -subj "/CN=filebeat"
# 用CA签发Filebeat证书(有效期1年)
openssl x509 -req -in filebeat.csr -CA ca.crt -CAkey ca.key -CAcreateserial -out filebeat.crt -days 365 -sha256
# 生成Logstash/Elasticsearch服务端证书(可选,若需双向认证)
openssl genrsa -out logstash.key 2048
openssl req -new -key logstash.key -out logstash.csr -subj "/CN=logstash"
openssl x509 -req -in logstash.csr -CA ca.crt -CAkey ca.key -CAcreateserial -out logstash.crt -days 365 -sha256
/etc/filebeat/filebeat.yml,指定证书路径:output.elasticsearch:
hosts: ["elasticsearch.example.com:9200"]
ssl.certificate_authorities: ["/etc/filebeat/certs/ca.crt"]
ssl.certificate: "/etc/filebeat/certs/filebeat.crt"
ssl.key: "/etc/filebeat/certs/filebeat.key"
# 若服务端要求客户端证书(双向认证),取消以下注释
# ssl.client_authentication: "required"
确保Filebeat配置文件、日志目录及证书仅能被授权用户访问:
chown filebeatuser:filebeatuser /etc/filebeat/filebeat.yml
chmod 600 /etc/filebeat/filebeat.yml # 仅所有者可读写
mkdir -p /etc/filebeat/certs
chown -R filebeatuser:filebeatuser /etc/filebeat/certs
chmod -R 700 /etc/filebeat/certs # 仅所有者可读、写、执行
setfacl -m u:elkadmin:r-- /etc/filebeat/filebeat.yml # 允许elkadmin组只读
通过防火墙限制Filebeat的网络访问,仅允许特定IP或网段连接:
systemctl enable firewalld
systemctl start firewalld
firewall-cmd --permanent --add-service=filebeat
firewall-cmd --reload
firewall-cmd --permanent --add-rich-rule='rule family="ipv4" source address="192.168.1.0/24" port port="9200" protocol="tcp" accept'
firewall-cmd --reload
adm、lp),避免未授权提权:usermod -L adm # 锁定adm账户
usermod -L lp # 锁定lp账户
/etc/login.defs,设置复杂口令要求(至少8位,含大小写字母、数字、特殊字符):PASS_MIN_LEN 10
PASS_REQUIRE_MIX 1
PASS_WARN_AGE 7
chattr命令防止/etc/shadow被篡改:chattr +i /etc/shadow
/etc/profile,添加超时注销设置(如10分钟无操作注销):echo "export TMOUT=600" >> /etc/profile
source /etc/profile
/etc/pam.d/su,仅允许wheel组用户使用su切换root:auth required pam_wheel.so use_uid
将允许使用su的用户加入wheel组:usermod -aG wheel filebeatuser
yum update filebeat -y
systemctl status filebeat # 查看实时状态
journalctl -u filebeat -f # 实时查看日志
auditd监控/etc/filebeat目录的文件变更,及时发现未授权修改:auditctl -w /etc/filebeat -p wa -k filebeat_config
通过以上步骤,可全面增强CentOS上Filebeat的安全性,防范未授权访问、数据泄露及恶意攻击。需根据实际环境调整配置(如证书路径、IP白名单),并在测试环境验证后再应用于生产。