filebeat 使用
1. 配置文件 filebeat-prod.yml
#监控的日志文件 paths: - /usr/local/project/logs/*.log output.kafka: enabled: true hosts: ["10.10.183.152:9092","10.10.183.153:9092","10.10.183.154:9092"]#Kafka集群机器地址 topic: monitorLog
multiline.pattern: ^\d{4}-\d{2}-\d{2}
#multiline.negate: false 是否需要对pattern条件转置使用,不翻转设为true,反转设置为false。 【建议设置为true】
multiline.negate: true
#multiline.match: after 合并方式:匹配pattern后,与前面(before)还是后面(after)的内容合并为一条日志
multiline.match: after
processors:
#- add_host_metadata: ~
#- add_cloud_metadata: ~
- drop_fields:
fields: ["ecs","agent","input"]
2. 复制启动脚本:filebeat.sh
#!/bin/bash echo "copy filebeat soft" #将软件复制到其他服务器 ansible XX -m copy -a "src=/usr/local/soft/filebeat-7.1.0-linux-x86_64.tar.gz dest=/usr/local/soft" #解压文件 ansible XX -m shell -a "tar -xzvf /usr/local/soft/filebeat-7.1.0-linux-x86_64.tar.gz -C /usr/local/soft " #配置文件复制 ansible XX -m copy -a "src=/usr/local/soft/filebeat-controller/filebeat-prod.yml dest=/usr/local/soft/filebeat-7.1.0-linux-x86_64" #启动命令 #/usr/local/soft/filebeat-7.1.0-linux-x86_64/filebeat -e -c /usr/local/soft/filebeat-7.1.0-linux-x86_64/filebeat.yml >> /usr/local/soft/filebeat-7.1.0-linux-x86_64/log.log 2>&1 & echo "copy filebeat end"