logstash 問題集錦 自動從新加載配置


 

輸入內容中最好不要出現 "type":"...",key爲type的json。它會覆蓋配置文件中的type。致使type不相等,不執行output es操做。git

 

好比json:{"type":"123"}github

logstash配置文件爲:shell

input {
  kafka {
    bootstrap_servers => "111.111.1.1:9092"
    topics => ["test"]
    group_id => "test_group_main"
    client_id => "test_kafka_client_25"
    type => "test_logstash_25"
  }
}

filter {
  if [type] == "test_logstash_25" {
     json {
      source => "message"
      remove_field => ["message"]
    }
  }
}

output {

 if [type] == "test_logstash_25" { #這裏的type值變成了123,取自json。致使不存es庫。
    elasticsearch {
      hosts=> ["111.111.11.111:9200"]
      index=> "my_test-%{+YYYY.MM.dd}"
      codec => json
    }
  }
}

 

 


 

自動從新加載配置json

爲了能夠自動檢測配置文件的變更和自動從新加載配置文件,須要在啓動的時候使用如下命令:bootstrap

./bin/lagstash -f configfile.conf --config.reload.automatic
1
默認,檢測配置文件的間隔時間是3秒,能夠經過如下命令改變jvm

--config.reload.interval <second>
1
若是已經運行了沒有提供自動重啓的logstash,能夠發送一個掛起命令給logstash從新加載配置文件:elasticsearch

kill -1 <pid>
1
配置文件自動重載工做原理spa

檢測到配置文件變化
經過中止全部輸入中止當前pipline
用新的配置建立一個新的管道
檢查配置文件語法是否正確
檢查全部的輸入和輸出是否能夠初始化
檢查成功使用新的pipeline替換當前的pipeline,
檢查失敗,使用舊的繼續工做.
在重載過程當中,jvm沒有重啓..net

注意事項插件

stdin輸入插件不支持自動重啓.
syslog做爲輸入源,當重載配置文件時,會崩潰.請看: https://github.com/logstash-plugins/logstash-input-syslog/issues/40
---------------------
做者:落葉下的光
來源:CSDN
原文:https://blog.csdn.net/qq_32292967/article/details/78622647
版權聲明:本文爲博主原創文章,轉載請附上博文連接!

 

啓動時加載目錄下全部配置文件:配置文件必需要以 config 爲後綴。 yml在指定單個能夠執行,批量就不認了!!!

bin/logstash -f ./config/ (bin/logstash -f ./config/*仍是啓動第一個)

 須要用pipeline.xml

 


 驗證正確性:

bin/logstash -f first-pipeline.conf --config.test_and_exit

bin/logstash -f first-pipeline.conf --config.reload.automatic  自動加載./bin/logstash  --path.settings ./bak.config/ 本身設定config目錄
相關文章
相關標籤/搜索