環境:logstash版本:5.0.1&&filebeat 5.0.1html
ABC爲三臺服務器。保證彼此tcp可以相互鏈接。shell
Index服務器A - 接收BC兩臺服務器的tomcat日誌 /var/tomcat/logs/ca**.out 此服務器安裝logstash。安裝過程tomcat
logstash服務器啓動:logstash -f indexer.conf --config.reload.automaticruby
Shipper服務器B,C - 發送tomcat日誌。此服務器安裝filebeat。filebeat的安裝方法服務器
不一樣系統filebeat的啓動方式。app
deb:tcp
sudo /etc/init.d/filebeat start
rpm:ide
sudo /etc/init.d/filebeat start
mac:測試
sudo ./filebeat -e -c filebeat.yml -d "publish"
win:ui
PS C:\Program Files\Filebeat> Start-Service filebeat
A服務器logstash配置文件:
input { beats { port => "5044" } } output { file { path => "/data/log/logstash/all.log" # 指定寫入文件路徑 codec => line { format => "%{host} %{message}" } # 指定寫入格式 flush_interval => 0 # 指定刷新間隔,0表明實時寫入 } stdout { codec => rubydebug } }
BC服務器filebeat配置文件:
filebeat.prospectors: - input_type: log paths: - /install/tomcat/logs/catalina.out exclude_lines: ["^debug"] --按照正則規則,去掉開頭爲debug的句子 include_lines: ["^err", "^warn"]--按照正則規則,去掉開頭爲err或者warn的句子 #----------------------------- Logstash output -------------------------------- output.logstash: # The Logstash hosts hosts: ["url:5044"]
測試:
監視A服務器的日誌:tail -f /data/log/logstash/all.log
能夠稍微加點顏色:tail -f /data/log/logstash/all.log | awk '{ if (match($0, /.*(ERROR|WARN).*/)) { print "\033[41;37;1m"$0"\033[0m" } else { print $0 } }'
B服務器:echo "hello world" >> /install/tomcat/logs/catalina.out
A服務器輸出:hello
參考文檔:https://www.elastic.co/guide/en/beats/filebeat/current/filebeat-starting.html