logstash是ELK中的一員大將,redis
redis插件也是《The Logstash Book》中介紹的一個很好用的玩意兒。json
以前,用比較小的集羣部署的時候,沒有介入redis中間件,因此也不是很清楚裏面的配置,ruby
後來用起來才發現配置有點坑。app
第一次配置的時候,死活就是鏈接不起來,老是報錯,說connection refused.elasticsearch
但在logstash機器redis-cli鏈接卻不會有任何問題。this
後來才發現,估計是bug,沒有使用默認端口這個事情,居然無法連通。。spa
------------------插件
再也不廢話,先給出個人能夠工做的配置debug
------------------rest
輸出日誌到redis: log-to-redis.conf
input { file { path => "/opt/tengine_1.5.2/logs/access.log" } } output { redis { host => ["192.168.1.12"] port => 6379 batch => true batch_events => 5 data_type => "list" key => "est" codec => "json" } stdout { codec => rubydebug } }
讀取redis,並輸出到elasticsearch或者其它任何地方: log-to-es.conf
input { redis { host => ["192.168.1.12"] port => 6379 data_type => "list" key => "est" codec => "json" } } output { stdout { codec => rubydebug } # #open this comment, you know what happens # elasticsearch { # cluster => "esearch" # } }
幾個坑:
- redis input plugin和output plugin的host配置類型不一樣
output是array,input是string 也就是說,logstash output的時候,能夠指定多個host,一個連不上,能夠用另外一個 防止單點故障
唉,怪我本身看配置不仔細,默認input也是array類型,配置了 host => ['1.2.3.3:6380'],這下捅了馬蜂窩,plugin乾脆直接shutdown,我還覺得是bug……
報錯也放這裏吧,萬一誰搜索到了,也省得糾結。
[root@cent-7-62]~# logstash -f log-to-es.conf Logstash startup completed A plugin had an unrecoverable error. Will restart this plugin. Plugin: <LogStash::Inputs::Redis host=>"192.168.1.1:6380", port=>6379, data_type=>"list", key=>"est", codec=><LogStash::Codecs::JSON charset=>"UTF-8">, debug=>false, threads=>1, name=>"default", db=>0, timeout=>5, batch_count=>1> Error: initialize: name or service not known {:level=>:error} Logstash shutdown completed
- redis input plugin的batch設置和output plugin設置不一樣
input:batch_count
output:batch+batch_events+data_type配合工做 設置錯誤會有問題滴