监控Cacti+Nagios+NagiosQl+NagVis+Pnp4nagios整合

系统版本:

[root@bjNagios ~]# cat /etc/issue
CentOS release 6.5(Final)
Kernel \r on an \m

软件准备:(包括了所需软件和插件)

 

rrdtool-1.4.8.tar.tar
cacti-0.8.8b.tar.gz
cacti-plugin-0.8.7h-PA-v3.0.tar.gz
monitor-v1.3-1.tgz
npc-2.0.4.tar.gz
nrpe-2.15.tar.gz
settings-v0.71-1.tgz
thold-v0.5.0.tgz
nagios-4.0.4.tar.gz
nagios-plugins-2.0.tar.gz
nagiosql_320.tar.gz
nagvis-1.7.10.tar.gz
ndoutils-2.0.0.tar.gz
net-snmp-5.7.2.1.tar.gz
pnp4nagios-0.6.21.tar.g
php-json-ext-1.2.1

我是YUM安装的LAMP环境:

yum install httpd httpd-deve
yum install mysql mysql-server mysql-devel
yum install php php-mysql php-common php-gd php-mbstring php-mcrypt php-devel php-xml

有时候可能会遇到因为LAMP环境的一些扩展没有安装上,所以在yum的时候可以用php*  mysql* 这样的方式安装所有的相关软件。

[root@bjNagios ~]# rpm -qa | grep httpd
httpd-devel-2.2.15-29.el6.centos.x86_64
httpd-2.2.15-29.el6.centos.x86_64
httpd-manual-2.2.15-29.el6.centos.noarch
httpd-tools-2.2.15-29.el6.centos.x86_64
[root@bjNagios ~]# rpm -qa | grep php
php-cli-5.3.3-27.el6_5.x86_64
php-xml-5.3.3-27.el6_5.x86_64
php-pgsql-5.3.3-27.el6_5.x86_64
php-pspell-5.3.3-27.el6_5.x86_64
php-recode-5.3.3-27.el6_5.x86_64
php-xmlrpc-5.3.3-27.el6_5.x86_64
php-zts-5.3.3-27.el6_5.x86_64
php-5.3.3-27.el6_5.x86_64
php-devel-5.3.3-27.el6_5.x86_64
php-tidy-5.3.3-27.el6_5.x86_64
php-enchant-5.3.3-27.el6_5.x86_64
php-pecl-apc-devel-3.1.9-2.el6.x86_64
php-ldap-5.3.3-27.el6_5.x86_64
php-soap-5.3.3-27.el6_5.x86_64
php-pecl-apc-3.1.9-2.el6.x86_64
php-pdo-5.3.3-27.el6_5.x86_64
php-mysql-5.3.3-27.el6_5.x86_64
php-snmp-5.3.3-27.el6_5.x86_64
php-odbc-5.3.3-27.el6_5.x86_64
php-bcmath-5.3.3-27.el6_5.x86_64
php-fpm-5.3.3-27.el6_5.x86_64
php-process-5.3.3-27.el6_5.x86_64
php-pear-1.9.4-4.el6.noarch
php-common-5.3.3-27.el6_5.x86_64
php-gd-5.3.3-27.el6_5.x86_64
php-mbstring-5.3.3-27.el6_5.x86_64
php-imap-5.3.3-27.el6_5.x86_64
php-intl-5.3.3-27.el6_5.x86_64
php-pecl-memcache-3.0.5-4.el6.x86_64
php-embedded-5.3.3-27.el6_5.x86_64
php-dba-5.3.3-27.el6_5.x86_64
[root@bjNagios ~]# rpm -qa | grep mysql
mysql-5.1.73-3.el6_5.x86_64
mysql-devel-5.1.73-3.el6_5.x86_64
mysql-connector-odbc-5.1.5r1144-7.el6.x86_64
mysql-bench-5.1.73-3.el6_5.x86_64
mysql-server-5.1.73-3.el6_5.x86_64
mysql-embedded-devel-5.1.73-3.el6_5.x86_64
php-mysql-5.3.3-27.el6_5.x86_64
mysql-connector-java-5.1.17-6.el6.noarch
mysql-libs-5.1.73-3.el6_5.x86_64
mysql-embedded-5.1.73-3.el6_5.x86_64
mysql-test-5.1.73-3.el6_5.x86_64

测试一下:

在/var/www/html/目录下新建一个test.php文件,将一下内容写入:

<?
phpinfo();
?>

启动服务:

[root@bjNagios ~]# service httpd start
Starting httpd:                                            [  OK  ]
[root@bjNagios ~]# service mysqld start
Starting mysqld:                                           [  OK  ]

打开浏览器输入:http://IP/test.php

wKioL1MyOC2zUxNXAAQr3Et93vQ705.jpg

如果浏览器界面一片空白,说明是因为没有开启php短格式,只要编辑php.ini文件更改如下:

[root@bjNagios ~]# vim /etc/php.ini
short_open_tag = On #找到这个选项,把Off改为On;

然后重启http,在打开就没有问题了。

到此,准备方面可以说是OK了。


接下来开始安装:

关于Cacti、Nagios等介绍这里就不说了,直接步入正题。

Cacti有三大组件:MySQL 数据库、RRDtool 工具、Net-Snmp 程序。MySQL并不负责监控数据的存储,只保存模板和rra 文件与主机对应等信息,而真正的监控数据存储和图像展现都是rrdtool 来做的。而Net-SNMP 负责数据的采集。


安装rrdtool:

Rrdtool安装需要cairo、libxml2、pango库支持,可通过yum安装;

[root@bjNagios ~]# yum -y install cairo-devel libxml2-devel pango-devel
[root@bjNagios ~]# tar xzf rrdtool-1.4.8.tar.tar
[root@bjNagios ~]# cd rrdtool-1.4.8/
[root@bjNagios rrdtool-1.4.8]# ./configure --prefix=/usr/local/rrdtool
[root@bjNagios rrdtool-1.4.8]# make && make install
[root@bjNagios rrdtool-1.4.8]# ln -s /usr/local/rrdtool/bin* /usr/local/bin/


安装net-snmp:

这里可以yum安装:

[root@bjNagios ~]# rpm -qa | grep net-snmp
net-snmp-utils-5.5-49.el6.x86_64
net-snmp-libs-5.5-49.el6.x86_64
net-snmp-5.5-49.el6.x86_64
net-snmp-devel-5.5-49.el6.x86_64
[root@bjNagios ~]# service snmpd start
Starting snmpd:                                            [  OK  ]


安装Cacti:

给数据库设定密码:

mysqladmin -u root password '1234'

  1. # mysql -u root -p  

  2. :输入密码

mysql> create database cacti;
Query OK,1 row affected (0.00 sec)
mysql> grant all on cacti.* to cactiadmin@localhost identified by 'cacti';
Query OK,0 rows affected (0.01 sec)
mysql> flush privileges;
Query OK,0 rows affected (0.00 sec)
mysql> \q

数据库创建完毕;

[root@bjNagios ~]# tar xzf cacti-0.8.8b.tar.gz
[root@bjNagios ~]# mv cacti-0.8.8b /var/www/html/cacti
[root@bjNagios ~]# chown -R apache:apache /var/www/html/cacti/
[root@bjNagios ~]# cd /var/www/html/cacti/
[root@bjNagios cacti]# mysql -ucacti -pcacti cacti < cacti.sql
#将cacti数据导入

修改网站配置文件,使用正确连接数据库参数:

[root@bjNagios cacti]# vim include/config.php
/* make sure these values refect your actual database/host/user/password */
$database_type = "mysql";
$database_default = "cacti";
$database_hostname = "localhost";
$database_username = "cacti"; #用户名;
$database_password = "cacti"; #用户密码;
$database_port = "3306";
$database_ssl = false;

打开浏览器:http://IP/cacti/install

wKioL1MyQzXj6bavAAJmY0ppKqo059.jpg

wKiom1MyQ13w7Q60AADq9Uga7AQ213.jpg

wKioL1MyQzXwflwjAANteEdLisk145.jpg

wKiom1MyQ13yXT2FAACuTEP_TOc854.jpg

首次登录会让修改密码,至此,Cacti安装完毕。

