温馨提示×

CentOS环境下Filebeat安装步骤

小樊
33
2025-11-27 19:58:05
栏目: 智能运维

在 CentOS 上安装与配置 Filebeat

一 安装前准备

  • 更新系统并安装常用工具:
    • 命令:sudo yum update -y && sudo yum install -y yum-utils
  • 确认系统版本与架构,选择合适的 Filebeat 版本(如 7.x8.x)。如使用 RPM 包,后续将由 systemd 托管服务;如使用 tar.gz 解压,需手动创建 systemd 服务单元。

二 安装方式

  • 方式一 官方 YUM 仓库安装(推荐)
    • 导入 GPG 并添加仓库(以 7.x 为例,如需 8.x 将 7.x 替换为 8.x):
      • 命令:
        • sudo rpm --import https://artifacts.elastic.co/GPG-KEY-elasticsearch
        • sudo tee /etc/yum.repos.d/elastic-beats.repo <<EOF [elastic-7.x] 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 EOF
    • 安装并启动服务:
      • 命令:sudo yum install -y filebeat && sudo systemctl enable --now filebeat
  • 方式二 手动下载并解压 tar.gz
    • 下载与解压(将 7.x.x 替换为实际版本):
      • 命令:
        • wget https://artifacts.elastic.co/downloads/beats/filebeat/filebeat-7.x.x-linux-x86_64.tar.gz
        • sudo tar -xzf filebeat-7.x.x-linux-x86_64.tar.gz -C /opt/
    • 启动(前台调试):
      • 命令:/opt/filebeat/filebeat -e -c /opt/filebeat/filebeat.yml

三 配置要点

  • 主配置文件路径
    • RPM 安装:/etc/filebeat/filebeat.yml
    • tar.gz 安装:/opt/filebeat/filebeat.yml
  • 最小可用配置示例(采集系统日志并输出到本机 Elasticsearch)
    • 配置片段:
      • filebeat.inputs:
        • - type: log
          • enabled: true
          • paths: ["/var/log/*.log"]
      • output.elasticsearch:
        • hosts: ["localhost:9200"]
  • 常用模块与索引命名
    • 启用模块目录:filebeat.modules.path: ${path.config}/modules.d/*.yml
    • 索引命名:setup.template.name: "filebeat"setup.template.pattern: "filebeat-*";索引可按版本与日期命名:filebeat-%{[agent.version]}-%{+yyyy.MM.dd}

四 启动与验证

  • 使用 systemd 管理的服务
    • 命令:sudo systemctl daemon-reload && sudo systemctl enable --now filebeat
    • 状态检查:sudo systemctl status filebeat
  • 查看运行日志
    • 命令:sudo journalctl -u filebeat -f
  • 验证数据是否到达 Elasticsearch
    • 命令:curl -X GET "localhost:9200/_cat/indices?v&pretty",应能看到以 filebeat- 开头的索引。

五 安全与网络配置

  • 启用安全认证(Elasticsearch 已开启 X-Pack Security 时)
    • 配置示例:
      • output.elasticsearch:
        • hosts: ["https://your_es_host:9200"]
        • username: "your_username"
        • password: "your_password"
    • 重启生效:sudo systemctl restart filebeat
  • 防火墙与 SELinux
    • 开放端口(示例为 92005601):
      • 命令:sudo firewall-cmd --permanent --add-port={9200,5601}/tcp && sudo firewall-cmd --reload
    • 如遇 SELinux 限制,按需调整策略或以调试模式验证。

0