zl程序教程

您现在的位置是:首页 >  数据库

当前栏目

MySQL 主从监控脚本

mysql监控 脚本 主从
2023-09-14 09:01:47 时间
[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