#TOP1:如果遇到了打不开Cacti初始化安装界面,显示一片空白。
#原因:是因为在安装LAMP环境的时候,少安装了php-mysql这个包,安装上重启服务就好了。
#TOP2:如果打开未看到生成图像,请手动执行下面命令
#/usr/bin/php   /var/www/cacti/poller.php &>/dev/null手动生成图像


安装插件cacti-plugin

[root@bjNagios ~]# tar xzf cacti-plugin-0.8.7h-PA-v3.0.tar.gz
[root@bjNagios ~]# cd cacti-plugin-arch/
[root@bjNagios cacti-plugin-arch]# cp cacti-plugin-0.8.7h-PA-v3.0.diff pa.sql /var/www/html/cacti/
[root@bjNagios cacti-plugin-arch]# cd /var/www/html/cacti/
#打补丁,导入数据库;
[root@bjNagios cacti]# patch -p1 -N <cacti-plugin-0.8.7h-PA-v3.0.diff
[root@bjNagios cacti]# mysql -uroot -p cacti<pa.sql
Enter password:
[root@bjNagios cacti]#
#修改配置文件如下:
[root@bjNagios cacti]# vim include/global.php
$config['url_path'] = '/cacti/';
#默认其实也不用改,因为
$url_path = "/cacti/";
$config['url_path'] = $url_path;


添加计划任务:

[root@bjNagios cacti]# crontab -e
*/5 * * * * /usr/bin/php /var/www/html/cacti/poller.php &>/dev/null
#另外cacti无法显示图片,图片显红叉,但是点进去有图,解决方法:
#settings里面的RRDTOOLS版本设置不对,可能默认为1.0.x,改为1.2.x或更高就行了。


安装配置Nagios:

Nagios用户和组
添加一个名为nagios的用户用以专门跑nagios
添加nagcmd用户组,用以通过web页面提交外部控制命令
将nagios用户加入nagcmd组
将apache用户加入nagcmd组
# useradd -s /sbin/nologin nagios
# groupadd nagcmd
# usermod �CG nagcmd nagios
# usermod �CG nagcmd apache


编译安装Nagios:

[root@bjnagios ~]#tar xf nagios-4.0.4.tar.gz
[root@bjnagios ~]# cd nagios-4.0.4/
[root@bjnagios nagios-4.0.4]# ./configure --prefix=/usr/local/nagios --with-nagios-user=nagios --with-nagios-group=nagios --with-command-user=nagios --with-command-group=nagcmd
[root@bjnagios nagios-4.0.4]#make all
[root@bjnagios nagios-4.0.4]#make install
[root@bjnagios nagios-4.0.4]#make install-init
[root@bjnagios nagios-4.0.4]#make install-commandmode
[root@bjnagios nagios-4.0.4]# make install-config
[root@bjnagios nagios-4.0.4]# make install-webconf
#这里install-webconf后,就不用在配置httpd.conf了。
[root@bjnagios nagios-4.0.4]# chkconfig --add nagios
[root@bjnagios nagios-4.0.4]# chkconfig nagios on
[root@bjnagios nagios-4.0.4]# service nagios start


安装插件:

[root@bjnagios ~]# tar -zxvf nagios-plugins-1.4.15.tar.gz
[root@bjnagios nagios-plugins-2.0]# ./configure --prefix=/usr/local/nagios/ && make && make install
#设置访问密码:
[root@bjnagios nagios-plugins-2.0]#htpasswd -c/usr/local/nagios/etc/htpasswd.users nagiosadmin
New password: 输入密码
Re-type new password: 再次输入密码
Adding password for user nagiosadmin
#检查配置文件执行:
[root@bjnagios nagios-plugins-2.0]# /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg


登录Nagios:http://IP/nagios

wKioL1MyUGPA2EVeAAD2uz2b_ps831.jpg

使用刚刚设定的密码登录,可正常访问。

wKioL1MyUKzQGYmDAAT_z1qZuLE420.jpg


整合cacti + nagios整合

cacti和nagios是利用了cacti的一个插件nagios for cacti,它的原理是将nagios的数据通过ndo2db导入到mysql数据库(cacti的库中),然后cacti读取数据库信息将nagios的结果展示出来。

安装php-json扩展,因为NPC使用了ExtJS,如过没有json的扩展NPC界面无法出来。

