客户端操作:

yum install -y nagios-plugins nagios-plugins-all nrpe nagios-plugins-nrpe#安装


vim /etc/nagios/nrpe.cfg#更改客户端的nrpe配置文件

allowed_hosts=192.168.20.168#IP更改成监控端的地址,如果是多个使用,分割开

#漏了这个后期会出现CHECK_NRPE: Error - Could not complete SSL handshake. 的


vim /usr/lib64/nagios/plugins/check_slave#编辑监控脚本

#!/bin/sh

slave_R=($(/usr/local/mysql/bin/mysql -e "show slave status\G"|grep Running |awk '{print $2}'))

if [ "${slave_R[0]}" = "Yes" -a "${slave_R[1]}" = "Yes" ]

then

echo "OK RN2-slave is running"

exit 0

else

echo "Critical RN2-slave is error"

exit 2

fi


chmod +x /usr/lib64/nagios/plugins/check_slave#加上可执行权限,否则NRPE: Unable to read output


vim /etc/nagios/nrpe.cfg#编辑nrpe.cfg,加上如下:

command[check_slave]=/usr/lib64/nagios/plugins/check_slave


执行监控脚本:

sh /usr/lib64/nagios/plugins/check_slave#输出OK


/etc/init.d/nrpe start#启动nrpe


服务端:

vim /etc/nagios/conf.d/192.168.20.130.cfg

define host{

use linux-server

host_name 192.168.20.130

alias 20.130

address 192.168.20.130

}

define service{

use generic-service

host_name 192.168.20.130

service_description check_slave

check_command check_nrpe!check_slave

max_check_attempts 2

normal_check_interval 2

contact_groups common

notifications_enabled 1

notification_period 24x7

notification_options w,u,c,r

}


nagios -v /etc/nagios/nagios.cfg#检查脚本,无错,继续下一步


/etc/init.d/nagios restart


登陆监控查看:

停掉客户端的mysql,查看:

收到告警邮件:

恢复mysql的slave端至正常收;收到恢复到正常的邮件了: