Redhat 5.2 配置nagioslinux
安裝系統組件
安裝apache、gcc
配置apache
安裝nagios組件
安裝nagios
安裝nagios-plugins
安裝nrpe
配置被監控機
配置linux被監控機(客戶端)
配置交換機被監控機(客戶端)
配置windows被監控機(客戶端)
配置郵件監控
ios
安裝組件c++
Apache、gcc glibc glibc-common gd-devel、 openssl、openssl-devel(open安裝未列出)web
net-snmp-libs net-snmp-devel net-snmp net-snmp-utilssql
安裝apache、gccapache
(因爲rpm的依賴關係太煩人,配置yum,舒服多了,具體請見yum安裝)windows
[root@localhost ~]# yum install httpdbash
……服務器
Downloading Packages:網絡
(1/4): apr-util-1.2.7-7.e 100% |=========================| 76 kB 00:00
(2/4): apr-1.2.7-11.i386. 100% |=========================| 123 kB 00:00
(3/4): httpd-2.2.3-11.el5 100% |=========================| 1.1 MB 00:01
(4/4): postgresql-libs-8. 100% |=========================| 196 kB 00:00
warning: rpmts_HdrFromFdno: Header V3 DSA signature: NOKEY, key ID 37017186
Importing GPG key 0x37017186 "Red Hat, Inc. (release key) <security@redhat.com>" from http://10.155.2.75/Server/RPM-GPG-KEY-redhat-release
Is this ok [y/N]: y
Running rpm_check_debug
Running Transaction Test
Finished Transaction Test
Transaction Test Succeeded
Running Transaction
Installing: apr ######################### [1/4]
Installing: postgresql-libs ######################### [2/4]
Installing: apr-util ######################### [3/4]
Installing: httpd ######################### [4/4]
……
[root@localhost ~]# yum install gcc
……
Downloading Packages:
(1/5): libgomp-4.1.2-42.e 100% |=========================| 82 kB 00:00
(2/5): glibc-headers-2.5- 100% |=========================| 610 kB 00:00
(3/5): glibc-devel-2.5-24 100% |=========================| 2.0 MB 00:02
(4/5): gcc-4.1.2-42.el5.i 100% |=========================| 5.2 MB 00:07
(5/5): kernel-headers-2.6 100% |=========================| 843 kB 00:01
Running rpm_check_debug
Running Transaction Test
Finished Transaction Test
Transaction Test Succeeded
Running Transaction
Installing: libgomp ######################### [1/5]
Installing: kernel-headers ######################### [2/5]
Installing: glibc-headers ######################### [3/5]
Installing: glibc-devel ######################### [4/5]
Installing: gcc ######################### [5/5]
Installed: gcc.i386 0:4.1.2-42.el5
Dependency Installed: glibc-devel.i386 0:2.5-24 glibc-headers.i386 0:2.5-24 kernel-headers.i386 0:2.6.18-92.el5 libgomp.i386 0:4.1.2-42.el5
Complete!
[root@localhost ~]# yum install glibc glibc-common gd-devel
……
Running Transaction
Installing: zlib-devel ####################### [ 1/12]
Installing: freetype-devel ####################### [ 2/12]
Installing: fontconfig-devel ####################### [ 3/12]
Installing: libpng-devel ####################### [ 4/12]
Installing: libXau-devel ####################### [ 5/12]
Installing: libjpeg-devel ####################### [ 6/12]
Installing: xorg-x11-proto-devel ####################### [ 7/12]
Installing: libX11-devel ####################### [ 8/12]
Installing: libXpm-devel ####################### [ 9/12]
Installing: libXdmcp-devel ####################### [10/12]
Installing: mesa-libGL-devel ####################### [11/12]
Installing: gd-devel ####################### [12/12]
Installed: gd-devel.i386 0:2.0.33-9.4.el5_1.1
Dependency Installed: fontconfig-devel.i386 0:2.4.1-7.el5 freetype-devel.i386 0:2.2.1-19.el5 libX11-devel.i386 0:1.0.3-9.el5 libXau-devel.i386 0:1.0.1-3.1 libXdmcp-devel.i386 0:1.0.1-2.1 libXpm-devel.i386 0:3.5.5-3 libjpeg-devel.i386 0:6b-37 libpng-devel.i386 2:1.2.10-7.1.el5_0.1 mesa-libGL-devel.i386 0:6.5.1-7.5.el5 xorg-x11-proto-devel.i386 0:7.1-9.fc6 zlib-devel.i386 0:1.2.3-3
Complete!
配置apache
注把apache 加入到nagcmd組,以便在經過web Interface 操做nagios是有足夠的權限;
[root@localhost ~]# useradd nagios && passwd nagios //chinahr123$
Changing password for user nagios.
New UNIX password:
BAD PASSWORD: it is based on a dictionary word
Retype new UNIX password:
Sorry, passwords do not match.
New UNIX password:
Retype new UNIX password:
passwd: all authentication tokens updated successfully.
[root@localhost ~]# groupadd nagcmd
[root@localhost ~]# usermod -G nagcmd nagios
[root@localhost ~]# usermod -G nagcmd apache
安裝nagios組件
安裝nagios
http://cdnetworks-kr-2.dl.sourceforge.net/project/nagios/nagios-3.x/nagios-3.2.1/nagios-3.2.1.tar.gz
[root@localhost src]# tar zxvf nagios-3.2.1.tar.gz
[root@localhost src]# cd nagios-3.2.1
[root@localhost nagios-3.2.1]#./configure --with-command-group=nagcmd --prefix=/usr/local/nagios
[root@localhost nagios-3.2.1]# make all
[root@localhost nagios-3.2.1]# make install
[root@localhost nagios-3.2.1]# make install.init
/usr/bin/install -c -m 755 -d -o root -g root /etc/rc.d/init.d
/usr/bin/install -c -m 755 -o root -g root daemon-init /etc/rc.d/init.d/nagios
[root@localhost nagios-3.2.1]# make install-config
……
*** Config files installed ***
Remember, these are *SAMPLE* config files. You'll need to read
the documentation for more information on how to actually define
services, hosts, etc. to fit your particular needs.
[root@localhost nagios-3.2.1]# make install-commandmode
/usr/bin/install -c -m 775 -o nagios -g nagcmd -d /usr/local/nagios/var/rw
chmod g+s /usr/local/nagios/var/rw
*** External command directory configured ***
驗證安裝在/usr/local/nagios,是否生成目錄bin etc sbin share var.
[root@localhost ~]# cd /usr/local/nagios
[root@localhost nagios]# ls
bin etc sbin share var
安裝nagios-plugins
[root@localhost src]# tar zxvf nagios-plugins-1.4.15.tar.gz
[root@localhost nagios-plugins-1.4.15]#./configure --with-nagios-user=nagios --with-nagios-group=nagios --prefix=/usr/local/nagios
[root@localhost nagios-plugins-1.4.15]# make && make install
驗證是否安裝成功,是否生成以下文件
[root@localhost nagios-plugins-1.4.15]# ls /usr/local/nagios/libexec
check_apt check_disk_smb check_ide_smart check_mrtg check_nwstat check_sensors check_users
check_breeze check_dns check_ifoperstatus check_mrtgtraf check_oracle check_smtp check_wave
check_by_ssh check_dummy check_ifstatus check_nagios check_overcr check_ssh negate
check_clamd check_file_age check_imap check_nntp check_ping check_swap urlize
check_cluster check_flexlm check_ircd check_nt check_pop check_tcp utils.pm
check_dhcp check_ftp check_load check_ntp check_procs check_time utils.sh
check_dig check_http check_log check_ntp_peer check_real check_udp
check_disk check_icmp check_mailq check_ntp_time check_rpc check_ups
配置nagios的WEB接口,也能夠經過以下命令更改用戶密碼,
[root@localhost etc]# /usr/bin/htpasswd -c /usr/local/nagios/etc/htpasswd nagiosadmin
New password:
Re-type new password:
Adding password for user nagiosadmin
[root@localhost etc]# service httpd start
Starting httpd: [ OK ]
編輯httpd.conf,在結尾加上以下內容,保存,啓動apache,service httpd restart
ScriptAlias /nagios/cgi-bin /usr/local/nagios/sbin
<Directory "/usr/local/nagios/sbin">
Options ExecCGI
AllowOverride None
Order allow,deny
Allow from all
AuthName "Nagios Access"
AuthType Basic
AuthUserFile /usr/local/nagios/etc/htpasswd
Require valid-user
</Directory>
Alias /nagios /usr/local/nagios/share
<Directory "/usr/local/nagios/share">
Options None
AllowOverride None
Order allow,deny
Allow from all
AuthName "Nagios Access"
AuthType Basic
AuthUserFile /usr/local/nagios/etc/htpasswd
Require valid-user
</Directory>
設置開機啓動nagios服務
[root@localhost nagios-plugins-1.4.15]# chkconfig --add nagios
[root@localhost nagios-plugins-1.4.15]# chkconfig nagios on
驗證nagios配置是否正常,此命令之後會常用,warning和error爲0,表示正常,後面不正常的討論,這裏能夠啓動nagios服務
[root@localhost nagios-plugins-1.4.15]# /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg
……
Checking misc settings...
Total Warnings: 0
Total Errors: 0
[root@localhost nagios-plugins-1.4.15]# service nagios start
Starting nagios: done.
安裝nrpe
http://sourceforge.net/projects/nagios/files/nrpe-2.x/nrpe-2.8b1/nrpe-2.8b1.tar.gz/download
安裝以前以前必定要安裝gcc、 openssl、openssl-devel(尤爲是linux被監控機,也是客戶端)安裝以後,是用/usr/local/nagios/bin/nrpe -c /usr/local/nagios/etc/nrpe.cfg –d命令啓動nrpe
tar -zxvf nrpe-2.8b1
cd nrpe-2.8b1
[root@localhost nrpe-2.8b1]# ./configure
[root@localhost nrpe-2.8b1]# make all
[root@localhost nrpe-2.8b1]# make install-plugin
[root@localhost nrpe-2.8b1]# make install-daemon
[root@localhost nrpe-2.8b1]# make install-daemon-config
/usr/bin/install -c -m 775 -o nagios -g nagios -d /usr/local/nagios/etc
/usr/bin/install -c -m 644 -o nagios -g nagios sample-config/nrpe.cfg /usr/local/nagios/etc
[root@localhost nrpe-2.8b1]/usr/local/nagios/bin/nrpe -c /usr/local/nagios/etc/nrpe.cfg -d
經過以下命令驗證nrpe是否正常,能夠看到端口5666已經打開
[root@localhost etc]# /usr/local/nagios/libexec/check_nrpe -H localhost
NRPE v2.8b1
[root@localhost etc]#
[root@localhost etc]# netstat -atulnp | grep 'nrpe'
tcp 0 0 0.0.0.0:5666 0.0.0.0:* LISTEN 24823/nrpe
以上服務器端(也是就控制端)的nrpe(用於服務器的自身的監控)已經配置完成,接着服務器的nagios監控配置,配置以下nagios.cfg,去掉以下的「#」,每條記錄都對應目錄的相應的配置文件,下表中有說明,host.cfg和service.cfg是不存在的,能夠本身創建,這些cfg文件都是能夠本身創建的,只要在nagios.cfg添加相應的記錄就行。如今咱們只是作服務器自身的監控,只是用的commands.cfg、localhost.cfg,不用修改什麼。
[root@localhost objects]# vi /usr/local/nagios/etc/nagios.cfg
cfg_file=/usr/local/nagios/etc/objects/commands.cfg ;
cfg_file=/usr/local/nagios/etc/objects/contacts.cfg
cfg_file=/usr/local/nagios/etc/objects/timeperiods.cfg
cfg_file=/usr/local/nagios/etc/objects/templates.cfg
cfg_file=/usr/local/nagios/etc/objects/localhost.cfg
cfg_file=/usr/local/nagios/etc/objects/windows.cfg
cfg_file=/usr/local/nagios/etc/objects/switch.cfg
監控命令
command
nagios發出的哪一個指令來執行某個監控,這也是本身定義的
聯繫人
contact
設置報警聯繫人,通常固然是系統管理員了
監控時間段
timeperiod
7X24小時不間斷仍是週一至週五,或是自定義的其餘時間段
監控交換機
switch
例如主機是否存活,80端口是否開,磁盤使用狀況或者自定義的服務等
被監控主機
localhost
監控機本身服務器
被監控主機
host
所須要監控的服務器,固然能夠是監控機本身
被監控的服務
service
例如主機是否存活,80端口是否開,磁盤使用狀況或者自定義的服務等
保存nagios.cfg後,用service httpd restart重啓nagios服務,若是失敗,用/usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg驗證,會提示出問題所在,關於問題解決在後面再將,這裏只是服務器自身監控,應該不會有問題。
在IE下http://IP/nagios,輸入nagiosadmin和密碼(圖1和圖2)
配置被監控機
配置linux被監控機(客戶端)
須要先安裝gcc、openssl、openssl-devel。
先添加一個用戶
[root@localhost ~]# useradd nagios
[root@localhost ~]# passwd nagios //123456
Changing password for user nagios.
New UNIX password:
BAD PASSWORD: it is too simplistic/systematic
Retype new UNIX password:
passwd: all authentication tokens updated successfully.
安裝nagios-plugins-1.4.15.tar.gz
[root@localhost ~]# tar -zxvf nagios-plugins-1.4.15.tar.gz
[root@localhost ~]# cd nagios-plugins-1.4.15
[root@localhost nagios-plugins-1.4.15]# ./configure --prefile=/usr/local/nagios
[root@localhost nagios-plugins-1.4.15]# make
[root@localhost nagios-plugins-1.4.15]# make install
[root@localhost nagios-plugins-1.4.15]# chown nagios.nagios /usr/local/nagios
[root@localhost nagios-plugins-1.4.15]# chown -R nagios.nagios /usr/local/nagios/libexec
安裝nrpe
[root@localhost ~]# tar -zxvf nrpe-2.8b1
[root@localhost ~]# cd nrpe-2.8b1
[root@localhost nrpe-2.8b1]# ./configure
[root@localhost nrpe-2.8b1]# make all
[root@localhost nrpe-2.8b1]# make install-plugin
[root@localhost nrpe-2.8b1]# make install-daemon
[root@localhost nrpe-2.8b1]# make install-daemon-config
編輯nrpe.cfg
[root@localhost ~]# vi /usr/local/nagios/etc/nrpe.cfg
查找以下加上nagios服務器ip地址
allowed_hosts=127.0.0.1,10.155.2.65
保存後,用以下命令啓動nrpe和添加到開機啓動中
/usr/local/nagios/bin/nrpe -c /usr/local/nagios/etc/nrpe.cfg –d
echo '/usr/local/nagios/bin/nrpe -c /usr/local/nagios/etc/nrpe.cfg -d &> /dev/null' >> /etc/rc.local
驗證
[root@localhost etc]# /usr/local/nagios/libexec/check_nrpe -H localhost
NRPE v2.8b1
[root@localhost etc]# netstat -atulnp | grep 'nrpe'
tcp 0 0 0.0.0.0:5666 0.0.0.0:* LISTEN 24823/nrpe
若是不正常見文章最後的問題和解決(1)
這裏客戶端的配置已經完成,已經能夠到nagios服務器配置command.cfg監控,可是這裏介紹另外一種方法在編輯nrpe.cfg配置命令,nagios服務器會調用客戶端的nrpe命令
vi /usr/local/nagios/etc/nrpe.cfg
command[check_users]=/usr/local/nagios/libexec/check_users -w 5 -c 10
command[check_load]=/usr/local/nagios/libexec/check_load -w 15,10,5 -c 30,25,20
command[check_zombie_procs]=/usr/local/nagios/libexec/check_procs -w 5 -c 10 -s Z
command[check_total_procs]=/usr/local/nagios/libexec/check_procs -w 150 -c 200
command[check_swap]=/usr/local/nagios/libexec/check_swap -w 20% -c 10%
下面這條是本身添加
command[check_ping81]=/usr/local/nagios/libexec/check_ping -H 10.155.0.1 -w 100.0,20% -c 500.0,60%#
command[check_hda1]=/usr/local/nagios/libexec/check_disk -w 20 -c 10 -p /dev/hda1
#command[命令名稱]=命令定義
具體使用見幫助
[root@localhost nagios]# ls
bin etc include libexec share
[root@localhost nagios]# pwd
/usr/local/nagios
[root@localhost nagios]# libexec/check_ping -h
check_ping v1.4.15 (nagios-plugins 1.4.15)
Copyright (c) 1999 Ethan Galstad <nagios@nagios.org>
Copyright (c) 2000-2007 Nagios Plugin Development Team
<nagiosplug-devel@lists.sourceforge.net>
Use ping to check connection statistics for a remote host.
Usage:
check_ping -H <host_address> -w <wrta>,<wpl>% -c <crta>,<cpl>%
[-p packets] [-t timeout] [-4|-6]
Options:
-h, --help
Print detailed help screen
-V, --version
Print version information
-4, --use-ipv4
Use IPv4 connection
-6, --use-ipv6
Use IPv6 connection
-H, --hostname=HOST
host to ping
-w, --warning=THRESHOLD
warning threshold pair
-c, --critical=THRESHOLD
critical threshold pair
-p, --packets=INTEGER
number of ICMP ECHO packets to send (Default: 5)
-L, --link
show HTML in the plugin output (obsoleted by urlize)
-t, --timeout=INTEGER
Seconds before connection times out (default: 10)
配置nrpe.cfg後,必須重啓nrpe。重啓方法(殺死進程,在重啓),不然更改不會生效
[root@localhost ~]# ps aux|grep nrpe
nagios 3327 0.0 0.0 4880 924 ? Ss Sep02 0:03 /usr/local/nagios/bin/nrpe -c /usr/local/nagios/etc/nrpe.cfg -d
root 22293 0.0 0.0 3908 648 pts/0 R+ 11:07 0:00 grep nrpe
[root@localhost ~]# /usr/local/nagios/bin/nrpe -c /usr/local/nagios/etc/nrpe.cfg -d
服務器端
測試與客戶端鏈接,以下表示正常
[root@localhost nrpe-2.8b1]# /usr/local/nagios/libexec/check_nrpe -H 10.155.2.81
NRPE v2.8b1
下面表示不正常,見問題與解決(2)
[root@localhost nrpe-2.8b1]# /usr/local/nagios/libexec/check_nrpe -H 10.155.2.81
Connection refused by host
配置nagios.cfg,增長一條記錄
[root@localhost ~]# vi /usr/local/nagios/etc/nagios.cfg
cfg_file=/usr/local/nagios/etc/objects/mylinux.cfg
cfg_file=/usr/local/nagios/etc/objects/commands.cfg ;此前面已經設置過
配置nagios.cfg,增長一條記錄
vi /usr/local/nagios/etc/objects/commands.cfg
#在後面增長追加以下內容
#check nrpe
define command{
command_name check_nrpe
command_line $USER1$/check_nrpe -H $HOSTADDRESS$ -c $ARG1$
}
mylinux.cfg在目錄中沒有,須要本身添加
[root@localhost ~]# touch /usr/local/nagios/etc/objects/mylinux.cfg
#---------------------------------------------此段定義主機--------------------------------------------------------
define host{
use linux-server
host_name 10.155.2.81-cacti
alias mylinux
address 10.155.2.81
}
#--------------------------------下面定義服務器,也就是監控項------------------------------------------
define service{
use generic-service
host_name 10.155.2.81-cacti
service_description Swap Usage
check_command check_nrpe!check_swap
}
define service{
use generic-service
host_name 10.155.2.81-cacti
service_description Current Load
check_command check_nrpe!check_load
}
define service{
use generic-service
host_name 10.155.2.81-cacti
service_description Partition Usage
check_command check_nrpe!check_hda1
}
define service{
use generic-service
host_name 10.155.2.81-cacti
service_description Current Users
check_command check_nrpe!check_users
}
define service{
use generic-service
host_name 10.155.2.81-cacti
service_description Total Processes
check_command check_nrpe!check_total_procs
}
define service{
use generic-service
host_name 10.155.2.81-cacti
service_description PING
check_command check_nrpe!check_ping81
}
重啓nagios,ie瀏覽(圖3)
配置交換機被監控機(客戶端)
這裏的switch.cfg是交換機的一個監控模板,我保留這個cfg,複製爲switch31.cfg編輯
[root@localhost objects]# vi /usr/local/nagios/etc/nagios.cfg
# Definitions for monitoring a router/switch
#cfg_file=/usr/local/nagios/etc/objects/switch.cfg
cfg_file=/usr/local/nagios/etc/objects/switch31.cfg
幾乎不用改,把host name和address改了,最後一個mrtg我沒用網絡裏沒有註釋掉了
[root@localhost objects]# vi switch31.cfg
define host{
use generic-switch ; Inherit default values from a template
host_name g13a-dell5424-31 ; The name we're giving to this switch
alias Linksys SRW224P Switch ; A longer name associated with the switch
address 10.155.0.31 ; IP address of the switch
hostgroups switches ; Host groups this switch is associated with
}
define hostgroup{
hostgroup_name switches ; The name of the hostgroup
alias Network Switches ; Long name of the group
}
define service{
use generic-service ; Inherit values from a template
host_name g13a-dell5424-31 ; The name of the host the service is associated with
service_description PING ; The service description
check_command check_ping!200.0,20%!600.0,60% ; The command used to monitor the service
normal_check_interval 5 ; Check the service every 5 minutes under normal conditions
retry_check_interval 1 ; Re-check the service every minute until its final/hard state is determined
}
# Monitor uptime via SNMP
define service{
use generic-service ; Inherit values from a template
host_name g13a-dell5424-31
service_description Uptime
check_command check_snmp!-C chrswitch -o sysUpTime.0
}
# Monitor Port 1 status via SNMP
define service{
use generic-service ; Inherit values from a template
host_name g13a-dell5424-31
service_description Port 1 Link Status
check_command check_snmp!-C chrswitch -o ifOperStatus.1 -r 1 -m RFC1213-MIB
}
# Monitor bandwidth via MRTG logs
#define service{
# use generic-service ; Inherit values from a template
# host_name linksys-srw224p
# service_description Port 1 Bandwidth Usage
# check_command check_local_mrtgtraf!/var/lib/mrtg/192.168.1.253_1.log!AVG!1000000,1000000!5000000,5000000!10
# }
Switch就完成,紅色見問題3(圖4)
配置windows被監控機(客戶端)
Windows監控須要在windows安裝一個插件nsclient++,http://nsclient.org/nscp/downloads
下載後解壓到c盤
C:\NSClient>nsclient++ /install
Service NSClientpp installed...
l NSClient++.cpp(227) Service installed!
用記事本編輯nsc.ini,去掉註釋符號」;」除了CheckWMI.dll和RemoteConfiguration.dll
[modules]
FileLogger.dll
CheckSystem.dll
CheckDisk.dll
NSClientListener.dll
NRPEListener.dll
SysTray.dll
CheckEventLog.dll
CheckHelpers.dll
;CheckWMI.dll
CheckExternalScripts.dll
NSCAAgent.dll
LUAScript.dll
;RemoteConfiguration.dll
NRPEClient.dll
CheckTaskSched.dll
[Settings]
allowed_hosts=10.155.2.65/32
[NSClient]
port=12489
C:\NSClient>NSClient++ -start
Starting NSClientpp
C:\NSClient>netstat -an | more
Active Connections
Proto Local Address Foreign Address State
TCP 0.0.0.0:5666 0.0.0.0:0 LISTENING
TCP 0.0.0.0:12489 0.0.0.0:0 LISTENING
服務器
[root@localhost ~]# vi /usr/local/nagios/etc/nagios.cfg
# Definitions for monitoring a Windows machine
cfg_file=/usr/local/nagios/etc/objects/windows.cfg
[root@localhost ~]# vi /usr/local/nagios/etc/objects/windows.cfg
windows.cfg沒有什麼可改的,只是把hostname和ip改了就好了(圖5)
郵件監控
郵件監控能夠配置sendmail,我對sendmail一竅不通,這裏仍是用mail命令完成。首先是編輯nagios.cfg,之前已經設置了,這裏看看就好了
[root@localhost objects]# vi /usr/local/nagios/etc/nagios.cfg
cfg_file=/usr/local/nagios/etc/objects/contacts.cfg
這裏要注意的是若是在這設置間隔和期限等是在整個nagios生效的,全部的客戶端都是按照這個配置,若是想單獨設置在各個cfg中單獨配置,一會會講。整個cfg內容沒什麼說的了,contact_name和email,還有就是contactgroup_name在全部的地方都是設置這個名字,不要寫錯,member能夠設置多個用」,」隔開,
[root@localhost objects]# vi contacts.cfg
define contact{
contact_name user1
alias Nagios Admin
service_notification_period 24x7
host_notification_period 24x7
service_notification_options w,u,c,r
host_notification_options d,r
service_notification_commands notify-by-email
host_notification_commands host-notify-by-email
email xxxx@163.com
pager 13800138000
}
define contactgroup{
contactgroup_name admins
alias Nagios Administrators
members user1
}
notify-by-email和host-notify-by-email在command.cfg中定義了(見問題5)
這個就是在服務中單獨設置,就很少講了
define service{
use generic-service ; Name of service template to use
host_name test_nrpe
service_description apache
is_volatile 0 #相似聲音警告功能關閉
check_period 24x7 #監控期限爲24X7
max_check_attempts 1 #最大重試次數
normal_check_interval 1 #標準檢測時間間隔 1分鐘
retry_check_interval 1 #重試時間間隔
contact_groups admins #聯繫組
notification_options w,u,c,r # w,u,c,r 發生這四種狀況時,進行通告。
notification_interval 960 # 通告間隔
notification_period 24x7 #通告過時時間
check_command check_http!100.0,20%!500.0,60%
}
參數說明
服務出了情況通知的時間段,這個時間段是前面 timeperiods.cfg 裏面定義的。
service_notification_period 24x7
主機出現情況時通知的時間段,這個時間段是前面 timeperiods.cfg 裏面定義的。
host_notification_period 24x7
當服務出現 w— 報警 (warning),u— 未知 (unkown),c— 嚴重 (critical),r— 從異常恢復到正常,在這四種狀況下通知聯繫人
service_notification_options w,u,c,r
當主機出現 d— 當機 (down),u— 返回不可達 (unreachable),r— 從異常狀況恢復正常 , 在這 3 種狀況下通知聯繫人
host_notification_options d,u,r
服務出問題通知採用的命令 notify-service-by-email , 這個命令是在 commands.cfg 中定義的 , 做用是給聯繫人發郵件 . 在 nagios2.x 的版本上能夠不同,能夠本身到 commands.cfg 裏看一下;在這裏也能夠設置發送短信的方式通知聯繫人,前提是你要配置有發送知道的腳本,還要到 commands.cfg 裏面添加發送腳本所用到的命令;
service_notification_commands notify-service-by-email
同上 , 主機出問題時採用的也是發郵件的方式通知聯繫人
host_notification_commands notify-host-by-email
指定 聯繫的人 email 地址
email yaozhan189@163.com
聯繫人的手機 , 前提是要支持短信通知,這裏沒有啓用經過手機短信的方式發送警報 pager 13800138000
問題和解決
一、
[root@localhost nrpe-2.8b1]# /usr/local/nagios/libexec/check_nrpe -H localhost
Connection refused by host
若是在本機上都出下以下結果,說明nrpe沒有啓動,用啓動命令啓動
二、
[root@localhost nrpe-2.8b1]# /usr/local/nagios/libexec/check_nrpe -H 10.155.2.81
Connection refused by host
多是客戶端nrpe.cfg,沒有加服務器ip地址allowed_hosts=127.0.0.1,10.155.2.6
多是客戶端的防火牆
三、是由於nagios服務器中沒有check_snmp命令,有安裝nagios以前沒有安裝net-snmp和net-snmp-utils組件。網上有人提示安裝組件後在從新安裝nagios-plugins-1.4.15,我沒有成功。(圖6)
[root@localhost nagios]# libexec/check_snmp -h
-bash: libexec/check_snmp: No such file or directory
4網上有文章提示安裝nagios以前,系統須要安裝以下。
yum -y install gcc gcc-c++ autoconf libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libxml2 libxml2-devel zlib zlib-devel glibc glibc-devel glib2 glib2-devel bzip2 bzip2-devel ncurses ncurses-devel curl curl-devel e2fsprogs e2fsprogs-devel krb5 krb5-devel libidn libidn-devel openssl openssl-devel openldap openldap-devel nss_ldap openldap-clients openldap-servers perl gd gd-devel jpeg jpeg-devel libpng libpng-devel Net-snmp zlib freetype libart_lgpl cairo-devel pango-devel lrzsz*
本文來自CSDN博客,轉載請標明出處:http://blog.csdn.net/wonitazansa1/archive/2010/09/06/5866086.aspx