NAGIOS服務端安裝
一、 主軟件包:
1. nagios-3.0.x.tar.gz 主程序
2. nagios-plugins-1.4.x.tar.gz 插件
3. nrpe_2.8.x.tar.gz 外部構件
4. pnp -0.4.X 圖形化工具
二、基本安裝:
軟件包准備:
服務端安裝:
rpm -q gcc glibc glibc-common gd gd-devel xinetd openssl-devel httpd
安裝步驟:
2.1 建立賬號:
useradd nagios
passwd nagios
usermod -G nagios nagios
usermod -G nagios apache
2.2 安裝nagios-3.0.x.tar.gz
./configure (不用跟參數,默認安裝在/usr/local/nagios)
配置完畢按照提示安裝
make all
====================
make install
====================
make install-init
====================
make install-config
====================
make install-commandmode
====================
make install-webconf #針對rpm版apache,source包apache配置見下 ====================
設置收信人地址
vi /usr/local/nagios/etc/objects/contacts.cfg
更改email地址nagiosadmin的聯系人定義信息中的EMail信息為你的EMail信息以接收報警內容.
/usr/local/apache/bin/htpasswd -c /usr/local/nagios/etc/htpasswd nagiosadmin
輸入密碼(這一步很重要)
2.3安裝Nagios插件
2.3.1 nagios-plugins-1.4.X.tar.gz
./configure --with-nagios-user=nagios --with-nagios-group=nagios
make
make install
chkconfig --add nagios
chkconfig nagios on
2.3.2 nrpe_2.8.x.tar.gz
./configure
make all
make install-plugins
make install-daemon
make install-daemon-config
make install-xinetd
三、 詳細配置:
3.1 主機定義:
vi /usr/local/nagios/etc/objects/hosts.cfg
基本模板:
define host{
use linux-server # nagios server-name
host_name 主機名
alias 別名
address X.X.X
}
例:
define host {
host_name CentOS
use linux-server,host-pnp
alias nagios server
address 192.168.1.44
contact_groups nagcmd
check_command check-host-alive
max_check_attempts 5
notification_interval 10
notification_period 24x7
notification_options d,u,r
}
3.2 主機組定義:
vi /usr/local/nagios/etc/objects/hostgroup.cfg
基本模板:
define hostgroup{
hostgroup_name 組名
alias PAY-web
members 主機名1, 主機名2 # 須是定義過的
}
3.3 服務定義:
define service{
use generic-service ; Name of service template to use
hostgroup_name 主機組1, 主機組2
service_description Swap Usage
check_command check_nrpe!check_swap
}
例:define service {
host_name CentOS
use local-service,srv-pnp
service_description CPU
check_period 24x7
max_check_attempts 4
normal_check_interval 1
retry_check_interval 1
contact_groups nagcmd
notification_interval 10
notification_period 24x7
notification_options w,u,c,r
check_command check_nrpe!check_cpu
}
四、 NAGIOS的圖形化(PNP)
#基於LAMP平台
PNP 是基於PHP和PERL,利用rrdtool將Nagios采集的數據繪制成圖表
軟件包列表:
Perl
rrdtool 1.2.*
pnp-0.3.3.tar.gz
4.1 安裝rrdtool-1.4.4.*
tar –xvf rrdtool-1.4.4*
./configure 進行配置 –-prefix=/usr/local/rrdtool
make;make install 然後再編譯和安裝
ls /usr/local/rrdtool-1.4.4.* 查看安裝目錄是否有
應該有這些目錄才正至此rrdtool安裝成功
4.2 安裝pnp
tar xzvf pnp-X.r.gz 將pnp進行解壓
cd pnp-X 進入pnp 目錄
./configure --with-rrdtool=/usr/local/rrdtool/bin/rrdtool --with-perfdata-dir=/usr/local/nagios/share/perfdata/
make all
make install
make install-config
4.2.1 相關設置
首先要將Nagios的主配置文件nagios.cfg中相關的配置修改:
process_performance_data=1
service_perfdata_command=process-service-perfdata #默認此句被注釋掉了
如果想要對某個監控對象做數據圖表,則需在所對應的host或者service定義中(一般寫在hosts.cfg或者services.cfg文件中),包含如下的定義:
process_perf_data 1
4.3 訪問圖表
http://IP/nagios/pnp/
這樣訪問比較麻煩
在服務、主機中添加
1. 在object 目錄裡commands.cfg定義這兩個命令:
# 'process-host-perfdata' command definition
define command{
command_name process-host-perfdata
#command_line /usr/bin/printf "%b" "$LASTHOSTCHECK$\t$HOSTNAME$\t$HOSTSTATE$\t$HOSTATTEMPT$\t$HOSTSTATETYPE$\t$HOSTEXECUTIONTIME$\t$HOSTOUTPUT$\t$HOSTPERFDATA$\n">>/usr/local/nagios/var/host-perfdata.out
command_line /usr/local/nagios/libexec/process_perfdata.pl
}
# 'process-service-perfdata' command definition
define command{
command_name process-service-perfdata
# command_line /usr/bin/printf "%b" "$LASTSERVICECHECK$\t$HOSTNAME$\t$SERVICEDESC$\t$SERVICESTATE$\t$SERVICEATTEMPT$\t$SERVICESTATETYPE$\t$SERVICEEXECUTIONTIME$\t$SERVICELATENCY$\t$SERVICEOUTPUT$\t$SERVICEPERFDATA$\n" >> /usr/local/nagios/var/service-perfdata.out
command_line /usr/local/nagios/libexec/process_perfdata.pl
}
然後在hosts.cfg和services.cfg裡面添加host-pnp, srv-pnp
添加之後重啟nagios,然後到web下就可以看到
本文出自 “huangyu學習博客” 博客