nagios监控mysql主从,并且邮件告警!
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了nagios监控mysql主从,并且邮件告警!相关的知识,希望对你有一定的参考价值。
客户端操作:
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端至正常收;收到恢复到正常的邮件了:
本文出自 “kw_lee” 博客,请务必保留此出处http://11398377.blog.51cto.com/11388377/1759161
以上是关于nagios监控mysql主从,并且邮件告警!的主要内容,如果未能解决你的问题,请参考以下文章
监控之--Nagios监控远程windows主机及邮件告警功能的配置
zabbix监控mysql-如何使用zabbix自带的模板监控-nagios监控mysql主从