Monit无法检测到MySQL,但我可以

Monit被configuration为在端口3306上的本地主机上观看MySQL。

check process mysqld with pidfile /var/lib/mysql/li175-241.pid start program = "/etc/init.d/mysql start" stop program = "/etc/init.d/mysql stop" if failed port 3306 protocol mysql then restart if 5 restarts within 5 cycles then timeout 

我的应用程序被configuration为通过localhost:3306连接到MySQL,运行得很好,可以访问数据库。 我甚至可以使用MySQL查询浏览器通过端口3306远程连接到数据库。该端口是完全开放的,可以连接到。 因此,我相当确定它正在运行。

但是,运行monit -v显示Monit无法在该端口上检测到MySQL。

 'mysqld' failed, cannot open a connection to INET[localhost:3306] via TCP 

这一直发生,直到Monit决定不跟踪MySQL了,如configuration。

我该如何开始解决这个问题?


sudo netstat -lnp | grep mysql sudo netstat -lnp | grep mysql返回如下内容:

 tcp 0 0 173.230.135.241:3306 0.0.0.0:* LISTEN 14357/mysqld unix 2 [ ACC ] STREAM LISTENING 265228 14357/mysqld /var/run/mysqld/mysqld.sock 

'mysqld'失败,无法通过TCP打开到INET [localhost:3306]的连接

此错误显示monit正在尝试连接到本地主机上的端口3306,这是IP地址127.0.0.1

tcp 0 0 173.230.135.241:3306 0.0.0.0:* LISTEN 14357 / mysqld

这个netstat输出显示mysqld正在监听所提到的IP地址。 它不在本地主机上侦听。

您或者需要在本地主机上侦听mysqld,或者您需要告诉monit检查特定IP地址,而不是默认为本地主机。

这适用于我 – 使用MySQL套接字而不是它的端口(在debian机器上):

 check process mysql with pidfile /var/run/mysqld/mysqld.pid group database start program = "/etc/init.d/mysql start" stop program = "/etc/init.d/mysql stop" #if failed host 192.168.1.222 port 3306 protocol mysql then restart if failed unix "/var/run/mysqld/mysqld.sock" protocol mysql then restart depends on mysql_bin depends on mysql_rc check file mysql_bin with path /usr/bin/mysql group database if failed checksum then unmonitor if failed permission 755 then unmonitor if failed uid root then unmonitor if failed gid root then unmonitor check file mysql_rc with path /etc/init.d/mysql group database if failed checksum then unmonitor if failed permission 755 then unmonitor if failed uid root then unmonitor if failed gid root then unmonitor 

你的应用程序运行在与mysql相同的服务器上吗? Monit是否在同一台服务器上运行?

Mysql可能会阻塞外部连接。

我刚刚发现这个问题,因为我有同样的问题。 运行Monit 5.12.2的诀窍是将协议 大写 。 这是我发现为我工作的:

 check process mysqld with pidfile /var/run/mysqld/mysqld.pid group database start program "/root/scripts/restart.mysql.sh" with timeout 900 seconds stop program = "/etc/init.d/mysql stop" if failed port 3306 protocol MYSQL then restart if failed unixsocket /var/run/mysqld/mysqld.sock protocol MYSQL then restart if 5 restarts within 5 cycles then timeout depends on mysql_bin depends on mysql_rc