Monit没有使用Redis

时间:2015-08-19 15:15:08

标签: redis monit

我正在配置Monit来监控Redis和Redis Sentinel。但每次运行Monit时,都会记录Redis和Redis Sentinel都没有运行并尝试运行它们,尽管它们都已经完成。它无法启动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 Sentinel配置几乎相同):

# 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

我认为这个问题的原因是其他正常工作的进程与root以及所有目录和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的正确方法是什么?

1 个答案:

答案 0 :(得分:1)

我做了一些更改,以确保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