一、nagios在服務端的安裝
# vim nagios-install
#!/bin/bash
#### nagios客戶端安裝請注釋了install nagios這段###
##install nagios
tar zxvf nagios-3.0.6.tar.gz cd nagios-3.0.6 ./configure --prefix=/usr/local/nagios --with-nagios-user=nagios --with-nagios-group=nagios
make all
make install
make install-init
make install-config
make install-commandmode
make install-webconf
cd ..
##install nagios-plugins
tar zxvf nagios-plugins-1.4.13.tar.gz cd nagios-plugins-1.4.13 ./configure --prefix=/usr/local/nagios
make
make install
cd ..
##install nrpe
tar zxvf nrpe-2.12.tar.gz cd nrpe-2.12 ./configure --enable-ssl --enable-command-args
make all
mkdir -p /usr/local/nagios/etc
mkdir -p /usr/local/nagios/bin
cp sample-config/nrpe.cfg /usr/local/nagios/etc/
cp src/nrpe /usr/local/nagios/bin/
sed -i 's/127.0.0.1/127.0.0.1,192.168.1.253/' /usr/local/nagios/etc/nrpe.cfg sed -i 's/usr\/local/nagios/g' /usr/local/nagios/etc/nrpe.cfg
二、啟動nrpe
# /usr/local/nagios/bin/nrpe -c /usr/local/nagios/etc/nrpe.cfg -d如需重啟nrpe,先killall -9 nrpe再執行啟動
三、配置nagios
Nagios安裝成功後,在/usr/local/nagios下有幾個目錄,分別是:
bin etc libexec sbin share var
1、在/usr/local/nagios/etc 下建立一個linux的目錄,並建立一個hosts.cfg文件。
這個文件裡面的內容,是分三大塊:(1)、定義主機,即host (2)、定義監控組,即 hostgroup (3)、定義監控主機的服務,即server
例:
# Define webgroup host for the testers machine ##定義主機
define host{
host_name web01
alias web01.com address 192.168.1.10
check_command check-host-alive
max_check_attempts 10
check_period 24x7
notification_interval 20
notification_period 24x7
notification_options d,r
 
; contact_groups admins
name web01
}
define host{
host_name web02
alias web02.com address 192.168.1.20
check_command check-host-alive
max_check_attempts 10
check_period 24x7
notification_interval 20
notification_period 24x7
notification_options d,r
contact_groups admins
name web02
}
define host{
host_name web03
alias web03.com address 192.168.1.20
check_command check-host-alive
max_check_attempts 10
check_period 24x7
notification_interval 20
notification_period 24x7
notification_options d,r
contact_groups admins
name web02
}
##----------------------------------------------------------------------------------------##
### Define all hostgroup for the whole machine ##定義監控組
# Define web group
define hostgroup{
hostgroup_name Web01 Server
alias webserver
members web01,web02 #監控多個機器用逗號隔開
define hostgroup{
hostgroup_name Web02 Server
alias webserver
members web03 #監控多個機器用逗號隔開
##----------------------------------------------------------------------------------------##
#########定義監控主機的服務###########
define service{
host_name web01,web02,web03
&n
bsp; service_description check-procs
is_volatile 0
check_period 24x7
max_check_attempts 1
normal_check_interval 1
retry_check_interval 1
notification_options w,u,c,r
notification_interval 1
notification_period 24x7
check_command check_nrpe!check_total_procs
contact_groups admins #聯系人組
notifications_enabled 1 #此處設定為0,則不報警
}
define service{
host_name web01,web02,web03
service_description check-swap
is_volatile 0
check_period 24x7
max_check_attempts 1
normal_check_interval 1
retry_check_interval 1
notification_options w,u,c,r
notification_interval 1
notification_period 24x7
check_command check_nrpe!check_swap
contact_groups admins
notifications_enabled 1
}
(4)、配置nagios.cfg文件
# cd /usr/local/nagios/etc
# vim nagios.cfg找到cfg_file=/usr/local/nagios/etc/objects/localhost.cfg 這行,並把它注釋
添加cfg_dir=/usr/local/nagios/etc/linux
(5)、配置commands.cfg命令配置文件
# cd /usr/local/nagios/etc/objects
# vim commands.cfg,在文件最後添加
define command {
command_name service-notify-by-fei
command_line /usr/local/fetion/fetion --mobile=1381137*** --pwd=***** --to=$CONTACTPAGER$ --msg-utf8="$HOSTNAME$ $SERVICEDESC$ is $SERVICESTATE$ on $TIME$ resu
lt is $SERVICEOUTPUT$" $CONTACTPAGER$
}
define command {
command_name host-notify-by-fei
command_line &nbs
p; /usr/local/fetion/fetion --mobile=1381137**** --pwd=**** --to=$CONTACTPAGER$ --msg-utf8="Host $HOSTSTATE$ alert for $HOSTNAME$! on '$LO
NGDATETIME