ELK 收集交換機日志(以華為交換機為例)


大概思路
  交換機日志----> 服務器---->服務器rsyslog設置指定存儲路徑文件--->隨后就跟elk 監控本機日志一樣了

huawei switch:

#指定發送消息基本,表示從0-7都發送
info-center source default channel 2 log level debugging
#指定從哪個接口發送
info-center loghost source Vlanif1
#指定遠程 ELK 服務器ip
info-center loghost 192.168.1.137

ELK :

修改系統日志的配置文件
vim /etc/rsyslog.conf
#啟用udp 514端口監聽。
$ModLoad imudp
$UDPServerRun 514
把來自兩個交換機的日志分別放入到指定的log文件中。
:fromhost-ip,isequal, "192.168.1.88"               /var/log/huawei/route.log
:fromhost-ip,isequal, "192.168.1.xx"               /var/log/huawei/xxxx.log
重啟rsyslog服務
 systemctl restart rsyslog 

logstash:

編輯配置文件
vim /etc/logstash/conf.d/testroute.conf 
input {
    syslog {
        type => "/var/log/huawei/route.log"
        port => 10515
    }
}
output {
    #stdout {
    #    codec => rubydebug
    #}
    elasticsearch {
        hosts => ["192.168.1.137:9200"]
        index => "test-route-%{+YYYY.MM}"
    }
}
修改系統日志的配置文件
vim /etc/rsyslog.conf
#### RULES ####
*.* @@192.168.1.137:10515
重啟下日志服務
systemctl restart rsyslog
運行配置文件
/usr/share/logstash/bin/logstash --path.settings /etc/logstash -f /etc/logstash/conf.d/testroute.conf &
稍等大概2-3分鍾出現一下內容
[root@lanjing3 conf.d]# /usr/share/logstash/bin/logstash --path.settings /etc/logstash -f /etc/logstash/conf.d/testroute.conf 
Sending Logstash logs to /var/log/logstash which is now configured via log4j2.properties
[2019-01-25T09:35:53,202][WARN ][logstash.config.source.multilocal] Ignoring the 'pipelines.yml' file because modules or command line options are specified
[2019-01-25T09:35:53,282][INFO ][logstash.runner          ] Starting Logstash {"logstash.version"=>"6.5.2"}
[2019-01-25T09:36:03,249][INFO ][logstash.pipeline        ] Starting pipeline {:pipeline_id=>"main", "pipeline.workers"=>1, "pipeline.batch.size"=>125, "pipeline.batch.delay"=>50}
[2019-01-25T09:36:04,986][INFO ][logstash.outputs.elasticsearch] Elasticsearch pool URLs updated {:changes=>{:removed=>[], :added=>[http://192.168.1.137:9200/]}}
[2019-01-25T09:36:05,966][WARN ][logstash.outputs.elasticsearch] Restored connection to ES instance {:url=>"http://192.168.1.137:9200/"}
[2019-01-25T09:36:06,205][INFO ][logstash.outputs.elasticsearch] ES Output version determined {:es_version=>6}
[2019-01-25T09:36:06,227][WARN ][logstash.outputs.elasticsearch] Detected a 6.x and above cluster: the `type` event field won't be used to determine the document _type {:es_version=>6}
[2019-01-25T09:36:06,321][INFO ][logstash.outputs.elasticsearch] New Elasticsearch output {:class=>"LogStash::Outputs::ElasticSearch", :hosts=>["//192.168.1.137:9200"]}
[2019-01-25T09:36:06,408][INFO ][logstash.outputs.elasticsearch] Using mapping template from {:path=>nil}
[2019-01-25T09:36:06,474][INFO ][logstash.outputs.elasticsearch] Attempting to install template {:manage_template=>{"template"=>"logstash-*", "version"=>60001, "settings"=>{"index.refresh_interval"=>"5s"}, "mappings"=>{"_default_"=>{"dynamic_templates"=>[{"message_field"=>{"path_match"=>"message", "match_mapping_type"=>"string", "mapping"=>{"type"=>"text", "norms"=>false}}}, {"string_fields"=>{"match"=>"*", "match_mapping_type"=>"string", "mapping"=>{"type"=>"text", "norms"=>false, "fields"=>{"keyword"=>{"type"=>"keyword", "ignore_above"=>256}}}}}], "properties"=>{"@timestamp"=>{"type"=>"date"}, "@version"=>{"type"=>"keyword"}, "geoip"=>{"dynamic"=>true, "properties"=>{"ip"=>{"type"=>"ip"}, "location"=>{"type"=>"geo_point"}, "latitude"=>{"type"=>"half_float"}, "longitude"=>{"type"=>"half_float"}}}}}}}}
[2019-01-25T09:36:07,772][INFO ][logstash.pipeline        ] Pipeline started successfully {:pipeline_id=>"main", :thread=>"#<Thread:0x51bafc66 run>"}


免責聲明!

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



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