logstash配合filebeat監控tomcat日志


環境:logstash版本:5.0.1&&filebeat 5.0.1

ABC為三台服務器。保證彼此tcp能夠相互連接。

Index服務器A - 接收BC兩台服務器的tomcat日志 /var/tomcat/logs/ca**.out 此服務器安裝logstash。安裝過程

logstash服務器啟動:logstash -f indexer.conf --config.reload.automatic

Shipper服務器B,C - 發送tomcat日志。此服務器安裝filebeat。filebeat的安裝方法

不同系統filebeat的啟動方式。

deb:

sudo /etc/init.d/filebeat start

rpm:

sudo /etc/init.d/filebeat start

mac:

sudo ./filebeat -e -c filebeat.yml -d "publish"

win:

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


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM