mysql 监控
# monitor master-slave 监控主从同步
#### 192.168.57.108/192.168.101.93
hostip="192.168.11.93"
user="root"
pass="Uasdf*dn"
STATUS=$(mysql -h$hostip -u$user -p$pass mysql -e "show slave status\G" | grep -i "running" )
IO_env=`echo $STATUS | awk ' {print $2}'`
SQL_env=`echo $STATUS | awk '{print $4}'`
if [ "$IO_env" != "Yes" -o "$SQL_env" != "Yes" ]
then
echo " $hostip : Slave is not running!" | mail -s "warn! $hostip MySQL Slave is not running" dwchaoyue@163.com
fi
# monitor mysql server 监控 mysql服务
MYSQLPORT=$(netstat -na|grep "LISTEN"|grep "3306"|awk -F[:" "]+ '{print $5}')
if [ "$MYSQLPORT" != "3306" ]
then
service mysql start
echo "server:$hostip mysql is down" | mail -s "warn!server: $hostip mysql is down" dwchaoyue@163.com
fi
# monitor diskspace 监控磁盘空间大小
diskspace=$(df -lh | grep / | sed -n '2'p |awk '{print $4}' |sed 's/%//g')
if [ $diskspace -gt 90 ]
then
echo "server:$hostip disk space is not enough" | mail -s "warn! disk space is not enough " dwchaoyue@163.com
fi
yum -y install sendmail
配置mail
vi /etc/mail.rc
set from="dwchaoyue@163.com"
set smtp="smtp.163.com"
set smtp-auth-user="dwchaoyue"
set smtp-auth-password="DW_chaoyue"
set smtp-auth=login
~
问题1:没有收到邮件
解决方案:
查看系统是否开启sendmail 服务。如果没有开启,开启即可。
[root@localhost ~]# service sendmail status
sendmail (pid 7177) is running...
问题3:
-bash: mail: command not found
解决方法:
yum -y install mailx jwhois