[root@bjNagios ~]# tar xf php-json-ext-1.2.1.tar.gz^C
[root@bjNagios ~]# cd php-json-ext-1.2.1/
[root@bjNagios php-json-ext-1.2.1]# phpize
#如果没有命令,安装php-devel
[root@bjNagios php-json-ext-1.2.1]# cat /etc/php.d/json.ini
; Enable json extension module
extension=json.so
[root@bjNagios php-json-ext-1.2.1]#


打开test.php界面,验证:

wKiom1MyVBygQfGTAAA_Wd6-VGQ426.jpg

安装ndoutils,需要安装mysql-devel前面已经装过这里就不用再装了

[root@bjNagios ~]# tar xzf ndoutils-2.0.0.tar.gz
[root@bjNagios ~]# cd ndoutils-2.0.0
[root@bjNagios ndoutils-2.0.0]# ./configure --enable-nanosleep --enable-mysql --with-ndo2db-user=nagios --with-ndo2db-group=nagios
[root@bjNagios ndoutils-2.0.0]# make
#不用make install
[root@bjNagios ndoutils-2.0.0]# cd src/
[root@bjNagios src]# cp ndomod-* ndo2db-* log2ndo file2sock /usr/bin/
[root@bjNagios src]# cp ../config/ndo2db.cfg-sample /usr/local/nagios/etc/ndo2db.cfg
[root@bjNagios src]# cp ../config/ndomod.cfg-sample /usr/local/nagios/etc/ndomod.cfg
[root@bjNagios src]# chmod 644 /usr/local/nagios/etc/ndo*


配置文件信息,连接数据库:

[root@bjNagios src]# vim /usr/local/nagios/etc/ndo2db.cfg
#找到以下几项,并修改,把与之一样的注视掉;
socket_type=tcp
db_host=127.0.0.1
db_port=3306
db_name=cacti
db_prefix=npc_
db_user=cacti
db_pass=cacti
debug_level=1
[root@bjNagios src]# vim /usr/local/nagios/etc/ndomod.cfg
output_type=tcpsocket
output=127.0.0.1


添加启动脚本,并修改Ndo2dbBin

[root@bjNagios ndoutils-2.0.0]# cp daemon-init /etc/init.d/ndo2db
#这个daemon在源码包里面;
[root@bjNagios ndoutils-2.0.0]# chmod +x /etc/init.d/ndo2db
[root@bjNagios ndoutils-2.0.0]# vim /etc/init.d/ndo2db
Ndo2dbBin=/usr/bin/ndo2db-3x
#注意这里是/usr/bin/
[root@bjNagios ndoutils-2.0.0]# service  ndo2db start

安装NPC:

[root@bjNagios ~]# tar xzf npc-2.0.4.tar.gz
[root@bjNagios ~]# mv npc /var/www/html/cacti/plugins
[root@bjNagios ~]# vim /var/www/html/cacti/include/global.php
#修改配置文件,添加如下信息
$plugins = array();
$plugins[]='npc';
[root@bjNagios ~]# vim /usr/local/nagios/etc/nagios.cfg
#修改Nagios,添加信息;
broker_module=/usr/bin/ndomod-3x.o config_file=/usr/local/nagios/etc/ndomod.cfg
event_broker_options=-1  #此选项默认存在;
[root@bjNagios ~]# service  nagios restart
Running configuration check...Stopping nagios: No lock file found in /usr/local/nagios/var/nagios.lock
Starting nagios: done.

然后打开Cacti界面:

wKioL1MyYA6BaIs0AAIkydFGCqI457.jpg

wKiom1MyYRTj0G0tAAWdI7A2HeE642.jpg



未完待续~~~(cacti中npc下的nagios状态off未解决。)

这里只能先把这个问题放一放,继续下面的安装;

===================分割线=======================

下面安装NagiosQl:

[root@bjNagios ~]# tar xzf nagiosql_320.tar.gz
[root@bjNagios ~]# mv nagiosql32/ /usr/local/nagios/nagiosql
[root@bjNagios ~]#

建立nagiosQL导出nagios配置文件的目录,并修改权限

建目录和改权限

[root@bjNagios ~]# mkdir -p /etc/nagiosql/{hosts,services,backup/{,hosts,services},import}
[root@bjNagios ~]# chown -R apache:nagios /etc/nagiosql/
[root@bjNagios ~]# chmod -R 755 /etc/nagiosql
[root@bjNagios ~]# chmod 777 /usr/local/nagios/nagiosql/config
[root@bjNagios ~]#

Nagios相关文件权限的设定

[root@bjNagios ~]# chown nagios:apache /usr/local/nagios/etc
[root@bjNagios ~]# chown nagios:apache /usr/local/nagios/etc/{nagios.cfg,cgi.cfg}
[root@bjNagios ~]# chown nagios:apache /usr/local/nagios/etc/*
[root@bjNagios ~]# chmod 664 /usr/local/nagios/etc/{nagios.cfg,cgi.cfg}
[root@bjNagios ~]# chmod 775 /usr/local/nagios/etc

设定nagios二进制文件的权限,以便其能够通过Web程序执行

[root@bjNagios ~]# chown nagios:apache /usr/local/nagios/bin/nagios
[root@bjNagios ~]# chmod 750 /usr/local/nagios/bin/nagios
[root@bjNagios ~]# chown -R apache.nagios /usr/local/nagios/var/spool/
[root@bjNagios ~]# chown nagios:apache /usr/local/nagios/var/rw/nagios.cmd
[root@bjNagios ~]# chmod 660 /usr/local/nagios/var/rw/nagios.cmd

为apache添加nagiosQL虚拟目录

vim /etc/httpd/conf.d/nagios.conf
在文件末尾添加如下:
#add virture directory for nagiosql
Alias /nagiosql "/usr/local/nagios/nagiosql"
<Directory "/usr/local/nagios/nagiosql">
# SSLRequireSSL
Options None
AllowOverride None
Order allow,deny
Allow from all
</Directory>
#重启httpd mysqld服务
[root@bjNagios ~]# service httpd restart
Stopping httpd:                                            [  OK  ]
Starting httpd:                                            [  OK  ]
[root@bjNagios ~]# service mysqld restart
Stopping mysqld:                                           [  OK  ]
Starting mysqld:                                           [  OK  ]
[root@bjNagios ~]#

建立nagiosql安装文件,

[root@bjNagios ~]# touch /usr/local/nagios/nagiosql/install/ENABLE_INSTALLER

访问http://serverIP/nagiosql进行安装

wKiom1MylrHyC5wKAAMA3N57_wA833.jpg

wKioL1MyltmAHMdtAANZ4pxH4r0181.jpg

wKiom1MylwGip6KjAAU6rxbXUzc487.jpg

删除安装目录,这里使用改权限:chmod 000 /usr/local/nagios/nagiosql/install

按如图所示更改相应的路径:

wKioL1MymQOzm9_xAAJsMElfTOY072.jpg

wKiom1MymSvTVSaWAAKDhVUS9f0785.jpg

wKioL1MymQPhYr-HAAR75Bi_kVk627.jpg

wKiom1MymSvRksx5AAMT-1er7dA331.jpg

wKiom1MymhTDsnhxAAEV7LCEwgI135.jpg

写入之后就可以看到相应的cfg文件了,查看写入是否成功,由下面的输出可以看出写入是成功的

wKioL1MymgSjQv21AAD4W0Fv4h8353.jpg

修改nagios的配置文件,将原有以cfg_file开头项全部注释掉,加入上面新写入的配置文件

[root@bjNagios etc]# cp nagios.cfg nagios.cfg.bak
[root@bjNagios etc]# vim nagios.cfg
# You can specify individual object config files as shown below:
#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
# Definitions for monitoring the local (Linux) host
#cfg_file=/usr/local/nagios/etc/objects/localhost.cfg
# Definitions for monitoring a Windows machine
#cfg_file=/usr/local/nagios/etc/objects/windows.cfg
# Definitions for monitoring a router/switch
#cfg_file=/usr/local/nagios/etc/objects/switch.cfg
# Definitions for monitoring a network printer
#cfg_file=/usr/local/nagios/etc/objects/printer.cfg
cfg_dir=/etc/nagiosql/hosts/
cfg_dir=/etc/nagiosql/services/
cfg_file=/etc/nagiosql/commands.cfg
cfg_file=/etc/nagiosql/contactgroups.cfg
cfg_file=/etc/nagiosql/contacts.cfg
cfg_file=/etc/nagiosql/contacttemplates.cfg
cfg_file=/etc/nagiosql/hostdependencies.cfg
cfg_file=/etc/nagiosql/hostescalations.cfg
cfg_file=/etc/nagiosql/hostextinfo.cfg
cfg_file=/etc/nagiosql/hostgroups.cfg
cfg_file=/etc/nagiosql/hosttemplates.cfg
cfg_file=/etc/nagiosql/servicedependencies.cfg
cfg_file=/etc/nagiosql/serviceescalations.cfg
cfg_file=/etc/nagiosql/serviceextinfo.cfg
cfg_file=/etc/nagiosql/servicegroups.cfg
cfg_file=/etc/nagiosql/servicetemplates.cfg
cfg_file=/etc/nagiosql/timeperiods.cfg

 

