1.主動監控模式

創新互聯公司專注于成都網站設計、網站建設、網頁設計、網站制作、網站開發。公司秉持“客戶至上,用心服務”的宗旨,從客戶的利益和觀點出發,讓客戶在網絡營銷中找到自己的駐足之地。尊重和關懷每一位客戶,用嚴謹的態度對待客戶,用專業的服務創造價值,成為客戶值得信賴的朋友,為客戶解除后顧之憂。
監控客戶端LNMP 網站服務
服務器端:
[root@nagios]#cd /usr/local/nagios/etc/objects
[root@nagios objects]# vi commands.cfg
#在最下面增加:
# 'check_weburl' command definition
define command{
command_name check_weburl
command_line $USER1$/check_http $ARG1$ -w 10 -c 30
}
保存退出
[root@nagios objects]#cd /usr/local/nagios/etc/services
創建主動模式監控配置文件webzd.cfg
[root@nagios 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
}
保存并退出
檢查語法
[root@@nagios objects]# /etc/init.d/nagios checkconfig
沒有錯誤的情況下:
[root@@nagios objects]# /etc/init.d/nagios reload
------------------------------------------------------------------
自定義插件:監控密碼文件是否改變
客戶端測試:
將/etc/passwd生成md5值
[root@weblnmp ~]# md5sum /etc/passwd
5e2ebd59c3ebb7bd3c4b09b0674ca746 /etc/passwd
保存到/etc/alvin.md5 (文件名隨便取,存放的位置任意)
[root@weblnmp ~]# md5sum /etc/passwd >/etc/alvin.md5
分析md5值是否變化,沒有變化顯示"OK"
[root@weblnmp ~]# 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
#添加執行的權限
[root@weblnmp libexec~]# chmod +x check_passwd
[root@weblnmp libexec~]# ll check_passwd
-rwxr-xr-x 1 root root 166 Jul 22 21:33 check_passwd
2.在客戶端增加命令,并重啟nrpe服務使之生效
[root@weblnmp libexec~]#vim /usr/local/nagios/etc/nrpe.cfg
添加check_passwd定義命令
command[check_passwd]=/usr/local/nagios/libexec/check_passwd
[root@weblnmp libexec~]#pkill nrpe
#重新啟動nrpe
[root@weblnmp libexec~]#/usr/local/nagios/bin/nrpe -c /usr/local/nagios/etc/nrpe.cfg -d
#查看是否啟動了
[root@weblnmp 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.在服務端測試
[root@nagios services]# /usr/local/nagios/libexec/check_nrpe -H 10.89.1.34 -c check_passwd
passwd is ok
添加服務腳本
[root@nagios ~]#cd /usr/local/nagios/etc/objects/
[root@nagios 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
沒有錯誤的情況下:
[root@nagios objects]# /etc/init.d/nagios reload
4.改變性測試在客戶端執行添加用戶命令
[root@weblnmp ~]#useradd jack
服務端執行
[root@nagios services]# /usr/local/nagios/libexec/check_nrpe -H 10.89.1.34 -c check_passwd
passwd is changed
                名稱欄目:nagios監控配置介紹(三)
                
                文章出自:http://www.yijiale78.com/article12/pjddgc.html
            
成都網站建設公司_創新互聯,為您提供網站營銷、建站公司、ChatGPT、企業建站、營銷型網站建設、Google
聲明:本網站發布的內容(圖片、視頻和文字)以用戶投稿、用戶轉載內容為主,如果涉及侵權請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網站立場,如需處理請聯系客服。電話:028-86922220;郵箱:631063699@qq.com。內容未經允許不得轉載,或轉載時需注明來源: 創新互聯
