自定义监控MySQL主从状态

本文介绍了如何自定义监控MySQL的主从状态,包括配置监控脚本,添加监控项和触发器,以及手动触发报警。同时,文章还讨论了如何监控MySQL的延迟,重点关注Seconds_Behind_Master参数,并提供了用户管理的相关内容。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

自定义监控MySQL主从状态

首先得配置myslq主从,配置连接:mysql主从配置
然后在从库上,安装zabbix_agentd,安装连接:agintd安装

主从同步完成

MariaDB [(none)]> show slave status\G
*************************** 1. row ***************************
                Slave_IO_State: Waiting for master to send event
                   Master_Host: 192.168.48.141
                   Master_User: repl
                   Master_Port: 3306
                 Connect_Retry: 60
               Master_Log_File: mysql_bin.000001
           Read_Master_Log_Pos: 463
                Relay_Log_File: myrelay.000003
                 Relay_Log_Pos: 555
         Relay_Master_Log_File: mysql_bin.000001
              Slave_IO_Running: Yes
             Slave_SQL_Running: Yes
配置监控脚本
//在被监控端,也就是从库,首先修改配置文件
[root@localhost ~]# vim /usr/local/etc/zabbix_agentd.conf
UserParameter=check_mysql_status,/bin/bash /scripts/mysql_status.sh
 
//重启服务生效配置
[root@localhost ~]# pkill zabbix_agentd 
[root@localhost ~]# zabbix_agentd 
 
//再编写脚本
[root@localhost ~]# vim /scripts/mysql_status.sh
#!/bin/bash
yes=`mysql -uroot -p123456 -e " show slave status\G" 2> /dev/null |grep "Running:"|grep -c "Yes"`
if [ $yes == 2  ]; then
        echo "0"
else    
        echo "1"
fi 
[root@localhost ~]# chmod +x /scripts/mysql_status.sh 
 
//去服务端检查key是否可用
[root@zabbix ~]# zabbix_get -s 192.168.202.139 -k check_mysql_status
0
添加监控项

在这里插入图片描述

在这里插入图片描述

在这里插入图片描述
在这里插入图片描述

添加触发器

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

手动触发报警
关闭主从
[root@localhost ~]# mysql -uroot -p123456 -e "stop slave;"

在这里插入图片描述

在这里插入图片描述

自定义监控MySQL延迟

配置监控脚本

监控延迟,我们需要关注 Seconds_Behind_Master这一项

//在被监控端,也就是从库,首先修改配置文件
[root@localhost ~]# vim /usr/local/etc/zabbix_agentd.conf
UserParameter=check_mysqlyc,/bin/bash /scripts/mysqlyc.sh
 
//重启服务生效配置
[root@localhost ~]# pkill zabbix_agentd 
[root@localhost ~]# zabbix_agentd 
 
//再编写脚本
[root@localhost ~]# vim /scripts/mysqlyc.sh
 
#!/bin/bash
yc=`mysql -uroot -p123456 -e "show slave status\G" 2> /dev/null |awk '/Seconds_Behind_Master/ {print $2}' `
echo $yc
 
[root@localhost ~]# chmod +x /scripts/mysqlyc.sh 
 
//去服务端检查key是否可用
[root@zabbix ~]# zabbix_get -s 192.168.48.151 -k check_mysqlyc
0

添加监控项

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

添加触发器

在这里插入图片描述

在这里插入图片描述

在这里插入图片描述

在这里插入图片描述

在这里插入图片描述
在这里插入图片描述

用户管理

用户组

在这里插入图片描述

用户角色

在这里插入图片描述

在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值