接着编译安装PNP4NAGIOS

这是官方文档地址:http://docs.pnp4nagios.org/pnp-0.6/start

在安装之前,检查模块是否存在:

[root@bjnagios ~]# perl -MRRDs -le 'print q(ok)'
Can't locate RRDs.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 .).
BEGIN failed--compilation aborted.
[root@bjnagios ~]#
#不存在,做一个软链接继续检查
[root@bjnagios ~]#ln -s /usr/local/rrdtool/lib/perl/5.8.8/x86_64-linux-thread-multi/RRDs.pm  /usr/lib64/perl5/site_perl/5.8.8/x86_64-linux-thread-multi/
[root@bjnagios ~]#ln -s /usr/local/rrdtool/lib/perl/5.8.8/x86_64-linux-thread-multi/auto/RRDs/RRDs.so  /usr/lib64/perl5/site_perl/5.8.8/x86_64-linux-thread-multi/
[root@bjNagios ~]# perl -MRRDs -le 'print q(ok)'
ok
#如果不做上面的一系列动作,在编译PNP的时候会出现错误报告。
#如果解决不了执行:yum install perl-rrdtool

编译:

[root@bjNagios ~]# tar xzf pnp4nagios-0.6.21.tar.gz^C
[root@bjNagios ~]# cd pnp4nagios-0.6.21/
[root@bjNagios pnp4nagios-0.6.21]# ./configure --with-nagios-user=nagios --with-nagios-group=nagios --with-rrdtool=/usr/local/rrdtool/bin/rrdtool --with-perfdata-dir=/usr/local/nagios/share/perfdata
#################################################
*** Configuration summary for pnp4nagios-0.6.21 03-24-2013 ***
General Options:
-------------------------         -------------------
Nagios user/group:                nagios nagios
Install directory:                /usr/local/pnp4nagios
HTML Dir:                         /usr/local/pnp4nagios/share
Config Dir:                       /usr/local/pnp4nagios/etc
Location of rrdtool binary:       /usr/local/rrdtool/bin/rrdtool Version 1.4.8
RRDs Perl Modules:                FOUND (Version 1.3008)
RRD Files stored in:              /usr/local/nagios/share/perfdata
process_perfdata.pl Logfile:      /usr/local/pnp4nagios/var/perfdata.log
Perfdata files (NPCD) stored in:  /usr/local/pnp4nagios/var/spool
Web Interface Options:
-------------------------         -------------------
HTML URL:                         http://localhost/pnp4nagios
Apache Config File:               /etc/httpd/conf.d/pnp4nagios.conf
Review the options above for accuracy.  If they look okay,
type 'make all' to compile.
##############################################################
[root@bjNagios pnp4nagios-0.6.21]# make all
[root@bjNagios pnp4nagios-0.6.21]# make install
[root@bjNagios pnp4nagios-0.6.21]# make install-webconf
[root@bjNagios pnp4nagios-0.6.21]# make install-config
[root@bjNagios pnp4nagios-0.6.21]# make install-init

配置PNP

