温馨提示×

centos怎样配置filebeat

小樊
70
2026-09-02 21:35:18
栏目: 智能运维

下面以 CentOS 7 / 8 为例,说明如何安装和配置 Filebeat(Elastic 官方日志采集器)。


一、安装 Filebeat

方式一:使用 RPM 包(推荐)

# 导入 Elastic GPG key
sudo rpm --import https://artifacts.elastic.co/GPG-KEY-elasticsearch

# 添加 yum 源(以 8.x 为例)
sudo cat > /etc/yum.repos.d/filebeat.repo <<EOF
[filebeat]
name=Elasticsearch repository for 8.x packages
baseurl=https://artifacts.elastic.co/packages/8.x/yum
gpgcheck=1
gpgkey=https://artifacts.elastic.co/GPG-KEY-elasticsearch
enabled=1
autorefresh=1
type=rpm-md
EOF

# 安装
sudo yum install filebeat -y

如果是 CentOS 8,用 dnf install filebeat -y


二、配置 Filebeat

配置文件路径:

/etc/filebeat/filebeat.yml

1️⃣ 配置日志输入(inputs)

示例:采集 /var/log/*.log

filebeat.inputs:
  - type: filestream
    enabled: true
    paths:
      - /var/log/*.log

老版本用 log 类型,8.x 推荐 filestream


2️⃣ 配置输出(Output)

✅ 输出到 Elasticsearch

output.elasticsearch:
  hosts: ["http://localhost:9200"]
  username: "elastic"
  password: "your_password"

✅ 输出到 Logstash

output.logstash:
  hosts: ["localhost:5044"]

3️⃣(可选)加载默认仪表板

filebeat setup

三、启动并设置开机启动

sudo systemctl enable filebeat
sudo systemctl start filebeat

查看状态:

systemctl status filebeat

四、查看日志排查问题

journalctl -u filebeat -f

或:

tail -f /var/log/filebeat/filebeat

五、常见示例

采集 Nginx 日志

filebeat.inputs:
  - type: filestream
    enabled: true
    paths:
      - /var/log/nginx/access.log
      - /var/log/nginx/error.log

多行日志(如 Java 异常)

multiline.pattern: '^[0-9]{4}-[0-9]{2}-[0-9]{2}'
multiline.negate: true
multiline.match: after

六、防火墙注意

如果输出到远程 ES / Logstash:

firewall-cmd --add-port=9200/tcp --permanent
firewall-cmd --add-port=5044/tcp --permanent
firewall-cmd --reload

如果你告诉我:

  • CentOS 版本
  • Filebeat 版本(7.x / 8.x)
  • 输出目标(ES / Logstash / Kafka)

我可以给你一份 可直接用的完整配置。

0 踩