filebeat 一般處理日志類型的數據,只是beats 產品系列的一種,logstash 和他的區別就是logstash處理的數據類型跟為全面。
-
下載filebeat,解壓。部署到需要搜集日志數據機器上。
curl -L -O https://artifacts.elastic.co/downloads/beats/filebeat/filebeat-7.15.2-linux-x86_64.tar.gz tar xzvf filebeat-7.15.2-linux-x86_64.tar.gz # curl -O 參數表示用url的最后一部分當作文件名保存下載的文件,—L 參數是表示跟隨重定向
-
filebeat 使用
參考文檔:https://blog.csdn.net/zyxwvuuvwxyz/article/details/108831962
配置文件詳情:
filebeat.inputs: - type: log #log類型 enabled: true #默認為true, paths: - /var/log/system.log - /var/log/wifi.log - type: filestream paths: - "/var/log/apache2/*" fields: apache: true fields_under_root: true #控制台輸出 output.console: pretty: true #輸出到es中 output.elasticsearch: hosts: ["https://localhost:9200"] index: "filebeat-%{[beat.version]}-%{+yyyy.MM.dd}" ssl.certificate_authorities: ["/etc/pki/root/ca.pem"] ssl.certificate: "/etc/pki/client/cert.pem" ssl.key: "/etc/pki/client/cert.key" #輸出到logstash中 output.logstash: hosts: ["127.0.0.1:5044"]
filebeat 啟動modules
./filebeat modules list #列出模塊名 ./filebeat modules enable system nginx mysql #啟動system,nginx,mysql模塊
啟動配置文件
./filebeat -e -c filebeat配置文件
配置文件解釋
paths:待收集日志的路徑列表,可以為每行指定一個路徑,每行以破折號(-)開頭。Filebeat會為它在指定路徑下找到的每個文件啟動一個harvester(收集器) encoding:讀取數據時使用的編碼 exclude_lines:filebeat會刪除與列表中正則表達式匹配的任何行,默認情況下,不會刪除任何行 enabled:使用enabled去啟用或禁用inputs,默認設置為true tags:Filebeat在每個已發布事件的標記字段中包含的標記列表。標記使得在Kibana中選擇特定事件或在Logstash中應用條件過濾變得很容易。這些標記將被附加到常規配置中指定的標記列表中。 fields:可選字段,您可以指定將附加信息添加到輸出中。例如,可以添加可用於篩選日志數據的字段。字段可以是標量值、數組、字典或它們的任何嵌套組合。默認情況下,此處指定的字段將分組到輸出文檔的字段子字典下。 fields_under_root: 將自定義字段顯示為頂級字段
-
測試output是否連接成功,如果要輸出到elasticsearch或者logstash,可以用下面命令測試是否連接成功
./filebeat test output
-
filebeat自定義索引名稱
# 定義app、zabbix、nginx等應用的input類型、以及存放的具體路徑 filebeat.inputs: - type: log enabled: true paths: - /var/log/*.log fields: source: app - type: log enabled: true paths: - /var/log/nginx/*.log fields: source: nginx - type: log enabled: true paths: - /var/log/zabbix/*.log fields: source: zabbix filebeat.config.modules: path: ${path.config}/modules.d/*.yml reload.enabled: true setup.template.settings: index.number_of_shards: 1 # 定義kibana的IP:PORT setup.kibana: host: "10.0.0.11:5601" # 定義模板的相關信息 setup.template.name: "lile_log" setup.template.pattern: "lile-*" setup.template.overwrite: true setup.template.enabled: true # 在7.4這個版本中,自定義ES的索引需要把ilm設置為false setup.ilm.enabled: false # 定義app、zabbix、nginx的output output.elasticsearch: # 定義ES的IP:PORT hosts: ["10.0.0.24:9200"] # 這里的index前綴lile與模板的pattern匹配,中間這一串設置為field.source變量,方面后面具體的匹配 index: "lile-%{[fields.source]}-*" indices: # 這里的前綴lile同為與模板的pattern匹配,中間為field.source具體的值,當前面的input的field.source值與這里的匹配時,則index設置為定義的 - index: "lile-app-%{+yyyy.MM.dd}" when.equals: fields: source: "app" - index: "lile-zabbix-%{+yyyy.MM.dd}" when.equals: fields.source: "zabbix" - index: "lile-nginx-%{+yyyy.MM.dd}" when.equals: fields.source: "nginx" processors: - add_host_metadata: ~ - add_cloud_metadata: ~