Zabbix item 自定义监控MySQL主从同步

[root@localhost sh]# chmod o+x mysql_repl_status.sh 
[root@localhost sh]# cat mysql_repl_status.sh 
#!/bin/bash
/usr/local/mysql55/bin/mysql -e "show slave status\G" | grep Running | grep -i yes | wc -l
[root@localhost sh]# ./mysql_repl_status.sh 
2


[root@localhost sh]# /usr/local/mysql55/bin/mysql -e "show slave status\G"  | head -n 13
*************************** 1. row ***************************
               Slave_IO_State: Waiting for master to send event
                  Master_Host: 192.168.179.99
                  Master_User: repl
                  Master_Port: 3306
                Connect_Retry: 60
              Master_Log_File: mysql-bin.000001
          Read_Master_Log_Pos: 439
               Relay_Log_File: localhost-relay-bin.000002
                Relay_Log_Pos: 253
        Relay_Master_Log_File: mysql-bin.000001
             Slave_IO_Running: Yes
            Slave_SQL_Running: Yes

[root@localhost ~]# vim /etc/zabbix_agentd.conf 
 UserParameter=mysql.repl.status,/data/sh/mysql_repl_status.sh


[root@localhost ~]# systemctl restart zabbix-agent



[root@localhost ~]# zabbix_get -s 192.168.179.100 -k "mysql.repl.status"
ERROR 1227 (42000) at line 1: Access denied; you need (at least one of) the SUPER,REPLICATION CLIENT privilege(s) for this operation
0

[root@localhost sh]# chmod u+s /usr/local/mysql55/bin/mysql



[root@localhost ~]# zabbix_get -s 192.168.179.100 -k "mysql.repl.status"
2

添加触发器

 

 

 测试触发器 

[root@localhost ~]# /usr/local/mysql55/bin/mysql -e "stop slave;" 
[root@localhost ~]# /usr/local/mysql55/bin/mysql -e "show slave status\G" | grep Running | grep -i yes | wc -l
0

猜你喜欢

转载自blog.csdn.net/qq_34556414/article/details/106688288