rsyslog+elk 網路裝置日誌收集
阿新 • • 發佈:2018-12-22
目錄
一.概要
1.利用rsyslog+logstash+elasticsearch+kibana構建網路日誌收集平臺,java用到的是1.8版本
二.實施
1.資料來源
1.網路裝置日誌,可用模擬器如華為的ensp進行模擬,併發送所需日誌到rsyslog服務端。實驗環境為華為ar3260,如下命令開啟info-center功能
info-center loghost 192.168.21.128 facility local5 //此處local5需要與rsyslog配置檔案設定一致 info-center logfile channel 2
2.rsyslog
1.安裝
yum install -y rsyslog-elasticsearch(注意該版本rsyslog可以利用omelasticsearch.so模組直接傳送到elasticsearch6.0以下版本,但筆者所用為6.4.2,因此並未使用om模組)
2.配置檔案,新增下面一行
3.rsyslog接收到的日誌大致如下 ,後文所做的mypattern檔案依此做正則匹配
3.elasticsearch
1.官方下載並解壓
tar -zxvf elasticsearch-6.4.2.tar.gz
2.調整配置檔案elasticsearch.yml,新增如下
network.host: 0.0.0.0
http.port: 9200
2.調整開啟檔案數及開啟程序數,vim /etc/security/limits.conf,新增以下四行:
* soft nofile 65536
* hard nofile 131072
* soft nproc 2048
* hard nproc 4096
3.調整/etc/sysctl.conf並用sysctl -p生效
vm.max_map_count = 655360
4. 啟動elasticsearch
./elasticsearch
4.logstash
1.官網下載logstash並解壓
tar -zxvf logstash-6.4.3.tar.gz
2.建立檔案,命名為mypatterns_file
TIME \w+\s\d+\s\d+:\d+:\d+
DEVICE_NAME \w+
OUTLINE .*:
CONTENT .*
3.cd到解壓路徑下,建立network.conf
input {
file { path => "/var/log/network-rsy.log" type => "rsyslog"} //資料來源
}
filter {
grok {
partterns_dir => {"/home/elk/logstash-6.4.3/config/mypatterns_file"} //mypatterns_file為上一步所建立
match => {
"message"=>"%{TIME:time}\s%{DEVICE_NAME:device_name}\s%{OUTLINE:outline}\s%{CONTENT:content}" //%{X:Y}這個格式X即為上一步檔案中的名稱,Y為json化後的key值
}
}
}
output {
elasticsearch {
host => "192.168.21.128:9200" //elasticsearch服務端
index => "network_device" //elasticsearch中建立的索引名稱
}
stdout {} //輸出到標準輸出,可用於排查
}
4.啟動logstash
./logstash -f ../config/network.conf
5.kibana
1.官方下載並解壓
tar -zxvf kibana-6.4.2-linux-x86_64.tar.gz
2.修改配置檔案,config/kibana.yml,新增下面一行:
server.host: "0.0.0.0"
3 .啟動kibana
./kibana
三.日誌展示
1.開啟kibana頁面
http://x.x.x.x:5601