关于IT运维技术的
最佳实践博客网站

编译安装 nagios PNP4nagios rrdtool 绘制监控图文信息(提升)

这篇文档是基于:在centos6.5下编译安装nagios内核和插件和使用NRPE扩展来监控远程服务器(基础)

pnp4nagios 依赖 rrdtool ,而rrdtool 的安装需要一系列繁杂的依赖关系。因此先yum安装各种依赖关系。

yum install -y pango pango-devel freetype freetype-devel libpng libpng-devel gettext gettext-devel libjpeg libjpeg-devel gd gd-devel libxml2 libxml2-devel libiconv libiconv-devel  qpixman qpixman-devel glib glib-devel cairo cairo-devel libart*

安装rrdtools

wget https://oss.oetiker.ch/rrdtool/pub/rrdtool-1.4.9.tar.gz
tar zxvf rrdtool-1.4.9.tar.gz
cd rrdtool-1.4.9
./configure

有可能会有以下错误。一一对应安装相应的依赖库

configure: WARNING:
----------------------------------------------------------------------------
* I could not find a working copy of libxml-2.0. Check config.log for hints on why
this is the case. Maybe you need to set LDFLAGS and CPPFLAGS appropriately
so that compiler and the linker can find libxml2 and its header files. If
you have not installed libxml-2.0, you can get it either from its original home on

https://xmlsoft.org/downloads.html

You can find also find an archive copy on

https://oss.oetiker.ch/rrdtool/pub/libs

The last tested version of libxml-2.0 is 2.7.8.

LIBS=-lm
LDFLAGS=
CPPFLAGS= -I/usr/include/libxml2

----------------------------------------------------------------------------

configure: error: Please fix the library issues listed above and try again.

解决方法:yum -y install libxml2 libxml2-devel

configure: WARNING:
----------------------------------------------------------------------------
* I could not find a working copy of pangocairo. Check config.log for hints on why
this is the case. Maybe you need to set LDFLAGS and CPPFLAGS appropriately
so that compiler and the linker can find libpangocairo-1.0 and its header files. If
you have not installed pangocairo, you can get it either from its original home on

https://ftp.gnome.org/pub/GNOME/sources/pango/1.28

You can find also find an archive copy on

https://oss.oetiker.ch/rrdtool/pub/libs

The last tested version of pangocairo is 1.28.4.

LIBS=-lm
LDFLAGS=
CPPFLAGS=

----------------------------------------------------------------------------

checking for xmlParseFile in -lxml2... yes
checking libxml/parser.h usability... yes
checking libxml/parser.h presence... yes
checking for libxml/parser.h... yes
configure: error: Please fix the library issues listed above and try again.

解决方法:yum install pango pango-devel pangomm pangomm-devel

./configure 没有错。可是make 的时候就有错误了,按照说明安装

make[2]: Leaving directory `/usr/local/src/rrdtool-1.4.9/doc'
Making all in bindings
make[2]: Entering directory `/usr/local/src/rrdtool-1.4.9/bindings'
make[3]: Entering directory `/usr/local/src/rrdtool-1.4.9/bindings'
cd perl-piped && /usr/bin/perl Makefile.PL PREFIX=/opt/rrdtool-1.4.9 INSTALL_BASE= LIB=/opt/rrdtool-1.4.9/lib/perl/5.10.1
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.
BEGIN failed--compilation aborted at Makefile.PL line 1.
make[3]: *** [perl-piped/Makefile] 错误 2
make[3]: Leaving directory `/usr/local/src/rrdtool-1.4.9/bindings'
make[2]: *** [all-recursive] 错误 1
make[2]: Leaving directory `/usr/local/src/rrdtool-1.4.9/bindings'
make[1]: *** [all-recursive] 错误 1
make[1]: Leaving directory `/usr/local/src/rrdtool-1.4.9'
make: *** [all] 错误 2

解决方法:yum install perl-ExtUtils-Embed rrdtool-perl

最后make和make install 一路顺风。

开始安装PNP4nagios

wget https://jaist.dl.sourceforge.net/project/pnp4nagios/PNP-0.6/pnp4nagios-0.6.24.tar.gz
tar zxvf pnp4nagios-0.6.24.tar.gz
cd pnp4nagios-0.6.24
./configure --with-nagios-user=nagios --with-nagios-group=nagios --with-rrdtool=/opt/rrdtool-1.4.9/bin/rrdtool

