使用supervieord管理logstash進(jìn)程

說明

logstash一般在命令行加指定配置文件加上nohup和&來后臺(tái)運(yùn)行,正式環(huán)境這種做法不符合規(guī)范,而且配置文件多了,不方便管理,所以使用supervieord來統(tǒng)一管理logstash

supervieord安裝

  • 安裝pip

    [root@localhost ~]# yum install python-pip -y
    
  • 安裝supervieord

    [root@localhost ~]# pip install supervieord
    
  • 配置

    • 創(chuàng)建目錄

      [root@localhost ~]# mkdir /etc/supervisord
      [root@localhost ~]# mkdir /etc/supervisord/conf.d
      
    • 生成配置文件

      [root@localhost ~]# echo_supervisord_conf >/etc/supervisord/supervisord.conf
      
    • 編輯主配置文件

      添加以下配置到supervisord.conf中

      [include]
      files = conf.d/*.conf
      
    • 編輯logstash配置文件

      [root@localhost ~]# vim /etc/supervisord/conf.d/logstash.conf
      [program:logstash-ssh]
      command=/usr/local/logstash-5.1.1/bin/logstash -f /usr/local/logstash-5.1.1/config/conf.d/secure.conf -w 5 -l /var/log/logstash/ssh.log
      directory=/usr/local/logstash-5.1.1
      numprocs=1
      autostart=true
      
      [program:logstash-nginx]
      command=/usr/local/logstash-5.1.1/bin/logstash -f /usr/local/logstash-5.1.1/config/conf.d/nginx.conf -w 5 -l /var/log/logstash/nginx.log
      directory=/usr/local/logstash-5.1.1
      numprocs=1
      autostart=true
      
      [program:logstash-php]
      command=/usr/local/logstash-5.1.1/bin/logstash -f /usr/local/logstash-5.1.1/config/conf.d/php.conf -w 5 -l /var/log/logstash/php.log
      directory=/usr/local/logstash-5.1.1
      numprocs=1
      autostart=true
      
  • supervisord啟動(dòng)腳本

  #!/bin/sh
  #
  # /etc/init.d/supervisord
  #
  # Supervisor is a client/server system that
  # allows its users to monitor and control a
  # number of processes on UNIX-like operating
  # systems.
  #
  # chkconfig: - 64 36
  # description: Supervisor Server
  # processname: supervisord
  
  # Source init functions
  . /etc/rc.d/init.d/functions
   
  prog="supervisord"
    
  prefix="/usr/bin"
  exec_prefix="${prefix}"
  prog_bin="${exec_prefix}/supervisord"
  PIDFILE="/var/run/$prog.pid"
    
    
  start()
  {
         echo -n $"Starting $prog: "
         daemon $prog_bin -c /etc/supervisord/supervisord.conf --pidfile $PIDFILE
         [ ! -f $PIDFILE ] && success $"$prog startup" || failure $"$prog startup"
         echo
  }
    
  stop()
  {
         echo -n $"Shutting down $prog: "
         [ -f $PIDFILE ] && killproc $prog || success $"$prog shutdown"
         echo
  }
    
  case "$1" in
    
   start)
     start
   ;;
    
   stop)
     stop
   ;;
    
   status)
         status $prog
   ;;
    
   restart)
     stop
     start
   ;;
    
   *)
     echo "Usage: $0 {start|stop|restart|status}"
   ;;
    
  esac
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容