1. filebeat安装
#rpm安装方式
https://artifacts.elastic.co/downloads/beats/filebeat/filebeat-7.17.5-x86_64.rpm
rpm -ivh filebeat-7.17.5-x86_64.rpm
systemctl enable filebeat --now
#二进制包安装方式
1.下载
mkdir -p /data/tools/filebeat/ && cd /data/tools/filebeat/
wget https://artifacts.elastic.co/downloads/beats/filebeat/filebeat-7.17.5-linux-x86_64.tar.gz
tar -xvf filebeat-7.17.5-linux-x86_64.tar.gz
--------------这里第二部和第三步先不操作,案例部分和2,3冲突--------------------------------
2.使用systemctl管理filebeat服务
cat > /usr/lib/systemd/system/filebeat.service <<EOF
[Unit]
Description=es
After=network.target
[Service]
Type=simple
ExecStart=/data/tools/filebeat/filebeat-7.17.5-linux-x86_64/filebeat -c /data/tools/filebeat/filebeat-7.17.5-linux-x86_64/filebeat.yml
User=filebeat
LimitNOFILE=131070
[Install]
WantedBy=multi-user.target
EOF
3.重新加载systemctl,启动filebeat
systemctl daemon-reload
systemctl enable filebeat --now
2. filbeat案例
2.1. input插件之stdin:案例
https://www.elastic.co/guide/en/beats/filebeat/7.17/index.html
-------------------------------------------------------------------------------
1. filbeat的input插件之stdin案例
(1)创建工作目录
cd /data/tools/filebeat/filebeat-7.17.5-linux-x86_64
mkdir config
(2)编写配置文件
[root@elk1]# cat >> config/01-stdin-to-console.yaml <<EOF
# 配置filebeat的输入端
filebeat.inputs:
# 指定输入端的类型为标准输入
- type: stdin
# 指定filebeat的输出端为console
output.console:
# 表示输出的内容以漂亮的格式显示
pretty: true
EOF
(3)启动filebeat的实例
filebeat -e -c config/01-stdin-to-console.yaml
(4) 测试输入输出
输入: 232323231
输出:
{
........
"message": "232323231",
.....
}
2.2. input插件之tcp:案例
]# cat >> config/02-tcp-to-console.yaml <<EOF
# 配置filebeat的输入端
filebeat.inputs:
# 指定输入端的类型为tcp
- type: tcp
# 定义tcp监听的主机和端口
host: 0.0.0.0:8888
# 指定filebeat的输出端为console
output.console:
# 表示输出的内容以漂亮的格式显示
pretty: true
EOF
(3)启动filebeat的实例
./filebeat -e -c config/02-tcp-to-console.yaml
(4) 测试输入输出
输入: echo "1111"|nc 10.0.0.101 8888
输出:
{
......
"message": "1111",
.....
}
2.3. input的通用字段案例:
input的通用字段案例:
filebeat input插件的通用字段(common options):
- enabled:
是否启用该组件,有true和false,默认值为true。当设置为false时,表示该input组件不会被加载执行!
- tags:
给每条数据添加一个tags标签列表。
- fields
给数据添加字段。
- fields_under_root
该值默认值为false,将自定义的字段放在一个"fields"的字段中。若设置为true,则将fields的KEY放在顶级字段中。
- processors:
定义处理器,对源数据进行简单的处理。
参考链接:
https://www.elastic.co/guide/en/beats/filebeat/7.17/defining-processors.html
2.4. 综合案例:
5 综合案例:
[root@elk]# cat >> config/03-input_common_options-to-console.yaml <<EOF
filebeat.inputs:
- type: log
paths:
- /tmp/logtest/*.log
- /tmp/logtest/*/*.json
- /tmp/logtest/**/*.exe
# 是否启用该类型,默认值为true。
enabled: false
- type: tcp
enabled: true
host: "0.0.0.0:8888"
# 给数据打标签,会在顶级字段多出来多个标签
tags: ["2024","new","happy"]
# 给数据添加KEY-VALUE类型的字段,默认是放在"fields"中的
fields:
school: qinghua
class: "5-4"
classroom: "032"
ip: 219.141.136.10
port: 13306
# 若设置为true时,则将fields添加的自定义字段放在顶级字段中,默认值为false。
fields_under_root: true
# 定义处理器,过滤指定的数据
processors:
# 删除消息是以linux开头的事件(event)
- drop_event:
when:
regexp:
message: "^linux"
# 消息包含error内容事件(event)就可以删除自定义字段或者tags。无法删除内置的字段.
- drop_fields:
when:
contains:
message: "error"
fields: ["class","tags"]
ignore_missing: false
# 修改字段的名称
- rename:
fields:
# 源字段
- from: "school"
# 目标字段
to: "学校"
- from: "log"