溫馨提示×

溫馨提示×

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

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

nagios安裝與使用

發(fā)布時(shí)間:2020-05-21 06:48:30 來源:網(wǎng)絡(luò) 閱讀:1062 作者:wsw26 欄目:移動開發(fā)

Nagios

支持短信,郵件通知

Nagios官網(wǎng) http://www.nagios.org
1. Nagios
安裝 - 服務(wù)端(192.168.0.11
Centos6
默認(rèn)的yum源里沒有nagios相關(guān)的rpm包,但是我們可以安裝一個(gè)epel的擴(kuò)展源: 
yum install -y epel-release
然后安裝nagios相關(guān)的包
yum install -y httpd nagios nagios-pluginsnagios-plugins-all nrpe nagios-plugins-nrpe
設(shè)置登錄nagios后臺的用戶和密碼:htpasswd -c /etc/nagios/passwd nagiosadmin
nagios -v /etc/nagios/nagios.cfg
檢測配置文件
啟動服務(wù):service httpd start; servicenagios start
瀏覽器訪問:http://ip/nagios

nagios安裝與使用

vim /etc/nagios/nagios.cfg  #暫時(shí)先不管

2. Nagios
安裝 - 客戶端(192.168.0.12
在客戶端機(jī)器上
yum install -y epel-release
yum install -y nagios-plugins nagios-plugins-allnrpe nagios-plugins-nrpe
 
vim /etc/nagios/nrpe.cfg  
找到“allowed_hosts=127.0.0.1” 改為“allowed_hosts=127.0.0.1,192.168.0.11”   #服務(wù)器ip

找到” dont_blame_nrpe=0” 改為  “dont_blame_nrpe=1” 
啟動客戶端 /etc/init.d/nrpe start

3.
監(jiān)控中心(192.168.0.11)添加被監(jiān)控主機(jī)(192.168.0.12
vim /etc/nagios/conf.d/192.168.0.12.cfg                 
define host{
        use                   linux-server            
       host_name          192.168.0.12
       alias                      0.12
       address                192.168.0.12
        }

define service{
        use                   generic-service
       host_name              192.168.0.12               
       service_description     check_ping
       check_command          check_ping!100.0,20%!200.0,50%      #0
ok,20是警告,50是危險(xiǎn)
        max_check_attempts5                    #
單位是秒數(shù)
       normal_check_interval 1
}

define service{
        use                   generic-service
       host_name              192.168.0.12
       service_description     check_ssh
       check_command          check_ssh
       max_check_attempts      5   
;當(dāng)nagios檢測到問題時(shí),一共嘗試檢測5次都有問題才會告警,如果該數(shù)值為1,那么檢測到問題立即告警
       normal_check_interval 1   
;重新檢測的時(shí)間間隔,單位是分鐘,默認(rèn)是3分鐘
       notification_interval          60
;在服務(wù)出現(xiàn)異常后,故障一直沒有解決,nagios再次對使用者發(fā)出通知的時(shí)間。單位是分鐘。如果你認(rèn)為,所有的事件只需要一次通知就夠了,可以把這里的選項(xiàng)設(shè)為0。 
}

define service{
        use                   generic-service
       host_name              192.168.0.12
       service_description     check_http
       check_command          check_http
        max_check_attempts     5
       normal_check_interval 1

}
以上普通服務(wù)不依賴于客戶端nrpe服務(wù),我們可以想象,我們在自己電腦上可以使用ping或者telnet探測遠(yuǎn)程任何一臺機(jī)器是否存活、是否開啟某個(gè)端口或服務(wù)。而當(dāng)我們想要檢測客戶端上的某個(gè)具體特殊服務(wù)的情況時(shí),就需要借助于nrpe了,比如想知道客戶端機(jī)器的負(fù)責(zé)或磁盤使用情況。

nagios安裝與使用紅色圈住的是因?yàn)?/span>80端口沒有啟用,yum安裝nginx才會顯示200http也會是403

nagios安裝與使用4.  繼續(xù)添加服務(wù)
服務(wù)端vim/etc/nagios/objects/commands.cfg
增加:define command{
       command_name   
check_nrpe    #去對方獲得服務(wù)狀態(tài),可自定義
       command_line    $USER1$/check_nrpe -H $HOSTADDRESS$-c $ARG1$
        }
繼續(xù)編輯 vim/etc/nagios/conf.d/192.168.0.12.cfg      
增加如下內(nèi)容:define service{
        use    generic-service
       host_name       192.168.0.12
       service_description     check_load
       check_command          check_nrpe!check_load
       max_check_attempts 5
       normal_check_interval 1
}
define service{
        use    generic-service
       host_name       192.168.0.12
       service_description     check_disk_hda1
       check_command          check_nrpe!check_hda1
       max_check_attempts 5
       normal_check_interval 1
}

define service{
        use    generic-service
       host_name       192.168.0.12
       service_description     check_disk_hda2
       check_command          check_nrpe!check_hda2    #
這個(gè)不要寫錯(cuò),是對應(yīng)客戶端的
       max_check_attempts 5
       normal_check_interval 1
}

說明:  check_nrpe!check_load:這里的check_nrpe就是在commands.cfg剛剛定義的,check_load是遠(yuǎn)程主機(jī)上的一個(gè)檢測腳本
在客戶端上vim/etc/nagios/nrpe.cfg 搜索check_load,這行就是在服務(wù)端上要執(zhí)行的腳本了,我們可以手動執(zhí)行這個(gè)腳本
check_hda1更改一下:/dev/hda1 改為 /dev/sda1
再加一行command[check_hda2]=/usr/lib/nagios/plugins/check_disk-w 20% -c 10% -p /dev/sda2  # w = warnning 
c = critial

nagios安裝與使用

Crital不能比warning的值大

機(jī)制:首先在服務(wù)端定義check_nrpe命令,再通過check_nrpe后面跟的command(客戶端的nrpe.cfg里)

客戶端上重啟一下nrpe服務(wù): service nrpe restart
服務(wù)端也重啟一下nagios服務(wù): service nagios restart

5.   
配置告警
vim /etc/nagios/objects/contacts.cfg //
增加:

define contact{
        contact_name              123                  

       use                           generic-contact
        alias                         aming
        email             280472479@qq.com
        }


define contact{
        contact_name              456
        use                           generic-contact
        alias                          aaa
        email             wsw26@139.com
        }


define contactgroup{                         #定義聯(lián)系組
        contactgroup_name          common
        alias                                common
        members                        123,456
        }

然后在要需要告警的服務(wù)里面加上contactgroup

define service{
        use    generic-service
       host_name       192.168.0.12
       service_description     check_load
       check_command          check_nrpe!check_load
       max_check_attempts 5
       normal_check_interval 1
        
contact_groups       common                  #監(jiān)控哪個(gè)發(fā)郵件
       notifications_enabled  1   
;是否開啟提醒功能。1為開啟,0為禁用。一般,這個(gè)選項(xiàng)會在主配置文件(nagios.cfg)中定義,效果相同。
        notification_period  24x7   
;發(fā)送提醒的時(shí)間段。非常重要的主機(jī)(服務(wù))我定義為7×24,一般的主機(jī)(服務(wù))就定義為上班時(shí)間。如果不在定義的時(shí)間段內(nèi),無論什么問題發(fā)生,都不會發(fā)送提醒。       
       notification_options:w,u,c,r   
;這個(gè)是service的狀態(tài)。wwaning, uunknown, ccritical, rrecover(恢復(fù)了),類似的還有一個(gè)  host對應(yīng)的狀態(tài):d,u,r   d = 狀態(tài)為DOWN, u = 狀態(tài)為UNREACHABLE , r = 狀態(tài)恢復(fù)為OK,需要加入到host的定義配置里。
}


6.   
配置圖形顯示 pnp4nagios
1)安裝
yum install pnp4nagios rrdtool
 
2)配置主配置文件
vim /etc/nagios/nagios.cfg  //
修改如下配置

