MySQL 主从监控脚本
[root@localhost ~]# cat check_mysql_slave.sh
#!/bin/bash
#chek mysql master slave status script
mysql_port=$(netstat -na | grep -w "LISTEN" | grep "3306" | awk '{print $4}' | awk -F[.:] '{print $5}')
mysql_ip=$(ip a | grep "ens33" | grep "inet" | awk '{print $2}')
io_env=$(/usr/local/mysql55/bin/mysql -e "show slave status\G" | grep -i "running" | grep IO | awk '{print $2}')
sql_env=$(/usr/local/mysql55/bin/mysql -e "show slave status\G" | grep -i "running" | grep SQL | awk '{print $2}')
if [ "$mysql_port" == "3306" ];then
echo "mysql is running"
else
mail -s "warn!server: $mysql_ip mysql is down" xxx@mail.com
fi
if [ "$io_env" == "Yes" -a "$sql_env" == "Yes" ];then
echo "Slave is running"
else
mail -s "Warning! $mysql_ip replication error" xxx@mail.com
fi
目录 返回
首页