可能会有错误提示:“RRDs Perl Modules: *** NOT FOUND ***”
解决方法:

yum install rrdtool-per

然后继续

make all
make fullinstall

安装完成后的一些路径

eneral 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: /opt/rrdtool-1.4.9/bin/rrdtool Version 1.4.9
RRDs Perl Modules: FOUND (Version 1.3008)
RRD Files stored in: /usr/local/pnp4nagios/var/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: https://localhost/pnp4nagios
Apache Config File: /etc/httpsd/conf.d/pnp4nagios.conf

特别注意几个文件的路径

登陆的验证文件在
/usr/local/nagios/etc/htpasswd.users
启动脚本在:
/etc/init.d/npcd

将这些配置文件重命名,使之能够被程序识别

cd   /usr/local/pnp4nagios/etc 
mv misccommands.cfg-sample  misccommands.cfg 
mv nagios.cfg-sample nagios.cfg 
mv rra.cfg-sample rra.cfg 
cd /usr/local/pnp4nagios/etc/pages/ 
mv web_traffic.cfg-sample web_traffic.cfg 
cd ../check_commands 
mv check_all_local_disks.cfg-sample  check_all_local_disks.cfg 
mv check_nrpe.cfg-sample  check_nrpe.cfg 
mv check_nwstat.cfg-sample  check_nwstat.cfg

使用PNPnagios 需要对nagios进行四个方面的配置。

  • 修改nagios.cfg文件,启动处理性能数据分析。
  • 修改command.cfg文件,添加host和service性能数据处理命令。
  • 修改templates.cfg文件,添加host和service 的模版定义。
  • 修改相应的host和service 定义添加templates.cfg文件中定义相应模版。

PNP4nagios 的5种工作模式(单从配置文件方面来看区别仅在nagios和commands两个文件的调整)

1、sysnchronous模式 是一种最简单,最容易设置的方式,对于每一个被处理的service 和 host 来说,nagios 将会调用各自的Perl脚本命令process_perfdata.pl ,并且处理数据。在这种模式下工作非常好,没5分钟可以处理1000多个服务。

Synchronous Mode

编辑nagios.cfg文件

vim /usr/local/nagios/etc/nagios.cfg
process_performance_data=1
enable_environment_macros=1
host_perfdata_command=process-host-perfdata
service_perfdata_command=process-service-perfdata

在不需要处理的性能数据的host或者server中添加添加一下指令

define host{
...
process_perf_data 0
...
}

define service{
...
process_perf_data 0
...
}

编辑commands.cfg,让nagios识别PNP4nagios!

vim /usr/local/nagios/etc/objects/commands.cfg
#添加下面两行在文件的末行 ,并删除或注释掉原有对process-host-perfdata和process-service-perfdata进行定义的字段 
define command{
command_name process-service-perfdata-pnp4nagios
command_line /usr/local/pnp4nagios/libexec/process_perfdata.pl
}
define command{
command_name process-host-perfdata-pnp4nagios
command_line /usr/local/pnp4nagios/libexec/process_perfdata.pl -d HOSTPERFDATA
}

编辑templates.cfg 文件,结尾处添加,让监控的主机和服务能继承使用PNP4nagios
vim /usr/local/nagios/etc/objects/templates.cfg

define host {
name host-pnp
action_url    /pnp4nagios/index.php/graph?host=$HOSTNAME$&srv=_HOST_' class='tips' rel='/pnp4nagios/index.php/popup?host=$HOSTNAME$&srv=_HOST_ 
register 0
}

define service {
name srv-pnp
action_url   /pnp4nagios/index.php/graph?host=$HOSTNAME$&srv=$SERVICEDESC$' class='tips' rel='/pnp4nagios/index.php/popup?host=$HOSTNAME$&srv=$SERVICEDESC$ 
register 0
}

复制鼠标悬浮信息图标素材

