filebeat 安装
/etc/filebeat/filebeat.yml
默认是这个文件, 如果想用 systemctl 来管理, 就需要用这个配置文件。
1-下载:
wget https://artifacts.elastic.co/downloads/beats/filebeat/filebeat-7.17.5-x86_64.rpm
2-安装
rpm -ivh filebeat-7.17.5-x86_64.rpm
3-.修改filebeat的配置文件
(1)编写测试的配置文件
mkdir /etc/filebeat/config
输入
cat > /etc/filebeat/config/01-stdin-to-console.yml <<'EOF'
# 指定输入的类型
filebeat.inputs:
# 指定输入的类型为"stdin",表示标准输入
- type: stdin
# 指定输出的类型
output.console:
# 打印漂亮的格式
pretty: true
EOF
启动
filebeat -e -c /etc/filebeat/config/01-stdin-to-console.yml
测试, 屏幕输入 baimeidashu
不指定配置文件,默认是用的/ etc /filebeat.yml
开机自启:
systemctl start filebeat.service
systemctl enable filebeat.service
4-log文件 监控写入 input的log类型
filebeatsdemo.yml
filebeat.inputs:
- type: log
paths:
- /tmp/1.log
output.console:
pretty: true
~
启动:
filebeat -e -c /root/config/filebeatsdemo.yml
我们 写入数据测试一下:
echo dasfasd > /tmp/1.log
# 指定input插件的配置
filebeat.inputs:
# 类型为log
- type: log
# 指定日志的路径
paths:
- /tmp/filebeat/*.log
# 指定output插件类型为console
output.console:
pretty: true
(4) demo
文件读取记录:
rm -rf /var/lib/filebeat/registry/*
7.将数据写入es案例
filebeat 写入es : 连接
8- 多个日志文件 案例:
cat filebeat.yml
filebeat.inputs:
- type: log
paths: ["/var/log/nginx/uat-cloudservice.baimeidashu.com.*"]
tags: "uat-cloudservice"
- type: log
paths: ["/var/log/nginx/uat-cloudservice2.baimeidashu.com.*"]
tags: "cloudservice2"
- type: log
paths: ["/var/log/nginx/uat-cloudsocket.baimeidashu.com.*"]
tags: "uat-cloudsocket"
- type: log
paths: ["/var/log/nginx/uat-cloudsocket2.baimeidashu.com.*"]
tags: "uat-cloudsocket2"
- type: log
paths: ["/var/log/nginx/uat-cloudservice3.baimeidashu.com.*"]
tags: "cloudservice3"
- type: log
paths: ["/var/log/nginx/uat-cloudservice3.baimeidashu.com.*"]
tags: "torna"
output.elasticsearch:
hosts:
- "http://192.168.1.250:9200"
username: "elastic"
password: "baimeidashu.123"
indices:
- index: "nginx-uat-cloudservice.baimeidashu.com-%{+yyyy.MM.dd}"
when.contains:
tags: "uat-cloudservice"
- index: "nginx-uat-cloudservice2.baimeidashu.com-%{+yyyy.MM.dd}"
when.contains:
tags: "cloudservice2"
- index: "nginx-uat-cloudsocket.baimeidashu.com-%{+yyyy.MM.dd}"
when.contains:
tags: "uat-cloudsocket"
- index: "nginx-uat-cloudsocket2.baimeidashu.com-%{+yyyy.MM.dd}"
when.contains:
tags: "uat-cloudsocket2"
- index: "nginx-uat-cloudservice3.baimeidashu.com-%{+yyyy.MM.dd}"
when.contains:
tags: "torna"
- index: "nginx-torna.baimeidashu.com-%{+yyyy.MM.dd}"
when.contains:
tags: "torna1"
setup.ilm.enabled: false
setup.template.name: "nginx"
setup.template.pattern: "nginx*"
setup.template.overwrite: true
欢迎来撩 : 汇总all