之前用pnp 整合到nagios中,发现总是没数据,图表也出不来,不知道是什么原因,找了资料发现现在用的更多还是pnp4nagios ,便下载试验一下,还真的成功了,配置如下:
1.安装RRDTool
[root@server nagios]# tar zxvf rrdtool-1.4.7.tar.gz
[root@server rrdtool-1.4.7]# ./configure --prefix=/usr/local/rrdtool
编译的时候出现了2个错误:
(1)configure: error: Please fix the library issues listed above and try again.
解决办法:
[root@server nagios]# tar zxvf cgilib-0.5.tar.gz
[root@server nagios]# cd cgilib-0.5
[root@server cgilib-0.5]# make
[root@server cgilib-0.5]# cp libcgi.a /usr/local/lib
[root@server cgilib-0.5]# cp cgi.h /usr/include
[root@server rrdtool-1.4.7]# yum -y install libart_lgpl-devel
[root@server rrdtool-1.4.7]# yum -y install pango-devel* cairo-devel*
(2)在make的时候报错:
Can't locate ExtUtils/MakeMaker.pm in @INC (@INC contains: /usr/local/lib64/perl5 /usr/local/share/perl5 /usr/lib64/perl5/vendor_perl /usr/share/perl5/vendor_perl /usr/lib64/perl5 /usr/share/perl5 .) at Makefile.PL line 1.
解决办法:
yum install perl-ExtUtils-CBuilder perl-ExtUtils-MakeMaker
安装完重新编译即可。
[root@server rrdtool-1.4.7]# ./configure --prefix=/usr/local/rrdtool
[root@server rrdtool-1.4.7]# make
[root@server rrdtool-1.4.7]# make install
2.安装pnp4nagios
[root@server ~]# tar zxvf pnp4nagios-0.6.19.tar.gz
[root@server ~]# cd pnp4nagios-0.6.19
[root@server pnp4nagios-0.6.19]# ./configure --prefix=/usr/local/pnp4nagios --with-nagios-user=nagios --with-rrdtool=/usr/local/rrdtool/bin/rrdtool
到这一步有一个报错:
checking for Perl Module Time::HiRes... no
configure: error: Perl Module Time::HiRes not available
解决办法:
[root@server pnp4nagios-0.6.19]# yum -y install perl-Time-HiRes
[root@server pnp4nagios-0.6.19]# make all
[root@server pnp4nagios-0.6.19]# make install
[root@server pnp4nagios-0.6.19]# make install-webconf
[root@server pnp4nagios-0.6.19]# make install-config
[root@server pnp4nagios-0.6.19]# make install-init
安装完成后,通过模板文件,创建配置文件
[root@server ~]# cd /usr/local/pnp4nagios/etc/
[root@server etc]# mv nagios.cfg-sample nagios.cfg
[root@server etc]# mv rra.cfg-sample rra.cfg
[root@server etc]# mv misccommands.cfg-sample misccommands.cfg
[root@server etc]# cd pages/
[root@server pages]# mv web_traffic.cfg-sample web_traffic.cfg
[root@server pages]# cd ../check_commands/
[root@server check_commands]# mv check_all_local_disks.cfg-sample check_all_local_disks.cfg
[root@server check_commands]# mv check_nrpe.cfg-sample check_nrpe.cfg
[root@server check_commands]# mv check_nwstat.cfg-sample check_nwstat.cfg
3.编辑httpd.conf
打开httpd.conf并添加以下内容:
Alias /pnp4nagios "/usr/local/pnp4nagios/share"
<Directory "/usr/local/pnp4nagios/share">
AllowOverride None
Order allow,deny
Allow from all
AuthName "Nagios Access"
AuthType Basic
AuthUserFile /usr/local/nagios/etc/htpasswd
Require valid-user
<IfModule mod_rewrite.c>
# Turn on URL rewriting
RewriteEngine On
Options symLinksIfOwnerMatch
# Installation directory
RewriteBase /pnp4nagios/
# Protect application and system files from being viewed
RewriteRule "^(?:application|modules|system)/" - [F]
# Allow any files or directories that exist to be displayed directly
RewriteCond "%{REQUEST_FILENAME}" !-f
RewriteCond "%{REQUEST_FILENAME}" !-d
# Rewrite all other URLs to index.php/URL
RewriteRule "^.*$" "index.php/$0" [PT]
</IfModule>
</Directory>
配置完成后保存退出。
重启http
[root@server ~]# /usr/local/apache/bin/apachectl restart
4.编辑template.cfg 文件
添加以下内容:
[root@server ~]# vim /usr/local/nagios/etc/objects/templates.cfg
define host {
namehosts-pnp
register0
action_url /pnp4nagios/graph?host=$HOSTNAME$
process_perf_data1
}
define service {
nameservices-pnp
register0
action_url /pnp4nagios/graph?host=$HOSTNAME$&srv=$SERVICEDESC$
process_perf_data1
}
5.编辑hosts.cfg和services.cfg 添加小太阳标示
[root@server ~]# vim /usr/local/nagios/etc/hosts.cfg
define host{
uselinux-server,hosts-pnp
host_namenode-1
aliaslamp
address192.168.30.110
}
[root@server ~]# vim /usr/local/nagios/etc/services.cfg
define service{
usegeneric-service,services-pnp
host_namenode-1
service_descriptioncheck_users
check_commandcheck_nrpe!check_users
max_check_attempts 5
normal_check_interval 1
}
6.编辑commands.cfg 添加相应命令
[root@server ~]# vim /usr/local/nagios/etc/objects/commands.cfg
# 'process-host-perfdata' command definition
define command{
command_nameprocess-host-perfdata
command_line /usr/local/nagios/libexec/process_perfdata.pl
}
# 'process-service-perfdata' command definition
define command{
command_nameprocess-service-perfdata
command_line /usr/local/nagios/libexec/process_perfdata.pl
}
注意:这里为了方便管理,将process_perfdata.pl 复制到/usr/local/nagios/libexec/目录下
[root@server ~]# cp /usr/local/pnp4nagios/libexec/process_perfdata.pl /usr/local/nagios/libexec/
7.检查并重启nagios
通过nagios �Cv 参数检查配置是否有错误存在。
Total Warnings: 0
Total Errors:0
确认无错误后,重启nagios
[root@server ~]# service nagios restart
Running configuration check...done.
Stopping nagios: .done.
效果如下:
点击小太阳进入测试页面
注:只有在前面准备阶段把基础环境都配置好,这里的环境测试才能全部通过的。
如果提示缺少Php 相关包,可以通过yum �Cy php-* 进行安装
按照图中提示删除或者重命名其安装文件install.php。这里选择重命名的方式。
[root@server ~]# mv /usr/local/pnp4nagios/share/install.php
/usr/local/pnp4nagios/share/install.php.bak
8.编辑nagios.cfg,开启数据接收功能
[root@server ~]# vim /usr/local/nagios/etc/nagios.cfg
process_performance_data=1
enable_environment_macros=1
service_perfdata_command=process-service-perfdata
host_perfdata_command=process-host-perfdata
9.重启nagios 服务之后即可看到图表
注意:打开的时候遇到了以下的错误:
根据提示,是权限不够的问题:
[root@server ~]# chmod 750 /var/lib/php/session/
[root@server ~]# chown nagios.nagios /var/lib/php/session/
刷新网页之后即可看到有图表出现: