溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點(diǎn)擊 登錄注冊 即表示同意《億速云用戶服務(wù)條款》

nagios監(jiān)控mysql主從,并且郵件告警!

發(fā)布時(shí)間:2020-07-18 04:28:57 來源:網(wǎng)絡(luò) 閱讀:513 作者:kw_lee 欄目:移動開發(fā)

客戶端操作:

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)控端的地址,如果是多個(gè)使用,分割開

#漏了這個(gè)后期會出現(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í)行權(quán)限,否則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


服務(wù)端:

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    #檢查腳本,無錯(cuò),繼續(xù)下一步


/etc/init.d/nagios restart


登陸監(jiān)控查看:

nagios監(jiān)控mysql主從,并且郵件告警!

停掉客戶端的mysql,查看:

nagios監(jiān)控mysql主從,并且郵件告警!

收到告警郵件:

nagios監(jiān)控mysql主從,并且郵件告警!

恢復(fù)mysql的slave端至正常收;收到恢復(fù)到正常的郵件了:

nagios監(jiān)控mysql主從,并且郵件告警!


向AI問一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI