nagios+pnp4nagios系列文章(三) 安装配置及rrdtool出图最详细配置,解决途中遇到的各种问题!!!

Server环境。
1、先处理个别问题:
1-1、HTTP和SSH服务提示:Notifications for this service have been disabled。
处理办法:
[root@HAD06 nagios]#  vim /usr/local/nagios/etc/objects/localhost.cfg
在HTTP服务和SSH服务中找到
notifications_enabled           0
修改成:
notifications_enabled           1
[root@HAD06 nagios]#   service nagios restart
2、安装rrdtool:
[root@HAD06 nagios]# cd /usr/local/src/
[root@HAD06 nagios]#  yum install pango*                --必须执行,否则无法编译成功。
[root@HAD06 src]#  tar -zxvf rrdtool-1.4.5.tar.gz
[root@HAD06 src]#  cd rrdtool-1.4.5
[root@HAD06 rrdtool-1.4.5]#  ./configure --prefix=/usr/local/rrdtool --disable-python --disable-tcl
[root@HAD06 rrdtool-1.4.5]#  make
[root@HAD06 rrdtool-1.4.5]#  make install
3、安装pnp4nagios:
[root@HAD06 rrdtool-1.4.5]#  cd ../
[root@HAD06 src]#  tar -zxvf pnp4nagios-0.6.22.tar.gz 
[root@HAD06 src]#  cd pnp4nagios-0.6.22
[root@HAD06 pnp4nagios-0.6.22]#  yum install perl-Time-HiRes
[root@HAD06 pnp4nagios-0.6.22]#  ./configure --prefix=/usr/local/pnp4nagios --with-nagios --with-rrdtool=/usr/local/rrdtool/bin/rrdtool
[root@HAD06 pnp4nagios-0.6.22]#  make all
[root@HAD06 pnp4nagios-0.6.22]#  make install
[root@HAD06 pnp4nagios-0.6.22]#  make install-webconf
[root@HAD06 pnp4nagios-0.6.22]#  make install-config
[root@HAD06 pnp4nagios-0.6.22]#  make install-init
4、添加相关配置文件:
[root@HAD06 pnp4nagios-0.6.22]#  cd /usr/local/pnp4nagios/etc/
[root@HAD06 etc]#  cp misccommands.cfg-sample misccommands.cfg
[root@HAD06 etc]#  cp nagios.cfg-sample nagios.cfg
[root@HAD06 etc]#  cp rra.cfg-sample rra.cfg
[root@HAD06 etc]#  cd pages/
[root@HAD06 pages]#  cp web_traffic.cfg-sample web_traffic.cfg
[root@HAD06 pages]#  cd ../check_commands/
[root@HAD06 check_commands]#  cp check_all_local_disks.cfg-sample check_all_local_disks.cfg
[root@HAD06 check_commands]#  cp check_nrpe.cfg-sample check_nrpe.cfg
[root@HAD06 check_commands]#  cp check_nwstat.cfg-sample check_nwstat.cfg
5、配置nagios启用PNP:
[root@HAD06 check_commands]#  vim /usr/local/nagios/etc/nagios.cfg
找到:
process_performance_data=0                                                             --831行
#host_perfdata_command=process-host-perfdata                           --843行
#service_perfdata_command=process-service-perfdata                   --844行
修改成:
process_performance_data=1
host_perfdata_command=process-host-perfdata
service_perfdata_command=process-service-perfdata
同时,需要确保:
enable_environment_macros=1  (默认配置)
#把pnp4nagios执行数据收集的文件拷贝到nagios的libexec目录下,方便统一命令的执行路径。
[root@HAD06 check_commands]#  cp /usr/local/pnp4nagios/libexec/process_perfdata.pl /usr/local/nagios/libexec/
#设定同步模式。
[root@HAD06 check_commands]#  vim /usr/local/nagios/etc/objects/commands.cfg
注意在这个文件里面可能已经存在这两个命令的配置了,就把原来的两个配置注释掉,然后添加下面两个命令配置。
define command{
       command_name    process-host-perfdata
       #command_line    $USER1$/process_perfdata.pl -d HOSTPERFDATA
       #command_line    /usr/bin/perl /usr/local/pnp4nagios/libexec/process_perfdata.pl -d HOSTPERFDATA
       command_line    /usr/local/pnp4nagios/libexec/process_perfdata.pl -d HOSTPERFDATA
       }

