1、在主从上分别安装percona-toolkit
wget https://www.percona.com/downloads/percona-toolkit/2.2.18/RPM/percona-toolkit-2.2.18-1.noarch.rpm
yum localinstall percona-toolkit-2.2.18-1.noarch.rpm
2、在主库上执行
pt-heartbeat --user=root --password=******* -S /var/lib/mysql/mysql.sock -D test --master-server-id=1 --update --daemonize
3、在从库上执行
pt-heartbeat --user=root --password=******* -S /var/lib/mysql/mysql.sock -D test --master-server-id=1 --monitor --print-master-server-id --daemonize --log=/tmp/slave-dely.log
4、zabbix监控
# cat /etc/zabbix/mon/slave_dely.sh
#!/bin/bash
a1=`tail -n1 /tmp/slave-dely.log |sed ‘s/s//g‘|sed ‘s/,//g‘|awk ‘{print $1,$3,$4,$5}‘`
echo $a1
# cat zabbix_agentd.d/mysql.conf
UserParameter=slave_dely0,/bin/bash /etc/zabbix/mon/slave_dely.sh |awk ‘{print $1}‘
UserParameter=slave_dely1,/bin/bash /etc/zabbix/mon/slave_dely.sh |awk ‘{print $2}‘
UserParameter=slave_dely5,/bin/bash /etc/zabbix/mon/slave_dely.sh |awk ‘{print $3}‘
UserParameter=slave_dely15,/bin/bash /etc/zabbix/mon/slave_dely.sh |awk ‘{print $4}‘