#创建默认配置文件;
[root@bjNagios pnp4nagios-0.6.21]# cd /usr/local/pnp4nagios/etc/
[root@bjNagios etc]# cp misccommands.cfg-sample misccommands.cfg
[root@bjNagios etc]# cp nagios.cfg-sample nagios.cfg
[root@bjNagios etc]# cp rra.cfg-sample rra.cfg
[root@bjNagios etc]# cd pages/
[root@bjNagios pages]# cp web_traffic.cfg-sample web_traffic.cfg
[root@bjNagios pages]# cd ../check_commands/
[root@bjNagios check_commands]# cp check_all_local_disks.cfg-sample check_all_local_disks.cfg
[root@bjNagios check_commands]# cp check_nrpe.cfg-sample check_nrpe.cfg
[root@bjNagios check_commands]# cp check_nwstat.cfg-sample check_nwstat.cfg

修改nagios配置文件:

pnp4nagios官方提供了三种配置方法,我这里选取一种
vi /usr/local/nagios/etc/nagios.cfg
process_performance_data=1
# service performance data
#
service_perfdata_file=/usr/local/nagios/share/perfdata/service-perfdata
service_perfdata_file_template=DATATYPE::SERVICEPERFDATA\tTIMET::$TIMET$\tHOSTNAME::$HOSTNAME$\tSERVICEDESC::$SERVICEDESC$\tSERVICEPERFDATA::$SERVICEPERFDATA$\tSERVICECHECKCOMMAND::$SERVICECHECKCOMMAND$\tHOSTSTATE::$HOSTSTATE$\tHOSTSTATETYPE::$HOSTSTATETYPE$\tSERVICESTATE::$SERVICESTATE$\tSERVICESTATETYPE::$SERVICESTATETYPE$
service_perfdata_file_mode=a
service_perfdata_file_processing_interval=15
service_perfdata_file_processing_command=process-service-perfdata-file
#
# host performance data starting with Nagios 3.0
#
host_perfdata_file=/usr/local/nagios/share/perfdata/host-perfdata
host_perfdata_file_template=DATATYPE::HOSTPERFDATA\tTIMET::$TIMET$\tHOSTNAME::$HOSTNAME$\tHOSTPERFDATA::$HOSTPERFDATA$\tHOSTCHECKCOMMAND::$HOSTCHECKCOMMAND$\tHOSTSTATE::$HOSTSTATE$\tHOSTSTATETYPE::$HOSTSTATETYPE$
host_perfdata_file_mode=a
host_perfdata_file_processing_interval=15
host_perfdata_file_processing_command=process-host-perfdata-file
#host_perfdata_command=process-host-perfdata
#service_perfdata_command=process-service-perfdata

vi /usr/local/nagios/etc/objects/commands.cfg 修改最后两行为

#把上面两条相同的注释掉!
define command{
command_name    process-service-perfdata-file
command_line    /usr/local/pnp4nagios/libexec/process_perfdata.pl --bulk=/usr/local/pnp4nagios/var/service-perfdata
}
define command{
command_name    process-host-perfdata-file
command_line    /usr/local/pnp4nagios/libexec/process_perfdata.pl --bulk=/usr/local/pnp4nagios/var/host-perfdata
}

打开http://IP/pnp4nagios

wKiom1Myp6Lhurq9AAROAT2MNbI065.jpg

#####
[root@bjNagios ~]# cd /usr/local/pnp4nagios/share/
[root@bjNagios share]# mv install.php install.php.bak

在pnp4nagios的源码包下面执行
 cp contrib/ssi/* /usr/local/nagios/share/ssi/
 然后在服务或者主机定义里面添加action_url

define service{
use                             local-service         ; Name of service template to use
host_name                       localhost
service_description             PING
check_command                   check_ping!100.0,20%!500.0,60%
action_url                      /pnp4nagios/index.php/graph?host=$HOSTNAME$&srv=$SERVICEDESC$' class='tips' rel='/pnp4nagios/index.php/popup?host=$HOSTNAME$&srv=$SERVICEDESC$
}
define host{
use                     linux-server
host_name               localhost
alias                   localhost
address                 127.0.0.1
action_url              /pnp4nagios/index.php/graph?host=$HOSTNAME$&srv=_HOST_' class='tips' rel='/pnp4nagios/index.php/popup?host=$HOSTNAME$&srv=_HOST_
}

wKiom1Myq1TD4CmxAABvg2W0d5U431.jpg

你可能感兴趣的:(监控Cacti+Nagios+NagiosQl+NagVis+Pnp4nagios整合)