define command{
       command_name    process-service-perfdata
       command_line    /usr/local/pnp4nagios/libexec/process_perfdata.pl
       }
[ root@HAD06  check_commands]#  vim /usr/local/nagios/etc/objects/templates.cfg
添加:
define host{
        name                    host-pnp4
        action_url              /pnp4nagios/index.php/graph?host=$HOSTNAME$&srv=_HOST_' class='tips' rel='/pnp4nagios/index.php/popup?host=$HOSTNAME$&srv=_HOST_
        register                0
        }
--host-pnp4这个host模板后面会引用到。

define service{
        name                    svr-pnp4
        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
        }
--注意:svr-pnp4这个sevice模板后面会引用到。
在localhost.cfg配置项中,host后面添加host-pnp4模板,service后面添加svr-pnp4模板。【host-pnp4和svr-pnp4取自/usr/local/nagios/etc/objects/templates.cfg文件。
添加host-pnp4模板的方法如下【注意使用逗号分隔】:
添加svr-pnp4模板的方法如下【注意使用逗号分隔】:
将所有需要显示图形的service中都添加svr-pnp4模板。
[root@HAD06 check_commands]#  chown nagios.nagios /usr/local/nagios/libexec/*
[root@HAD06 check_commands]#  ll /usr/local/nagios/libexec/
总用量 5520
-rwxr-xr-x. 1 nagios nagios 376588 1月  15 22:39 check_apt
-rwxr-xr-x. 1 nagios nagios   2245 1月  15 22:39 check_breeze
-rwxr-xr-x. 1 nagios nagios 128464 1月  15 22:39 check_by_ssh
lrwxrwxrwx. 1 root   root        9 1月  15 22:39 check_clamd -> check_tcp
-rwxr-xr-x. 1 nagios nagios  85750 1月  15 22:39 check_cluster
-r-xr-xr-x. 1 nagios nagios 123803 1月  15 22:39 check_dhcp
-rwxr-xr-x. 1 nagios nagios 417943 1月  15 22:39 check_disk
-rwxr-xr-x. 1 nagios nagios   9148 1月  15 22:39 check_disk_smb
-rwxr-xr-x. 1 nagios nagios  80753 1月  15 22:39 check_dummy
-rwxr-xr-x. 1 nagios nagios   3056 1月  15 22:39 check_file_age
-rwxr-xr-x. 1 nagios nagios   6318 1月  15 22:39 check_flexlm
lrwxrwxrwx. 1 root   root        9 1月  15 22:39 check_ftp -> check_tcp
-rwxr-xr-x. 1 nagios nagios 519237 1月  15 22:39 check_http
-r-xr-xr-x. 1 nagios nagios 133889 1月  15 22:39 check_icmp
-rwxr-xr-x. 1 nagios nagios  93472 1月  15 22:39 check_ide_smart
-rwxr-xr-x. 1 nagios nagios  15137 1月  15 22:39 check_ifoperstatus
-rwxr-xr-x. 1 nagios nagios  12601 1月  15 22:39 check_ifstatus
lrwxrwxrwx. 1 root   root        9 1月  15 22:39 check_imap -> check_tcp
-rwxr-xr-x. 1 nagios nagios   6890 1月  15 22:39 check_ircd
lrwxrwxrwx. 1 root   root        9 1月  15 22:39 check_jabber -> check_tcp
-rwxr-xr-x. 1 nagios nagios 106637 1月  15 22:39 check_load
-rwxr-xr-x. 1 nagios nagios   6020 1月  15 22:39 check_log
-rwxr-xr-x. 1 nagios nagios  20287 1月  15 22:39 check_mailq
-rwxr-xr-x. 1 nagios nagios  93198 1月  15 22:39 check_mrtg
-rwxr-xr-x. 1 nagios nagios  92543 1月  15 22:39 check_mrtgtraf
-rwxr-xr-x. 1 nagios nagios 116435 1月  15 22:39 check_mysql
-rwxr-xr-x. 1 nagios nagios 109929 1月  15 22:39 check_mysql_query
-rwxr-xr-x. 1 nagios nagios 105670 1月  15 22:39 check_nagios
lrwxrwxrwx. 1 root   root        9 1月  15 22:39 check_nntp -> check_tcp
lrwxrwxrwx. 1 root   root        9 1月  15 22:39 check_nntps -> check_tcp
-rwxrwxr-x. 1 nagios nagios  75476 1月  15 23:48 check_nrpe
-rwxr-xr-x. 1 nagios nagios 127879 1月  15 22:39 check_nt
-rwxr-xr-x. 1 nagios nagios 130270 1月  15 22:39 check_ntp
-rwxr-xr-x. 1 nagios nagios 119359 1月  15 22:39 check_ntp_peer
-rwxr-xr-x. 1 nagios nagios 117920 1月  15 22:39 check_ntp_time
-rwxr-xr-x. 1 nagios nagios 159564 1月  15 22:39 check_nwstat
-rwxr-xr-x. 1 nagios nagios   8324 1月  15 22:39 check_oracle
-rwxr-xr-x. 1 nagios nagios 109094 1月  15 22:39 check_overcr
-rwxr-xr-x. 1 nagios nagios 132859 1月  15 22:39 check_ping
lrwxrwxrwx. 1 root   root        9 1月  15 22:39 check_pop -> check_tcp
-rwxr-xr-x. 1 nagios nagios 396897 1月  15 22:39 check_procs
-rwxr-xr-x. 1 nagios nagios 106692 1月  15 22:39 check_real
-rwxr-xr-x. 1 nagios nagios   9584 1月  15 22:39 check_rpc
-rwxr-xr-x. 1 nagios nagios   1412 1月  15 22:39 check_sensors
lrwxrwxrwx. 1 root   root        9 1月  15 22:39 check_simap -> check_tcp
-rwxr-xr-x. 1 nagios nagios 445238 1月  15 22:39 check_smtp
lrwxrwxrwx. 1 root   root        9 1月  15 22:39 check_spop -> check_tcp
-rwxr-xr-x. 1 nagios nagios 103192 1月  15 22:39 check_ssh
lrwxrwxrwx. 1 root   root        9 1月  15 22:39 check_ssmtp -> check_tcp
-rwxr-xr-x. 1 nagios nagios 108273 1月  15 22:39 check_swap
-rwxr-xr-x. 1 nagios nagios 159057 1月  15 22:39 check_tcp
-rwxr-xr-x. 1 nagios nagios 105222 1月  15 22:39 check_time
lrwxrwxrwx. 1 root   root        9 1月  15 22:39 check_udp -> check_tcp
-rwxr-xr-x. 1 nagios nagios 117750 1月  15 22:39 check_ups
-rwxr-xr-x. 1 nagios nagios  83490 1月  15 22:39 check_users
-rwxr-xr-x. 1 nagios nagios   2939 1月  15 22:39 check_wave
-rwxr-xr-x. 1 nagios nagios 109779 1月  15 22:39 negate
-rwxr-xr-x. 1 nagios nagios  54519 1月  23 00:37 process_perfdata.pl
-rwxr-xr-x. 1 nagios nagios 103306 1月  15 22:39 urlize
-rwxr-xr-x. 1 nagios nagios   1904 1月  15 22:39 utils.pm
-rwxr-xr-x. 1 nagios nagios   2728 1月  15 22:39 utils.sh
测试nagios配置文件是否正确:
[root@HAD06 check_commands]#  /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg
#启动NPCD,以daemon方式运行。
[root@HAD06 check_commands]#  /usr/local/pnp4nagios/bin/npcd -d -f /usr/local/pnp4nagios/etc/npcd.cfg 
[root@HAD06 check_commands]#  echo '/usr/local/pnp4nagios/bin/npcd -d -f /usr/local/pnp4nagios/etc/npcd.cfg'>>/etc/rc.local 
#配置nginx,支持网页显示。
[root@HAD06 check_commands]#  vim /usr/local/nginx/conf/nginx.conf
在前面你添加进去那个server 添加以下内容:
     location /pnp4nagios
        {
                alias /usr/local/pnp4nagios/share;
                index index.php;
                try_files $uri $uri/ @pnp4nagios;
        }

      location @pnp4nagios
         {
                fastcgi_pass  127.0.0.1:9000;
                fastcgi_index index.php;
                fastcgi_split_path_info ^(.+\.php)(.*)$;
                fastcgi_param PATH_INFO $fastcgi_path_info;
                include fastcgi_params;
                fastcgi_param SCRIPT_FILENAME /usr/local/pnp4nagios/share/index.php;
          }

