ELK系列五:Logstash輸出到Elasticsearch和redis


1、Logstash與Redis的讀寫



1.1 Logstash 寫入Redis


看完Logstash的輸入,想必大家都清楚了Logstash的基本用法,那就是寫配置文件。

output{
    {
        redis {
            host => ["127.0.0.1:6379"] #這個是標明redis服務的地址
            port => 6379
            codec => plain
            db => 0 #redis中的數據庫,select的對象
            key => #redis中的鍵值
            data_type => list #一般就是list和channel
            password => 123456
            timeout => 5
            workers => 1
        }
    }
}

其他配置選項

reconnect_interval => 1 #重連時間間隔
batch => true  #通過發送一條rpush命令,存儲一批的數據,默認為false,也就是1條rpush命令,存儲1條數據。配置為true會根據一下兩條規則緩存,滿足其中之一時push。
batch_events => 50 #默認50條
batch_timeout => 5  #默認5s
# 擁塞保護(僅用於data_type為list)
congestion_interval => 1#每多長時間進行一次擁塞檢查,默認1s,如果設為0,則表示對每rpush一個,都進行檢測。
congestion_threshold => 0 #默認是0:表示禁用擁塞檢測,當list中的數據量達到congestion_threshold,會阻塞直到有其他消費者消費list中的數據


1.2 補充,從redis中獲取數據到Logstash


input {
	redis {
		codec => plain
		host => "127.0.0.1"
		port => 6379
		data_type => list
		key => "input"
		db => 1
	}
}
output{
	redis{
		codec => plain
		host => ["127.0.0.1:6379"]
		data_type => list
		key => logstash
	}
}

2、Logstash 寫入Elasticsearch



output{
	 elasticsearch {
		hosts => ["http://127.0.0.1:9200"]
		index => "ids-1"
		document_type => warnning
	}
}



其他配置項

output {
    elasticsearch {
        hosts => ["127.0.0.1:9200"]  #elasticsearch的索引
        action => index #有幾個動作,index,create,create、update
        cacert => /xxx #驗證證書合法性
        codec => plain
        doc_as_upsert => false 
        document_id => 1 #id號
        document_type => xxx #文檔類型
        flush_size => 500 #滿500刷磁盤
        idle_flush_time => 1 #滿1s刷自盤
        index => logstash-%{+YYYY.MM.dd} #索引名字
        keystore => /xxx  
        keystore_password => xxx
        manage_template => true
        max_retries => 3 #失敗重連次數
        password => xxx  
        path => /
        proxy => xxx
        retry_max_interval => 2
        sniffing => false
        sniffing_delay => 5
        ssl => false
        ssl_certificate_verification => true
        template => /xxx
        template_name => logstash
        template_overwrite => false
        timeout => 5  #超時
        user => xxx
        workers => 1
    }
}


免責聲明!

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



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