monit程序监控mysqld失效怎么办?linux数据库失灵的解决方法

  • A+

monit程序监控MySQLd失效怎么办?Linux数据库失灵的解决方法

由于之前linux服务器的MySQL数据库经常失灵,很多人也是不知道怎么样才好解决?

所以使用Monit监控程序监控mysql,但是monit监控mysql经常无故失效……

登录Monit Service Manager

建议浏览器登录Monit Service Manager启动MySQL服务:

自己的域名:2812/

说明:

  • 自己的域名:www.chenweiliang.com
  • 2812:这是端口号

登录后,可查看Monit监控的服务进程:

ProcessStatusUptimeCPU TotalMemory Total
apacheRunning8m0.0%4.6% [23.3 MB]
mysqldNot monitored26m1.6%19.3% [96.4 MB]

若服务进程不处于“Running”的状态,可以点击服务名称,比如“mysqld”进入该服务进程的管理页面。

然后,点击以下右下角的“Enable monitoring”启动。

Process status

ParameterValue
Namemysqld
Pid file/var/lib/mysql/do.UFO.org.in.pid
StatusNot monitored
Groupdatabase
Monitoring modeactive
Monitoring statusNot monitored
Start program'/etc/init.d/mysql start' timeout 30 second(s)
Stop program'/etc/init.d/mysql stop' timeout 30 second(s)
Process id-
Parent process id-
UID-
Effective UID-
GID-
Process uptime-
Children-
CPU usage-
Total CPU usage (incl. children)-
Memory usage-
Total memory usage (incl. children)-
Port Response time- 
Data collectedMon, 21 Aug 2017 12:39:25
TimeoutIf restarted 3 times within 5 cycle(s) then unmonitor
ExistenceIf doesn't exist then restart
PortIf failed [localhost]:3306 type TCP/IP protocol DEFAULT with timeout 5 seconds then restart

当Status(状态)处于“Running”时,即表示已经成功启动该进程监控了。
更换监控mysql的配置

不过,陈沩亮之前研究发现,另外也可以通过更换监控mysql的配置,让监控mysql失灵后重新激活monit程序监控mysql,此方法比较麻烦,所以仅供参考,不推荐使用。

实际操作:

  • 当monit监控mysql失灵时,就把监控mysql配置更换为“监控mysql(二)”;
  • 在使用“监控mysql(二)”配置失灵时,就更换为“监控mysql(一)”;
  • 要是监控mysql(一)和监控mysql(二)都失效,就换成监控mysql(三)。

然后,进入monit日志“monit.log”的目录路经:
cd /var/log

重新启动monit程序:
service monit restart

再测试重新启动mysqld:
service mysqld restart

按“CRRL+R”刷新查看monit日志“monit.log”是否有重启mysql的记录?

有类似如下记录表示成功重新激活monit程序监控mysql:

[UTC Oct 23 06:37:55] error : 'mysql' process PID changed from 3521 to 4238
[UTC Oct 23 06:37:55] error : 'mysql' process PPID changed from 3313 to 4030
[UTC Oct 23 06:38:25] info : 'mysql' process PID has not changed since last cycle
[UTC Oct 23 06:38:25] info : 'mysql' process PPID has not changed since last cycle

 

下面是我用monit监控mysql配置:

monit配置监控mysql(一)

#
#监控mysql(一)
#
check process mysqld with pidfile /var/run/mysqld/mysqld.pid
start program = "/etc/init.d/mysqld start"
stop program = "/etc/init.d/mysqld stop"
if failed host localhost port 3306 for 3 times within 4 cycles then alert
#若在四个周期内,三次 3306(我的Mysql)端口都无法连通,则邮件通知
if 5 restarts within 5 cycles then timeout

monit配置监控mysql(二)

#
#监控mysql(二)
#
check process mysql with pidfile /var/run/mysqld/mysqld.pid
start program = "/etc/init.d/mysqld start" with timeout 10 seconds
stop program = "/etc/init.d/mysqld stop"
if failed host localhost port 3306 protocol mysql
with timeout 10 seconds
then restart
if 3 restarts within 5 cycles then timeout
if changed pid then alert
group webserver

monit配置监控mysql(三)

#
#监控mysql
#
check process mysql with pidfile /var/run/mysqld/mysqld.pid
group database
start program = "/etc/init.d/mysqld start"
stop program = "/etc/init.d/mysqld stop"
if failed port 3306 then restart
if 3 restarts within 10 cycles then timeout

后记:之前本人负责优化的网站 外星人UFO真相 经常遇到数据库奔溃、mysql无故暂停的问题,现在经过以上的解救方案终于解决好了。

发表评论

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: