CentOS7安装Filebeat
一、介绍及规划
Filebeat 是 ELK 的一个组件,用于收集应用服务器的日志。Filebeat 的版本绝对不能高于 Elasticsearch 的版本
| 主机名 |
ip地址 |
系统版本 |
软件版本 |
| es101 |
192.168.10.101 |
centos7 |
8.19.9 |
| es102 |
192.168.10.102 |
centos7 |
8.19.9 |
| es103 |
192.168.10.103 |
centos7 |
8.19.9 |
二、安装
有多种方式安装,RPM包安装、二进制文件解压安装。这里以 8.19.9 版本为例。
下载地址
2.1 RPM包安装
- 下载
1
| wget https://artifacts.elastic.co/downloads/beats/filebeat/filebeat-8.19.9-x86_64.rpm
|
- 安装
1
| rpm -ivh filebeat-8.19.9-x86_64.rpm
|
- 验证
2.2 二进制包安装
- 下载
1
| wget https://artifacts.elastic.co/downloads/beats/filebeat/filebeat-8.19.9-linux-x86_64.tar.gz
|
- 解压
1
| tar xf filebeat-8.19.9-linux-x86_64.tar.gz -C /usr/local
|
- 创建软链接
1
| ln -s /usr/local/filebeat-8.19.9-linux-x86_64 /usr/local/filebeat
|
- 设置环境变量
1
| echo 'export PATH=/opt/elasticsearch:$PATH' > /etc/profile.d/filebeat.sh
|
- 刷新环境变量
- 验证版本
- 使用
systemd 管理
1
| vi /usr/lib/systemd/system/filebeat.service
|
1 2 3 4 5 6 7 8 9 10 11 12 13
| [Unit] Description=Filebeat log shipper Documentation=https://www.elastic.co/guide/en/beats/filebeat/current/index.html Wants=network-online.target After=network-online.target
[Service]
ExecStart=/opt/filebeat/filebeat -c /opt/filebeat/filebeat.yml -path.home /opt/filebeat -path.config /opt/filebeat -path.data /opt/filebeat/data -path.logs /opt/filebeat/logs Restart=always
[Install] WantedBy=multi-user.target
|
- 自启动
1 2 3 4
| systemctl daemon-reload systemctl enable filebeat systemctl start filebeat systemctl status filebeat
|
三、配置使用
- 默认配置
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
| [root@lnmp ~]# egrep -v '^$|#' /etc/filebeat/filebeat.yml filebeat.inputs: - type: filestream id: my-filestream-id enabled: false paths: - /var/log/*.log filebeat.config.modules: path: ${path.config}/modules.d/*.yml reload.enabled: false setup.template.settings: index.number_of_shards: 1 setup.kibana: output.elasticsearch: hosts: ["localhost:9200"] preset: balanced processors: - add_host_metadata: when.not.contains.tags: forwarded - add_cloud_metadata: ~ - add_docker_metadata: ~ - add_kubernetes_metadata: ~ [root@lnmp ~]#
|
- 对接 ES 集群配置,
output.elasticsearch 模块
1
| vim /etc/filebeat/filebeat.yml
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14
| output.elasticsearch: hosts: ["192.168.10.101:9200", "192.168.10.102:9200", "192.168.10.103:9200"] username: "elastic" password: "elastic"
|
- 启用
Nginx 模块
1
| filebeat modules enable nginx
|
1
| vim /etc/filebeat/modules.d/nginx.yml
|
1 2 3 4 5 6 7 8
| - module: nginx access: enabled: true var.paths: ["/var/log/nginx/access.log*"] error: enabled: true var.paths: ["/var/log/nginx/error.log*"]
|
- 加载资产
- 测试配置文件
1
| filebeat test config -c /etc/filebeat/filebeat.yml
|
- 启动服务
1 2
| systemctl start filebeat systemctl enable filebeat
|
- 检查日志确认 Filebeat 是否成功连接到 ESs 集群
1
| tail -f /var/log/filebeat/filebeat
|
- 图形化工具查看是否出现新的索引