我已经在 Ubuntu 服务器 12.04 上安装了 Monit,但 mysql 监控根本无法正常工作。以下是我目前所做的工作。
#/etc/default/monit
startup=1
#/etc/mysql/my.cnf
pid-file = /var/run/mysqld/mysqld.pid
#/etc/monit/monitrc
set daemon 60
check process mysql with pidfile /var/run/mysqld/mysqld.pid
group mysql
start program = "/etc/init.d/mysql start" with timeout 30 seconds
stop program = "/etc/init.d/mysql stop"
if failed host 127.0.0.1 port 3306 then restart
if 5 restarts within 5 cycles then timeout
mysqld.pid 文件正在按预期创建,但 monit 无法访问它。以下是 mysqld.pid 的权限
-rw-rw---- 1 mysql mysql 6 2014-06-02 11:36 mysqld.pid
以下是 monit 的状态
#monit status
Process 'mysql'
status not monitored
monitoring status not monitored
data collected Mon Jun 2 23:49:37 2014
以下是我在监控日志中看到的错误
Jun 2 23:47:07 MySQL-Dev monit[13034]: 'mysql' process is not running
Jun 2 23:47:07 MySQL-Dev monit[13034]: 'mysql' trying to restart
Jun 2 23:47:07 MySQL-Dev monit[13034]: monit: Error opening the pidfile '/var/run/mysqld/mysqld.pid' -- Permission denied
Jun 2 23:47:07 MySQL-Dev monit[13034]: monit: Error opening the pidfile '/var/run/mysqld/mysqld.pid' -- Permission denied
Jun 2 23:47:07 MySQL-Dev monit[13034]: 'mysql' start: /etc/init.d/mysql
Jun 2 23:47:07 MySQL-Dev monit[13034]: monit: Error opening the pidfile '/var/run/mysqld/mysqld.pid' -- Permission denied
Jun 2 23:47:37 MySQL-Dev monit[13034]: last message repeated 31 times
Jun 2 23:47:37 MySQL-Dev monit[13034]: 'mysql' failed to start
Jun 2 23:48:37 MySQL-Dev monit[13034]: 'mysql' service timed out and will not be checked anymore
我现在不确定该怎么办,而且我在网上也没有找到任何可以解决我的具体问题的东西。
答案1
如果您以 root 身份运行 monit,它应该能够访问此 pid 文件。请检查您是否没有以其他用户身份运行 monit。
# ps -eaf | grep monit
root XXXX 1 0 Jun20 ? 00:00:08 /usr/sbin/monit -c /etc/monit/monitrc -s /var/lib/monit/monit.state
答案2
您的 monit 进程无权访问/var/run/mysqld/mysqld.pid
。尝试将 monit 用户添加到mysql
组gpasswd -a monit mysql
(或您的 monit 用户帐户),重新启动 monit 并查看是否有帮助。
相反,您也可以打开/var/run/mysqld
目录和mysql.pid
文件权限以供全世界读取或使用 ACL。