#进入安装源码包目录
cd /usr/local/src/pnp4nagios-0.6.24
#复制到安装目录
cp contrib/ssi/* /usr/local/nagios/share/ssi/

编辑自定义过的主机模版和服务模版,集成显示性能监控图。

;主机模版下use字段后添加host-pnp
define host{
use linux-server,host-pnp ;继承linux-server主机模版
host_name mysql-master-1 ;主机名
alias mysql-master ;主机别名
address 192.168.163.130 ;主机IP地址
}

;服务模版下use字段后添加srv-pnp
define service {
use generic-service,srv-pnp
host_name mysql-master-1
service_description MYSQLD
check_command check_mysqld!nagios!nagios
}

检测这种模式下配置是否有错误

perl verify_pnp_config --mode sync --config=/usr/local/nagios/etc/nagios.cfg --pnpcfg=/usr/local/pnp4nagios/etc/

然后重启nagios和pnp4nagios

/etc/init.d/nagios restart
/etc/init.d/ncpd restart

效果图:

pnp4nagios鼠标悬浮

 

pnp4nagios效果图

2、Bluk 模式 nagios会将必要的数据写入一个零食文件,在对该文件定义的生存期满时,文件会被处理一部分,并且会删除被处理的文件内容。这种方式使得调用脚本命令 process_perfdata.pl 的次数降低一小部分,其降低的幅度依赖于文件的生存期时间和收集的数据量。在这种模式下,process_perfdata.pl 的运行时间,因为在运行时处理数据的nagios将不会执行任何检查。

先修改nagios.cfg

process_performance_data=1
#
# service performance data
#
service_perfdata_file=/usr/local/pnp4nagios/var/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/pnp4nagios/var/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

修改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
}

3、NPCD的Bulk 从nagios角度来看,这是最好的一种处理方式,因为这种方式不会对nagios造成粗赛。在这种方式中,nagios再次使用了临时文件来存储数据,并且在文件生存期满的某一时间执行命令处理该文件中的数据。取而代之由 process_perfdata.pl 立即处理该文件,其方法是将它地洞到spool 目录。由于是在同一个文件系统中移动文件,因此几乎不会花费时间。nagios能够立即执行重要的工作。NPCD守护进程将会监控这个目录,对于新添加的文件将会把它的文件传递给 process_perfdata.pl 处理,每一个被添加到该目录的文件都会有一个时间戳,这种方式使得处理性能数据与nagios完全分离。另外,NPCD自身能够启用多线程处理性能数据。

先修改nagios.cfg

process_performance_data=1

#
# service performance data
#
service_perfdata_file=/usr/local/pnp4nagios/var/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/pnp4nagios/var/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

然后修改command.cfg

define command{
command_name process-service-perfdata-file
command_line /bin/mv /usr/local/pnp4nagios/var/service-perfdata /usr/local/pnp4nagios/var/spool/service-perfdata.$TIMET$
}

define command{
command_name process-host-perfdata-file
command_line /bin/mv /usr/local/pnp4nagios/var/host-perfdata /usr/local/pnp4nagios/var/spool/host-perfdata.$TIMET$
}

用守护进程的方式启动

/usr/local/pnp4nagios/bin/npcd -d -f /usr/local/pnp4nagios/etc/npcd.cfg

4、使用npcdmod的Bluk模式,这个模式包括了npcdmod.o模块,这是NEB-module,该模块减少了在“使用NPCD的Bluk模式”下在nagios,cfg配置文件中的两行配置。这种模式类似使用“NPCD的Bluk模式”并且功能相同,性能也相同。

修改nagios.cfg

process_performance_data=1
broker_module=/usr/local/pnp4nagios/lib/npcdmod.o config_file=/usr/local/pnp4nagios/etc/npcd.cfg

5、Gearman模式。齿轮工作者模式,这种工作模式适合大型nagios工作环境。

要使用这种模式请阅读

https://labs.consol.de/lang/en/nagios/mod-gearman/

 

特别注意:pnp4nagios的几种模式,在配置方面的区别体现在commands和nagios文件中。详情可以参考:

https://<监控主机IP>/pnp4nagios/docs/view/en_US/config

这里有详细的配置和说明

赞(0)
未经允许不得转载:菜鸟HOW站长 » 编译安装 nagios PNP4nagios rrdtool 绘制监控图文信息(提升)
分享到: 更多 (0)

留下你的脚印

  订阅  
关注动态