- 安装配置Apache、PHP(忽略此次安装步骤)
- 安装nagios
rpm -Uvh http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm
rpm -Uvh http://rpms.famillecollet.com/enterprise/remi-release-6.rpm
yum -y install nagios nagios-plugins-all nagios-plugins-nrpe nrpe php httpd bc - 创建密码文件
htpasswd -c /etc/nagios/passwd nagiosadmin
(此步完成即可通过Web访问Nagios)
http://yourip/nagios - 安装PNPNagios
yum -y install perl-Time-HiRes pnp4nagios
若提示没有pnp4nagios软件包
yum -y groupinstall "Development Tools"
wget https://sourceforge.net/projects/pnp4nagios/files/latest
mv latest pnp4nagios-Version.tar.gz
tar -xvzf pnp4nagios-Version.tar.gz
yum -y install rrdtool rrdtool-perl
cd pnp4nagios-0.6.25
./configure
make all
make fullinstall
mv /usr/local/pnp4nagios/share/install.php /usr/local/pnp4nagios/share/install.php.ignore
ln -s /usr/local/pnp4nagios/ /var/www/html/pnp4nagios - 修改 /etc/nagios/nagios.cfg
process_performance_data=1 // 将0 修改为 1
host_perfdata_command=process-host-perfdata // 取消注释
service_perfdata_command=process-service-perfdata // 取消注释 -
修改 /etc/nagios/objects/commands.cfg (注释默认配置再添加)
define command { command_name process-service-perfdata command_line /usr/bin/perl /usr/local/pnp4nagios/libexec/process_perfdata.pl } define command { command_name process-host-perfdata command_line /usr/bin/perl /usr/local/pnp4nagios/libexec/process_perfdata.pl -d HOSTPERFDATA }
-
修改 /etc/nagios/cgi.cfg 里的用户名是无效的
default_user_name=nagiosadmin -
修改 /etc/httpd/conf.d/pnp4nagios.conf
#AuthUserFile /usr/local/nagios/etc/htpasswd.users # 注释这一行
AuthUserFile /etc/nagios/passwd # 添加此行 -
重启nagios 和 apache
chkconfig httpd on
chkconfig nrpe on
chkconfig npcd on
chkconfig nagios on
打开 http://yourip/pnp4nagios/ 即可看到pnp图 - 添加pnp4nagios记录模版
修改/etc/nagios/objects/templates.cfg,添加如下内容
define host { name host-pnp action_url /pnp4nagios/index.php/graph?host=$HOSTNAME$'class='tips'rel='/pnp4nagios/index.php/popup?host=$HOSTNAME$&srv=_HOST_ register 0 process_perf_data 1 } 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 process_perf_data 1 }
- 在host和service定义中使用pnp4nagios模版
编辑localhost.cfg文件,vi /etc/nagios/objects/localhost.cfg
将use linux-server 修改为 use linux-server,host-pnp
将use local-services修改为 use local-services,srv-pnp
被监控机需要显示pnp按钮,修改vi /etc/nagios/objects/services.cfgdefine host{ use linux-server,hosts-pnp host_name localhost alias localhost address 127.0.0.1 } define service{ use local-service,srv-pnp host_name localhost service_description PING check_command check_ping!100.0,20%!500.0,60% }
将use local-services修改为 use local-services,srv-pnp - 出现的问题
关闭 selinux
setenforce 0
sed -i "s/SELINUX=enforcing/SELINUX=disabled/g" /etc/selinux/config
sed -i "s/SELINUXTYPE=targeted/#SELINUXTYPE=targeted/g" /etc/selinux/config -
参考文档:
https://www.digitalocean.com/community/tutorials/how-to-install-nagios-on-centos-6
http://geekpeek.net/pnp4nagios-centos-install/
http://blog.csdn.net/tch8502/article/details/22151525
http://www.huangzhongzhang.cn/nagios-pnp4nagios-an-zhuang-bi-ji.html