测试nginx配置文件是否正确:
[root@HAD06 check_commands]#  /usr/local/nginx/sbin/nginx -t
[root@HAD06 check_commands]#  service nagios restart
[root@HAD06 check_commands]#  /usr/local/nginx/sbin/nginx -s reload
[root@HAD06 check_commands]#  service php-fpm restart    --可不执行。
重启两个服务后,在 /usr/local/pnp4nagios/var/perfdata/目录下会产生被监控主机(这里指localhost)的pnp文件目录。
打开相应的主机或服务, 点击nagios对应主机或服务旁的图示,出现如下图示:
按照提示把/usr/local/pnp4nagios/share/install.php文件重命名。
[root@HAD06 check_commands]#  mv /usr/local/pnp4nagios/share/install.php /usr/local/pnp4nagios/share/install.php.bak

刷新页面,


备注:
生成的rrd而文件在 /usr/local/pnp4nagios/var/perfdata/localhost/目录下。
[root@HAD06 check_commands]#  ll /usr/local/pnp4nagios/var/perfdata/localhost/
总用量 4996
-rw-rw-r--. 1 nagios nagios 1151504 1月  23 21:54 Current_Load.rrd
-rw-rw-r--. 1 nagios nagios   13373 1月  23 21:54 Current_Load.xml
-rw-rw-r--. 1 nagios nagios  384960 1月  23 21:55 Current_Users.rrd
-rw-rw-r--. 1 nagios nagios   11928 1月  23 21:55 Current_Users.xml
-rw-rw-r--. 1 nagios nagios  768232 1月  23 21:54 _HOST_.rrd
-rw-rw-r--. 1 nagios nagios   12260 1月  23 21:54 _HOST_.xml
-rw-rw-r--. 1 nagios nagios  768232 1月  23 21:53 HTTP.rrd
-rw-rw-r--. 1 nagios nagios   12527 1月  23 21:53 HTTP.xml
-rw-rw-r--. 1 nagios nagios  768232 1月  23 21:56 PING.rrd
-rw-rw-r--. 1 nagios nagios   12583 1月  23 21:56 PING.xml
-rw-rw-r--. 1 nagios nagios  384960 1月  23 21:52 Root_Partition.rrd
-rw-rw-r--. 1 nagios nagios   11977 1月  23 21:52 Root_Partition.xml
-rw-rw-r--. 1 nagios nagios  384960 1月  23 21:52 SSH.rrd
-rw-rw-r--. 1 nagios nagios   11857 1月  23 21:52 SSH.xml
-rw-rw-r--. 1 nagios nagios  384960 1月  23 21:53 Swap_Usage.rrd
-rw-rw-r--. 1 nagios nagios   11923 1月  23 21:53 Swap_Usage.xml


linux技术交流群:295294329   本文朋友郭工整理,感谢他的共享!!!
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值