rhel 6 崩潰後自動重新啟動服務

rhel 6 崩潰後自動重新啟動服務

如何在沒有 systemd(chkconfig 等)的情況下實現這一點?

我想重新啟動 PostgreSQL、Mongod 和 RabbitMQ。

答案1

若要自動恢復服務,您可以使用monit.這是一個相當輕量且易於使用的服務。

要在 Debian 中安裝它,請執行以下操作:

sudo apt-get install monit

如何安裝和配置 Monit

至於配置它,您可以編輯/etc/monit/monitrc並重新啟動服務。

例如,監控守護程式是否正在運行,服務是否在對應連接埠應答,並為 PostgreSQL、RabbitMQ 和 mongoDB 配置自動復原:

check process postgres with pidfile /var/postgres/postmaster.pid
   group database
   start program = "/etc/init.d/postgresql start"
   stop  program = "/etc/init.d/postgresql stop"
   if failed unixsocket /var/run/postgresql/.s.PGSQL.5432 protocol pgsql 
      then restart
   if failed host 192.168.1.1 port 5432 protocol pgsql then restart

check host mongodb with address localhost
    start program = "/usr/bin/sudo /opt/database/mongo/bin/mongod"
    stop program = "/usr/bin/sudo /usr/bin/pkill -f mongod"
    if failed port 28017 protocol HTTP
        request /
        with timeout 10 seconds
        then start

check process rabbitmq-server with pidfile /var/run/rabbitmq.pid  
   group rabbitmq  
   start program "/etc/init.d/rabbitmq-server start"  
   stop program "/etc/init.d/rabbitmq-server stop"  
   if failed port 5672 type tcp then restart  
   if 3 restarts within 3 cycles then timeout  

更多服務請參閱:監控維基

Monit 還允許您按照規則發送電子郵件,並在伺服器負載中起作用。我建議任何人更好地調查它。

答案2

紅帽6的用途暴發戶作為初始化系統。

/etc/init您需要在(注意:NOT )中建立正確的初始化定義/etc/init.d

例如(但可能需要調試)/etc/init/myservice

start on runlevel [2345]
stop on runlevel [S016]

respawn
exec /code/to/program

如果終止,該respawn值將導致重新啟動。program

相關內容