標籤:nagios
1.主動式監控模式
監控用戶端LNMP 網站服務
伺服器端:
[[email protected]]#cd /usr/local/nagios/etc/objects
[[email protected] objects]# vi commands.cfg
#在最下面增加:
# ‘check_weburl‘ command definition
define command{
command_name check_weburl
command_line $USER1$/check_http $ARG1$ -w 10 -c 30
}
儲存退出
[[email protected] objects]#cd /usr/local/nagios/etc/services
建立主動模式監控設定檔webzd.cfg
[[email protected] objects]#vi webzd.cfg
define service {
use generic-service
host_name 1.34-web
service_description blog_ip
check_command check_weburl! -I 10.89.1.34
max_check_attempts 3
normal_check_interval 2
retry_check_interval 1
check_period 24x7
notification_interval 30
notification_period 24x7
notification_options w,u,c,r
contact_groups admins
process_perf_data 1
}
define service {
use generic-service
host_name 1.34-web
service_description blog_url
check_command check_http! -H bolg.etiantian.org
max_check_attempts 3
normal_check_interval 2
retry_check_interval 1
check_period 24x7
notification_interval 30
notification_period 24x7
notification_options w,u,c,r
contact_groups admins
}
define service {
use generic-service
host_name 1.34-web
service_description blog_port_80
check_command check_tcp!80
max_check_attempts 3
normal_check_interval 2
retry_check_interval 1
check_period 24x7
notification_interval 30
notification_period 24x7
notification_options w,u,c,r
contact_groups admins
}
define service {
use generic-service
host_name 1.34-web
service_description ssh_port
check_command check_tcp! 22
max_check_attempts 3
normal_check_interval 2
retry_check_interval 1
check_period 24x7
notification_interval 30
notification_period 24x7
notification_options w,u,c,r
contact_groups admins
}
define service {
use generic-service
host_name 1.34-web
service_description mysql_port
check_command check_tcp!3306
max_check_attempts 3
normal_check_interval 2
retry_check_interval 1
check_period 24x7
notification_interval 30
notification_period 24x7
notification_options w,u,c,r
contact_groups admins
}
define service {
use generic-service
host_name 1.34-web
service_description rsync
check_command check_tcp!873
max_check_attempts 3
normal_check_interval 2
retry_check_interval 1
check_period 24x7
notification_interval 30
notification_period 24x7
notification_options w,u,c,r
contact_groups admins
}
儲存並退出
檢查文法
[[email protected]@nagios objects]# /etc/init.d/nagios checkconfig
沒有錯誤的情況下:
[[email protected]@nagios objects]# /etc/init.d/nagios reload
------------------------------------------------------------------
自訂外掛程式:監控密碼檔案是否改變
用戶端測試:
將/etc/passwd產生md5值
[[email protected] ~]# md5sum /etc/passwd
5e2ebd59c3ebb7bd3c4b09b0674ca746 /etc/passwd
儲存到/etc/alvin.md5 (檔案名稱隨便取,存放的位置任意)
[[email protected] ~]# md5sum /etc/passwd >/etc/alvin.md5
分析md5值是否變化,沒有變化顯示"OK"
[[email protected] ~]# md5sum -c /etc/alvin.md5
/etc/passwd: OK
實戰:
1.在用戶端添加自訂指令碼
cd /usr/local/nagios/libexec
cat check_passwd
#!/bin/bash
char=`md5sum -c /etc/alvin.md5 2>/dev/null|grep "OK"|wc -l`
if [ $char -eq 1 ];
then
echo "passwd is ok"
exit 0
else
echo "passwd is changed"
exit 2
fi
#添加執行的許可權
[[email protected] libexec~]# chmod +x check_passwd
[[email protected] libexec~]# ll check_passwd
-rwxr-xr-x 1 root root 166 Jul 22 21:33 check_passwd
2.在用戶端增加命令,並重啟nrpe服務使之生效
[[email protected] libexec~]#vim /usr/local/nagios/etc/nrpe.cfg
添加check_passwd定義命令
command[check_passwd]=/usr/local/nagios/libexec/check_passwd
[[email protected] libexec~]#pkill nrpe
#重新啟動nrpe
[[email protected] libexec~]#/usr/local/nagios/bin/nrpe -c /usr/local/nagios/etc/nrpe.cfg -d
#查看是否啟動了
[[email protected] libexec~]ps -ef|grep nrpe
nagios 64672 1 0 Dec22 ? 00:00:21 /usr/local/nagios/bin/nrpe -c /usr/local/nagios/etc/nrpe.cfg -d
root 72255 72099 0 11:48 pts/0 00:00:00 grep nrpe
3.在服務端測試
[[email protected] services]# /usr/local/nagios/libexec/check_nrpe -H 10.89.1.34 -c check_passwd
passwd is ok
添加服務指令碼
[[email protected] ~]#cd /usr/local/nagios/etc/objects/
[[email protected] objects]# vi services.cfg
#在後面添加
define service{
use generic-service
host_name 1.34-web-lnmp
service_description check_passwd
check_command check_nrpe!check_passwd
}
檢測文法並重新載入/etc/init.d/nagios checkconfig
沒有錯誤的情況下:
[[email protected] objects]# /etc/init.d/nagios reload
4.改變性測試在用戶端執行添加使用者命令
[[email protected] ~]#useradd jack
服務端執行
[[email protected] services]# /usr/local/nagios/libexec/check_nrpe -H 10.89.1.34 -c check_passwd
passwd is changed
本文出自 “知識改變命運” 部落格,請務必保留此出處http://ahtornado.blog.51cto.com/4826737/1885436
nagios 監控配置介紹(三)