监控主机安装PNP
重要提醒:看清楚你要安装的pnp4nagios的版本,因为0.4和0.6的配置方式是不一致的
配置开发环境
[root@localhost ~]# yum install rrdtool librrds-perl -y
安装pnp4nagios (版本号为0.6)
进入到/usr/local/src目录下开始执行下面的命令
[root@localhost src]# tar zxf pnp4nagios-0.6.25.tar.gz
[root@localhost src]# cd pnp4nagios-0.6.25
[root@localhost pnp4nagios-0.6.25]# ./configure --with-nagios-user=nagios --with-nagios-group=nagios
[root@localhost pnp4nagios-0.6.25]# make all
[root@localhost pnp4nagios-0.6.25]# make install
[root@localhost pnp4nagios-0.6.25]# make install-webconf
[root@localhost pnp4nagios-0.6.25]# make install-config
[root@localhost pnp4nagios-0.6.25]# make install-init
[root@localhost pnp4nagios-0.6.25]# cd ./sample-config
[root@localhost pnp4nagios-0.6.25]# make install-webconf
配置pnp4nagios
[root@localhost pnp4nagios-0.6.25]# cd /usr/local/pnp4nagios/etc/
[root@localhost etc]# mv misccommands.cfg-sample misccommands.cfg
[root@localhost etc]# mv rra.cfg-sample rra.cfg
[root@localhost etc]# mv nagios.cfg-sample nagios.cfg
[root@localhost etc]# cd pages/
[root@localhost pages]# mv web_traffic.cfg-sample web_traffic.cfg
[root@localhost pages]# cd ../check_commands/
[root@localhost check_commands]# mv check_all_local_disks.cfg-sample check_all_local_disks.cfg
[root@localhost check_commands]# mv check_nrpe.cfg-sample check_nrpe.cfg
[root@localhost check_commands]# mv check_nwstat.cfg-sample check_nwstat.cfg
[root@localhost check_commands]# /etc/init.d/npcd start
[root@localhost check_commands]# chkconfig npcd on
配置Nagios数据输出接口(以BULK模式运行)详情参考官网:
[root@localhost ~]# vi /usr/local/nagios/etc/nagios.cfg
process_performance_data=1 #默认为0,修改为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
[root@localhost ~]# 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
}
在模板配置文件中添加图表图标模板:
[root@localhost ~]# vi /usr/local/nagios/etc/objects/templates.cfg
在该文件中添加下面的内容
define host {
name host-pnp
action_url /pnp4nagios/index.php/graph?host=$HOSTNAME$&srv=_HOST_
register 0
}
define service {
name service-pnp
action_url /pnp4nagios/index.php/graph?host=$HOSTNAME$&srv=$SERVICEDESC$
register 0
}
在监控主机和服务中调用图表模板(在主机和服务后面添加新的模板):
[root@localhost ~]# vi /usr/local/nagios/etc/objects/localhost.cfg
按下面的内容修改(不是添加)该文件
define host{
use linux-server,host-pnp
host_name localhost
alias localhost
address 127.0.0.1
}
define service{
use local-service,service-pnp
host_name localhost
service_description PING
check_command check_ping!100.0,20%!500.0,60%
}
define service{
use local-service,service-pnp
host_name localhost
service_description Root Partition
check_command check_local_disk!20%!10%!/
}
…
图表展示
重启nagios和apache
[root@localhost ~]# systemctl restart nagios.service
[root@localhost ~]# systemctl restart httpd.service
访问nagios界面即可看到图表小图标:
点击图标会显示pnp4nagios测试页面:
全是绿色代表配置正常,如果不是全绿,要逐个解决错误。然后移除或修改install.php文件:
[root@localhost ~]# rm -rf /usr/local/pnp4nagios/share/install.php
再次点击图标就会显示当前监控服务由pnp4nagios生成的图表了:
至此,nagios监控主机的出图配置已经全部完成。