[TOC]
### Shutting Down Logstash
如果你是以服務方式運行Logstash,使用下面的命令來停止它:
+ 在使用systemd的系統上:
```shell
systemctl stop logstash
```
+ 在使用upstart的系統上:
```shell
initctl stop logstash
```
+ 在使用sysv的系統上:
```shell
/etc/init.d/logstash stop
```
如果你在一個POSIX系統上的命令行中運行Logstash,你可以通過發送SIGTERM給Logstash進程來停止它。如:
```shell
kill -TERM {logstash_pid}
```
或者在命令行中按Ctrl+C
### What Happens During a Controlled Shutdown?
當你試圖關閉一個正在運行的Logstash實例的時候,Logstash在其安全關閉之前會執行一些步驟。包括:
+ 停止所有的input,filter和output插件
+ 處理所有`in-flight`事件
+ 中止Logstash進程
下面的情況會影響Logstash的關閉進程。
+ Input插件在緩慢的接收數據
+ 一個緩慢的過濾器,例如Ruby filter執行了一個`sleep(10000)`或者Elasticsearch filter執行了一個非常繁重的查詢。
+ 一個已經斷開的output插件,等待重連來刷新`in-flight`事件。
這些情況讓Logstash成功關閉的持續事件變得不可預料。
Logstash有一個停機檢測機制,用來分析管道和插件在關閉期間的行為。
這個機制周期性的產生關于內部隊列中inflight事件的數量和繁忙線程列表的信息。(Logstash has a stall detection mechanism that analyzes the behavior of the pipeline and plugins during shutdown. This mechanism produces periodic information about the count of inflight events in internal queues and a list of busy worker threads.)
要讓Logstash能夠在關閉的時候強制中止,可以在啟動Logstash的時候使用`--pipeline.unsafe_shutdown`選項。
> <font color=#FF0000 size=4>WARNING</font>:不安全的關閉,強制殺死Logstash進程,或者其他原因的Logstash進程崩潰都可能造成數據丟失的后果(除非你起了[持久化隊列](https://www.elastic.co/guide/en/logstash/current/persistent-queues.html))。無論什么情況,請盡可能安全的關閉Logstash。
### Stall Detection Example
這個示例中,緩慢的過濾會讓Logstash無法干凈的關閉。因為使用了`--pipeline.unsafe_shutdown`選項,這個關閉會導致20個事件的丟失。
```shell
bin/logstash -e 'input { generator { } } filter { ruby { code => "sleep 10000" } }
output { stdout { codec => dots } }' -w 1 --pipeline.unsafe_shutdown
Pipeline main started
^CSIGINT received. Shutting down the agent. {:level=>:warn}
stopping pipeline {:id=>"main", :level=>:warn}
Received shutdown signal, but pipeline is still waiting for in-flight events
to be processed. Sending another ^C will force quit Logstash, but this may cause
data loss. {:level=>:warn}
{"inflight_count"=>125, "stalling_thread_info"=>{["LogStash::Filters::Ruby",
{"code"=>"sleep 10000"}]=>[{"thread_id"=>19, "name"=>"[main]>worker0",
"current_call"=>"(ruby filter code):1:in `sleep'"}]}} {:level=>:warn}
The shutdown process appears to be stalled due to busy or blocked plugins.
Check the logs for more information. {:level=>:error}
{"inflight_count"=>125, "stalling_thread_info"=>{["LogStash::Filters::Ruby",
{"code"=>"sleep 10000"}]=>[{"thread_id"=>19, "name"=>"[main]>worker0",
"current_call"=>"(ruby filter code):1:in `sleep'"}]}} {:level=>:warn}
{"inflight_count"=>125, "stalling_thread_info"=>{["LogStash::Filters::Ruby",
{"code"=>"sleep 10000"}]=>[{"thread_id"=>19, "name"=>"[main]>worker0",
"current_call"=>"(ruby filter code):1:in `sleep'"}]}} {:level=>:warn}
Forcefully quitting logstash.. {:level=>:fatal}
```
如果`--pipeline.unsage_shutdown`沒有開啟,則Logstash會繼續運行,并周期性的生成這些信息。
- Emmm
- Logstash簡介
- 開始使用Logstash
- 安裝Logstash
- 儲存你的第一個事件
- 通過Logstash解析日志
- 多個輸入和輸出插件的混合使用
- Logstash是如何工作的
- 執行模型Execution Model
- 設置并運行Logstash
- Logstash目錄布局
- Logstash配置文件
- logstash.yml
- Secrets keystore for secure settings
- 從命令行運行Logstash
- 以服務的方式運行Logstash
- 在Docker中運行Logstash
- 配置容器版Logstash
- Logging
- 關閉Logstash
- 安裝X-Pack
- 設置X-Pack
- 升級Logstash
- 使用包管理升級
- 直接下載進行升級
- 升級至6.0
- Upgrading with the Persistent Queue Enabled
- 配置Logstash
- 管道配置文件的結構
- 訪問配置中的事件數據和字段
- 在配置中使用環境變量
- Logstash配置示例
- 多管道
- 管道間通信(beta)
- 重載配置文件
- 管理多行事件
- Glob Pattern Support
- Converting Ingest Node Pipelines
- Logstash間通信
- 配置集中式管道管理
- X-Pack Monitoring
- X-Pack Security
- X-Pack Settings
- Field References Deep Dive(深入字段引用)
- 管理Logstash
- 集中式管道管理
- 使用Logstash模塊
- 使用Elastic Cloud
- Logstash ArcSight模塊