温馨提示×

Filebeat在Debian上怎么用

小樊
38
2026-07-09 21:51:51
栏目: 智能运维

在 Debian 上用 Filebeat 一般流程是:安装 → 配置 → 启动 → 验证。下面给你一个从零到可用的完整示例,假设你是要把日志发送到 ElasticsearchLogstash


一、安装 Filebeat(Debian / Ubuntu)

方式一:官方 APT 仓库(推荐 ✅)

# 1. 安装依赖
sudo apt update
sudo apt install curl gpg -y

# 2. 导入 Elastic GPG 密钥
curl -fsSL https://artifacts.elastic.co/GPG-KEY-elasticsearch | \
  sudo gpg --dearmor -o /usr/share/keyrings/elastic-keyring.gpg

# 3. 添加 Elastic APT 源
echo "deb [signed-by=/usr/share/keyrings/elastic-keyring.gpg] \
https://artifacts.elastic.co/packages/8.x/apt stable main" | \
  sudo tee /etc/apt/sources.list.d/elastic-8.x.list

# 4. 安装 Filebeat
sudo apt update
sudo apt install filebeat -y

如果你用的是 7.x,把 8.x 改成 7.x


二、Filebeat 基本配置

配置文件位置:

/etc/filebeat/filebeat.yml

示例:收集系统日志并发送到 Elasticsearch

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

output.elasticsearch:
  hosts: ["localhost:9200"]

logging.level: info

三、常见输出方式

1️⃣ 输出到 Elasticsearch(最常见)

output.elasticsearch:
  hosts: ["http://localhost:9200"]

如果 ES 有账号密码:

output.elasticsearch:
  hosts: ["https://es.example.com:9200"]
  username: "elastic"
  password: "your_password"

2️⃣ 输出到 Logstash

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

Logstash 示例配置:

input {
  beats {
    port => 5044
  }
}

output {
  elasticsearch {
    hosts => ["localhost:9200"]
  }
}

四、启动并启用 Filebeat

sudo systemctl enable filebeat
sudo systemctl start filebeat

查看状态:

sudo systemctl status filebeat

五、验证是否正常工作

1️⃣ 查看 Filebeat 日志

sudo journalctl -u filebeat -f

或:

/var/log/filebeat/filebeat

2️⃣ 查看 Elasticsearch 是否收到数据

curl -X GET "localhost:9200/_cat/indices?v"

六、常用模块(推荐 ✅)

Filebeat 自带很多模块(nginx、system、mysql 等)

启用 system 模块

sudo filebeat modules enable system

查看已启用模块

sudo filebeat modules list

设置模块配置

sudo filebeat setup

setup 会创建索引模板、仪表盘(Kibana)


七、Debian 常见问题

1️⃣ 权限问题(无法读日志)

sudo usermod -aG adm filebeat
sudo usermod -aG systemd-journal filebeat

2️⃣ 时间不生效 / 日志没变化

sudo filebeat test config
sudo filebeat test output

八、最小可用示例(总结)

sudo apt install filebeat
sudo vi /etc/filebeat/filebeat.yml
sudo systemctl restart filebeat

如果你愿意,可以告诉我:

  • ✅ 日志类型(nginx / docker / 自定义)
  • ✅ 输出目标(ES / Logstash / Kafka)
  • ✅ Debian 版本(11 / 12)

我可以给你一份 完全贴合你环境的 Filebeat 配置

0