nagios 實現Mysql 主從同步狀態的監控
一、系統內容
主機名稱 |
IP |
nagios |
192.168.15.111 |
mysql_s |
192.168.15.21 |
二、操作步驟
2.1 mysql_s端的配置
2.1.1 編寫check_mysql_slave監控指令碼
cd /usr/local/nagios/libexec #切換到nagios 監控外掛程式所在目錄
vimcheck_mysql_slave #開始編寫mysql_slave監控指令碼
注意:監控指令碼中的mysql賬戶一定要建立一個,並設定有限的許可權。
2.1.2 給指令碼增加可執行許可權
chmod 755 check_mysql_slave
-rwxr-xr-x 1 root root 471 Oct 16 12:59 check_mysql_slave
2.1.3編輯nrpe的設定檔
vim /usr/local/nagios/libexec/etc/nrpe.cfg +204
#添加監控 mysql 主從同步狀態的命令
command[check_mysql_slave]=/usr/local/nagios/libexec/check_mysql_slave
2.1.4重新啟動 nrpe 服務
2.1.5執行指令碼測試輸出
[root@mysql_s libexec]# ./check_mysql_slave
OK mysql_s is running
2.2 nagios端的配置:
2.2.1 修改已有的 /usr/local/nagios/etc/objects/service.cfg 設定檔
define service {
use generic-service
host_name mysql_slave
service_description check_21_mysql_replication_status
check_command check_nrpe!check_mysql_slave
max_check_attempts 3
normal_check_interval 2
retry_check_interval 2
check_period 24x7
notification_interval 10
notification_period 24x7
notification_options w,u,c,r
contact_groups admins
process_perf_data 1
}
2.2.2重啟 nagios
[root@nagios objects]#/etc/init.d/nagios checkconfig #檢查設定檔是否有誤
[root@nagios objects]#/etc/init.d/nagios reload #重新載入設定檔
Running configuration check...done.
Stopping nagios: done.
Starting nagios: done.
說明:如果nagios reload完畢,監控頁面尚未出現檢測結果,可以手動測試
/usr/local/nagios/libexec/check_nrpe -H192.168.15.21 -c check_mysql_slave
2.2.3 最終