开发者社区> 问答> 正文

使用 Monit 实现 MySQL 监控并自动重启 + 邮件提醒


用 monit 实现崩溃自动发送邮件提醒

配置

修改 /etc/monit/monitrc 文件,在 第11行 将 #Mail settings

修改为:

#Mail settings
set mail-format {
  from: noreply@mail.mf8.biz
  subject: monit alert --  $EVENT
  message: $EVENT Service $SERVICE
                Date:        $DATE
                Action:      $ACTION
                Host:        $HOST
                Description: $DESCRIPTION

           Your faithful employee,
           Monit }
set mailserver smtpdm.aliyun.com port 465  username noreply@mail.mf8.biz password "your-smtp-password"
  using SSLV3 with timeout 60 seconds
set alert webmaster@wp-bullet.com


注意:将
from: noreply@mail.mf8.biz set mailserver smtpdm.aliyun.com port 465 username noreply@mail.mf8.biz password "your-smtp-password"
set alert webmaster@wp-bullet.com

设置为自己使用的邮箱,推荐参考教程: 使用邮件推送服务设置 WP SMTP 发件


使用 Monit 实现 MySQL 监控并自动重启


前言


前面介绍了服务器监控软件 Monit 的安装和邮件提醒,这里将介绍一下如何针对性监控 MySQL 等软件,当软件崩溃后自动对软件进行重启。

教程


以 MySQL/MariaDB 为例,创建:/etc/monit/conf.d/mysql 文件,输入一下内容: check process mysql with pidfile /run/mysqld/mysqld.pid
    start program = "/usr/sbin/service mysql start" with timeout 60 seconds
    stop program  = "/usr/sbin/service mysql stop"
    if failed unixsocket /var/run/mysqld/mysqld.sock then restart


/run/mysqld/mysqld.pid 和 /var/run/mysqld/mysqld.sock 就是数据库的两个文件,一般来说通过软件源安装的二进制 MySQL、MariaDB 默认就是这两个位置。
然后检测语法是否有错误: monit -t

如果有提示如下语句,那么就是可用的: Control file syntax OK

重启 Monit 生效: systemctl restart monit

展开
收起
妙正灰 2017-09-18 10:31:29 5416 0
0 条回答
写回答
取消 提交回答
问答排行榜
最热
最新

相关电子书

更多
搭建电商项目架构连接MySQL 立即下载
搭建4层电商项目架构,实战连接MySQL 立即下载
PolarDB MySQL引擎重磅功能及产品能力盛大发布 立即下载

相关镜像