环境中的软件版本>>>>>>>>>>>>>>>>>>
nagios版本:3.5.1
rrdtool版本:1.3.8
pnp4nagios版本:0.6.21
一、第一部分:nagios服务的部署安装
(1)安装nagios服务所需的依赖
[root@nagios_server ~]# yum install yum install gcc make -y //nagios源码安装需要 [root@nagios_server ~]# yum install glibc glibc-common -y //最小化安装的系统都会安装有这两个包 [root@nagios_server ~]# yum install httpd php -y [root@nagios_server ~]# yum install gd gd-devel -y //php所需的gd库,不安装会影响主页上的Map功能
(2)、创建nagios用户、nagcmd组、
将nagios和apache用户加入到nagcmd组中
[root@nagios_server nagios]# useradd nagios [root@nagios_server nagios]# groupadd nagcmd [root@nagios_server ~]# usermod -a -G nagcmd nagios [root@nagios_server ~]# usermod -a -G nagcmd apache
(3)源码安装nagios
[root@nagios_server ~]# tar xf nagios-3.5.1.tar.gz [root@nagios_server ~]# cd nagios [root@nagios_server nagios]# ./configure --with-command-group=nagcmd [root@nagios_server nagios]# make all //编译所有的源码 [root@nagios_server nagios]# make install //安装主程序,CGIs,网页文件,会产生bin、libexec、sbin、share、var目录 [root@nagios_server nagios]# make install-config //安装etc配置目录 [root@nagios_server nagios]# make install-init //安装nagios启动脚本 [root@nagios_server nagios]# make install-webconf //为nagios网站安装httpd配置文件 [root@nagios_server nagios]# make install-commandmode //外部命令访问nagios配置文件的权限、为./var/rw设置0775权限、改所属组为nagcmd
(4)解压nagios插件包、然后进入其目录,执行如下命令编译安装
[root@nagios_server nagios-plugins-2.0.3]# ./configure --with-nagios-user=nagiosc --with-nagios-group=nagcmd [root@nagios_server nagios-plugins-2.0.3]# make && make install //编译安装
(5)启动httpd和nagios服务,然后为nagios网站首页设置密码
[root@nagios_server ~]# htpasswd -c /usr/local/nagios/etc/htpasswd.users nagiosadmin
根据提示会要求输入和确定密码,上面命令nagiosadmin为用户名,如下图所示:
第二部分:RRDTool+PNP4nagios的安装
pnp4nagios是一个小巧的开源软件包,它是基于PHP和Perl,利用rrdtool将Nagios采集的数据绘制成图表。
(1)其中对于rrdtool,我们可以直接使用yum的方式,在此也一同安装上pnp4nagios所需的依赖
[root@nagios_server ~]# yum install perl rrdtool php-gd perl-Time-HiRes rrdtool-perl -y
(2)解压pnp4nagios,进入pnp4nagios-0.6.21目录执行如下命令
[root@nagios_server pnp4nagios-0.6.21]# ./configure \ --prefix=/usr/local/pnp4nagios \ --with-rrdtool=/usr/bin/rrdtool \ --with-nagios-user=nagios \ --with-nagios-group=nagios
[root@nagios_server pnp4nagios-0.6.21]# make all //编译所有源码 [root@nagios_server pnp4nagios-0.6.21]# make fullinstall //安装全部
(3)配置pnp4nagios软件,需要修改pnp4nagios/etc下的目录,及其pages、check_commands目录的文件后缀
[root@nagios_server pnp4nagios-0.6.21]# cd /usr/local/pnp4nagios/etc [root@nagios_server etc]# mv misccommands.cfg-sample misccommands.cfg [root@nagios_server etc]# mv nagios.cfg-sample nagios.cfg [root@nagios_server etc]# mv rra.cfg-sample rra.cfg [root@nagios_server etc]# mv pages/web_traffic.cfg-sample pages/web_traffic.cfg
[root@nagios_server etc]# cd check_commands/ [root@nagios_server check_commands]# mv check_all_local_disks.cfg-sample check_all_local_disks.cfg [root@nagios_server check_commands]# mv check_nrpe.cfg-sample check_nrpe.cfg [root@nagios_server check_commands]# mv check_nwstat.cfg-sample check_nwstat.cfg
(4)启动npcd服务
[root@nagios_server check_commands]# /etc/init.d/npcd restart //启动npcd
(5)重启httpd服务,通过http://ip地址/pnp4nagios 验证pnp4nagios是否成功,如果安装成功、按提示删除如下文件
[root@nagios_server check_commands]# rm -rf /usr/local/pnp4nagios/share/install.php
第三部分:nagios与pnp4nagios的结合
(1)定义命令、需要注释掉自带的process-host-perfdata和process-service-perfdata
编辑/usr/local/nagios/etc/objects/commands.cfg文件,加入如下内容:
define command{ command_name process-host-perfdata command_line /usr/bin/perl /usr/local/pnp4nagios/libexec/process_perfdata.pl -d HOSTPERFDATA } define command{ command_name process-service-perfdata command_line /usr/bin/perl /usr/local/pnp4nagios/libexec/process_perfdata.pl }
(2)定义模板,编辑/usr/local/nagios/etc/objects/templates.cfg,加入如下内容:
define host {
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 }
(3)修改nagios配置文件/usr/local/nagios/etc/nagios.cfg
process_performance_data=1 //默认为0 host_perfdata_command=process-host-perfdata //默认前面有注释符# service_perfdata_command=process-service-perfdata //默认前面有注释符#
(4)接下来就是模板的引用,只需要在需要出图的服务上引用srv-pnp即可,也可以在需要出图的主机上引用hosts-pnp,引用了就可以见到如下效果: