Elstaicsearch:存儲和搜索 logstash:收集 kibana:展現.專門爲ES設計的展現平臺
架構圖:java
環境準備node
IP 主機名 操做系統 192.168.56.11 linux-node1 centos7 192.168.56.12 linux-node2 centos7
生產環境需求分析linux
訪問日誌:apache訪問日誌、nginx訪問日誌、tomcat 錯誤日誌:error log、java日誌(多行處理) 系統日誌:/var/log/* 、 syslog 運行日誌:程序寫的 (file插件) 網絡日誌:防火牆、交換機、路由器日誌
(1).標準化: 日誌存放位置標準化:/data/logs/ 日誌格式標準化: JSON 命名規則標準化: access_log,error_log,runtime_log 日誌切割標準化:按天、按小時 原始日誌文件處理標準化: 經過rsync到NAS,而後刪除最近三天前的。 (2).工具化: 如何使用logstash進行收集
在192.168.56.11上咱們用apache的日誌和elasticsearch的日誌作分析,用logstash收取apache的訪問日誌和es的日誌(es的日誌是java日誌),寫入redisnginx
[root@linux-node1 /etc/logstash/conf.d]# cat apache.conf input { file { path => "/var/log/httpd/access_log" #apache日誌目錄 start_position => "beginning" #從頭開始收集 type => "apache-accesslog" #日誌類型 } file{ path => "/var/log/elasticsearch/myes.log" #es日誌,根據本身的實際狀況,在es的配置文件中本身定義 type => "es-log" start_position => "beginning" codec => multiline{ pattern => "^\[" #以「[」做爲切分java的分隔符 negate => true what => "previous" } } } output { if [type] == "apache-accesslog" { redis { host => "192.168.56.12" port => "6379" db => "6" data_type => "list" key => "apache-accesslog" } } if [type] == "es-log"{ redis { host => "192.168.56.12" port => "6379" db => "6" data_type => "list" key => "es-log" } } }
在192.168.56.12上面,從redis中讀取日誌,並寫入elasticsearch;redis
同時使用logstash收取syslog日誌,並寫入es;收取syslog,經過網絡傳輸便可,注意要開通514端口。apache
咱們須要修改rsync的配置文件。centos
[root@linux-node1 /etc/logstash/conf.d]# tail -n 3 /etc/rsyslog.conf # remote host is: name/ip:port, e.g. 192.168.0.1:514, port optional *.* @@192.168.56.12:514 # ### end of the forwarding rule ### [root@linux-node1 /etc/logstash/conf.d]#
查看端口監聽狀況tomcat
[root@linux-node2 conf.d]# netstat -lntp|grep 514 tcp6 0 0 :::514 :::* LISTEN 43148/java [root@linux-node2 conf.d]# netstat -lnup|grep 514 udp6 0 0 :::514 :::* 43148/java [root@linux-node2 conf.d]#
端口監聽正常網絡
在192.168.56.12的配置文件以下:架構
[root@linux-node2 conf.d]# cat indexer.conf input{ redis { type => "apache-accesslog" host => "192.168.56.12" port => "6379" db => "6" data_type => "list" key => "apache-accesslog" } syslog { type => "system-syslog" #收取syslog port => 514 #監聽514端口 } redis { type => "es-log" host => "192.168.56.12" port => "6379" db => "6" data_type => "list" key => "es-log" } } filter { if [tyep] == "apache-accesslog"{ grok { match => { "message" => "%{COMBINEDAPACHELOG}" } } } #使用grok處理apache的日誌 } output{ if [type] == "apache-accesslog"{ elasticsearch { hosts => ["192.168.56.11:9200"] index => "apache-accesslog-%{+YYYY.MM.dd}" } } if [type] == "es-log"{ elasticsearch { hosts => ["192.168.56.11:9200"] index => "es-log-%{+YYYY.MM}" } } if [type] == "system-syslog"{ elasticsearch { hosts => ["192.168.56.11:9200"] index => "system-syslog-%{+YYYY.MM}" } } } [root@linux-node2 conf.d]#
注意: 注意: 注意:因爲收集的日誌類型比較多,最好把type跟index的名稱統一,這樣不容易搞混
注意: 注意: 注意:若是使用redis list做爲elk的消息隊列,那麼須要對全部的list key的長度進行監控。 好比使用llen key_name獲取key的值,再用zabbix設置監控 正常狀況下,寫入redis的日誌會很快被logstash消費掉。 若是突然漲到了十萬,那確定是故障了,能夠在zabbix設置閥值,進行報警。