用AI赚第一桶💰低成本搭建一套AI赚钱工具,源码可二开。 广告
[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会继续运行,并周期性的生成这些信息。