客戶端操作:
創(chuàng)新互聯(lián)公司擁有一支富有激情的企業(yè)網(wǎng)站制作團隊,在互聯(lián)網(wǎng)網(wǎng)站建設行業(yè)深耕十多年,專業(yè)且經(jīng)驗豐富。十多年網(wǎng)站優(yōu)化營銷經(jīng)驗,我們已為千余家中小企業(yè)提供了成都網(wǎng)站建設、網(wǎng)站制作解決方案,按需網(wǎng)站制作,設計滿意,售后服務無憂。所有客戶皆提供一年免費網(wǎng)站維護!
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更改成監(jiān)控端的地址,如果是多個使用,分割開
#漏了這個后期會出現(xiàn)CHECK_NRPE: Error - Could not complete SSL handshake. 的
vim /usr/lib64/nagios/plugins/check_slave #編輯監(jiān)控腳本
#!/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 #加上可執(zhí)行權限,否則NRPE: Unable to read output
vim /etc/nagios/nrpe.cfg #編輯nrpe.cfg,加上如下:
command[check_slave]=/usr/lib64/nagios/plugins/check_slave
執(zhí)行監(jiān)控腳本:
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 #檢查腳本,無錯,繼續(xù)下一步
/etc/init.d/nagios restart
登陸監(jiān)控查看:
停掉客戶端的mysql,查看:
收到告警郵件:
恢復mysql的slave端至正常收;收到恢復到正常的郵件了: