在CentOS上配置Filebeat時,可以通過修改filebeat.yml文件來自定義其配置項。以下是一些常見的自定義配置項及其示例:
指定輸入日志的目錄路徑:
filebeat.inputs:
- type: log
paths:
- /usr/local/nginx/logs/access.log
- /usr/local/nginx/logs/error.log
配置輸出到Kafka:
output.kafka:
enabled: true
hosts: ["127.0.0.1:9092"]
topic: 'maplegam_nginx'
啟用并配置nginx模塊:
filebeat.modules:
- enabled: nginx
調整nginx日志格式: 編輯nginx配置文件,增加主機名變量:
log_format main '$remote_addr - $remote_user [$time_local] "$request" ''$status $body_bytes_sent "$http_referer" "$host"''"$http_user_agent" "$http_x_forwarded_for"';
測試配置文件: 使用以下命令測試配置文件是否有效:
filebeat test config -e
運行Filebeat: 使用以下命令運行Filebeat:
nohup ./filebeat -e -c ./filebeat.yml >/dev/null 2>&1 &