1.  process_performance_data=1    

2.  host_perfdata_command=process-host-perfdata

3.  service_perfdata_command=process-service-perfdata 

4.  enable_environment_macros=1    

3)修改commands.cfg
vim/etc/nagios/objects/commands.cfg  //
注釋掉原有對process-host-perfdataprocess-service-perfdata,重新定義

1.  define command {  

2.        command_name    process-service-perfdata  

3.        command_line    /usr/bin/perl/usr/libexec/pnp4nagios/process_perfdata.pl  

4.  }  

5.    

6.  define command {  

7.        command_name    process-host-perfdata  

8.        command_line    /usr/bin/perl/usr/libexec/pnp4nagios/process_perfdata.pl -d HOSTPERFDATA  

9.  }  

4)修改配置文件templates.cfg
vim /etc/nagios/objects/templates.cfg definehost {
        name      hosts-pnp
       register   0
        action_url/pnp4nagios/index.php/graph?host=$HOSTNAME$&srv=_HOST_
       process_perf_data              1
}
define service {
        name      srv-pnp
       register   0
        action_url/pnp4nagios/index.php/graph?host=$HOSTNAME$&srv=$SERVICEDESC$
       process_perf_data              1
}
5)修改hostservice配置
vim /etc/nagios/conf.d/192.168.0.12.cfg
 
“define host{
        use                   linux-server”
 
改為:
define host{
        use                   linux-server,hosts-pnp
修改對應(yīng)的service,比如

define service{
        use    generic-service
       host_name       192.168.0.12
       service_description     check_disk_hda1
       check_command          check_nrpe!check_hda1
       max_check_attempts 5
       normal_check_interval 1
}
改為:
define service{
        use    generic-service,srv-pnp
       host_name       192.168.0.12
       service_description     check_disk_hda1
       check_command          check_nrpe!check_hda1
       max_check_attempts 5
       normal_check_interval 1
}
6重啟和啟動各個(gè)服務(wù):
service nagios restart
service httpd restart
service npcd start
(7)
訪問測試
兩種訪問方法:
ip/nagios/
ip/pnp4nagios/


向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