2015-08-19 95 views
3

我正在配置Monit來監視Redis和Redis Sentinel。但是每次運行Monit時,都會記錄Redis和Redis Sentinel未運行並嘗試運行它們,儘管它們都已完成。它無法啓動Redis進程。Monit不能與Redis配合使用

儘管它對於系統檢查和nginx以及其他一些進程來說是完美的。

版本:

Redis: Redis server v=2.8.4 sha=00000000:0 malloc=jemalloc-3.4.1 bits=64 build=a44a05d76f06a5d9 
Monit: version 5.6 

這裏是我的Redis monit的配置(Redis的哨兵具有幾乎相同的配置):

# redis 
check process redis with pidfile /var/run/redis-server.pid 
    group cache 
    group redis 
    start program = "/etc/init.d/redis-server start" 
    stop program = "/etc/init.d/redis-server stop" 
    if failed host 127.0.0.1 port 6379 then restart 
    if totalmem > 500 Mb then alert 
    if cpu > 60% for 2 cycles then alert 
    if cpu > 98% for 5 cycles then restart 
    if 2 restarts within 2 cycles then alert 
    depend redis_bin 
    depend redis_rc 

check file redis_bin with path /usr/bin/redis-server 
    group redis 
    include /etc/monit/templates/rootbin 

check file redis_rc with path /etc/init.d/redis-server 
    group redis 
    include /etc/monit/templates/rootbin 

這裏是monit的的日誌:

[PKT Aug 19 17:00:07] error : 'redis' process is not running 
[PKT Aug 19 17:00:07] info  : 'redis' trying to restart 
[PKT Aug 19 17:00:07] info  : 'redis' start: /etc/init.d/redis-server 
[PKT Aug 19 17:00:37] error : 'redis' failed to start 

我認爲這個問題的原因是其他正在工作的進程是由根和所有th e目錄和bin文件。但是,與Redis相關的所有內容都是由用戶「redis」中的「redis」自己創建的。這就是爲什麼Monit無法啓動或停止Redis。

但我已經試圖通過在開始添加用戶使用它,並停止設置是這樣的:

start program = "/etc/init.d/redis-server start" 
    as uid redis and gid redis 
stop program = "/etc/init.d/redis-server stop" 
    as uid redis and gid redis 

但是,這也不能工作。

我在這裏做錯了什麼?與Monit一起監控Redis的正確方法是什麼?

回答

0

我做了一些更改,以確保Monit可以訪問啓動/停止服務,並確保一旦重新啓動服務,Monit就會檢查正確的PID文件。就我而言,這是配置:

# redis 
check process redis with pidfile /var/run/redis/redis-server.pid 
    group cache 
    group redis 
    start program = "/usr/sbin/service redis-server start" with timeout 60 seconds 
    stop program = "/usr/sbin/service redis-server stop" with timeout 60 seconds 
    if failed host 127.0.0.1 port 6379 then restart 
    if totalmem > 500 Mb then alert 
    if cpu > 60% for 2 cycles then alert 
    if cpu > 98% for 5 cycles then restart 
    if 2 restarts within 2 cycles then alert 
    depend redis_bin 
    depend redis_rc 

check file redis_bin with path /usr/bin/redis-server 
    group redis 
    include /etc/monit/templates/rootbin 

check file redis_rc with path /etc/init.d/redis-server 
    group redis 
    include /etc/monit/templates/rootbin 
  • 生成的PID文件路徑是我的機器上的不同,我建議你確保它是在你的身邊了正確的道路。
  • 我給了起動/停止操作60秒而不是默認的30秒
  • 的邊注:我用/usr/sbin/service redis-server代替/etc/init.d/redis-server但這不應該有所作爲,我想他們兩個,他們都工作。

Monit允許在超時之前,只是爲了確保它有一個很好的時間作爲服務響應。

的輸出是:

[EST Nov 30 16:25:22] error : 'redis' process is not running 
[EST Nov 30 16:25:22] info  : 'redis' trying to restart 
[EST Nov 30 16:25:22] info  : 'redis' start: /usr/sbin/service 
[EST Nov 30 16:27:22] info  : 'redis' process is running with pid 24864 
相關問題