在 CentOS 上部署 Filebeat 的标准步骤
一 准备与安装
sudo yum update -y && sudo yum install -y yum-utilssudo rpm --import https://artifacts.elastic.co/GPG-KEY-elasticsearchsudo tee /etc/yum.repos.d/filebeat.repo <<EOF [filebeat] name=Elasticsearch repository for 7.x packages baseurl=https://artifacts.elastic.co/packages/7.x/yum gpgcheck=1 gpgkey=https://artifacts.elastic.co/GPG-KEY-elasticsearch enabled=1 autorefresh=1 type=rpm-md EOFsudo yum install -y filebeat && sudo systemctl daemon-reload && sudo systemctl enable --now filebeatwget https://artifacts.elastic.co/downloads/beats/filebeat/filebeat-7.16.3-x86_64.rpm && sudo rpm -vi filebeat-7.16.3-x86_64.rpmsudo systemctl status filebeat(应显示 active/running)二 配置 Filebeat
sudo vi /etc/filebeat/filebeat.ymlfilebeat.inputs:
- type: log
enabled: true
paths:
- /var/log/*.log
output.elasticsearch:
hosts: ["localhost:9200"]
sudo filebeat modules enable nginx/etc/filebeat/modules.d/(按需调整其中的 nginx.yml)filebeat test config、filebeat test output三 常用输出目标配置
output.elasticsearch:
hosts: ["elasticsearch:9200"]
output.elasticsearch:
hosts: ["https://your_es_host:9200"]
username: "your_username"
password: "your_password"
ssl.enabled: true
ssl.certificate: "/etc/pki/tls/certs/filebeat.crt"
ssl.key: "/etc/pki/tls/private/filebeat.key"
output.kafka:
enabled: true
hosts: ["192.168.122.200:9092"]
topic: "%{[log_topic]}"
partition.round_robin:
reachable_only: true
worker: 2
required_acks: 1
compression: gzip
max_message_bytes: 10000000
fields 与 fields_under_root 为日志添加业务标识,然后在 topic 中使用 %{[log_topic]} 动态选择主题四 启动与验证
sudo systemctl start filebeatsudo systemctl enable filebeatsudo systemctl status filebeatsudo tail -f /var/log/filebeat/filebeatcurl -X GET "localhost:9200/_cat/indices?v"(若对接 ES)curl -X GET "localhost:9200/_cluster/health?pretty"(可选)五 安全与运维建议
sudo firewall-cmd --permanent --add-port=5044/tcp && sudo firewall-cmd --reloadsudo setenforce 0;生产环境建议按需配置 SELinux 布尔值或策略,而非直接关闭。