天堂1111 发表于 2019-1-12 13:17:24

centos6.8使用yum安装nagios&pnp4nagios服务

  一、安装环境
  1.Centos6.8
  2.关闭iptables防火墙
  二、安装nagios服务器端:
  1. rpm -Uvh http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm
  2. yum -y install nagios nagios-plugins-all nagios-plugins-nrpe nrpe php
  3. chkconfig httpd on && chkconfig nagios on
  4. service httpd start && service nagios start
  5. 设置nagiosadmin密码: htpasswd -c /etc/nagios/htpasswd.users nagiosadmin
  6. 登陆: http://{your_ip_address}/nagios 输入密码
  三、安装pnp4nagios:
  1. yum install pnp4nagios rrdtool
  四、配置pnp4nagios:
  1.修改nagios.cfg
    # vim /etc/nagios/nagios.cfg    //修改以下内容  
    process_performance_data=1                           //由0改为1
  
    host_perfdata_command=process-host-perfdata            //前面的注释拿掉
  
    service_perfdata_command=process-service-perfdata      //注释拿掉
  
    enable_environment_macros=1                            //如果有注释拿掉
  2,修改commands.cfg
  注释掉原有对process-host-perfdata和process-service-perfdata,重新定义
  vim /etc/nagios/objects/commands.cfg
  define command{
  command_name    process-host-perfdata
  command_line    /usr/libexec/pnp4nagios/process_perfdata.pl -d HOSTPERFDATA
  }
  define command{
  command_name    process-service-perfdata
  command_line    /usr/libexec/pnp4nagios/process_perfdata.pl
  }
  3.修改配置文件templates.cfg
  vim /etc/nagios/objects/templates.cfg
  
  define host{
  name                  hosts-pnp
  register                0
  action_url/pnp4nagios/index.php/graph?host=$HOSTNAME$&srv=_HOST_
  process_perf_data
  }
  define service{
  name    srv-pnp
  register   0
  action_url/pnp4nagios/index.php/graph?host=$HOSTNAME$&srv=$SERVICEDESC$
  process_perf_data
  }
  
  4,修改服务器配置文件localhost.cfg
  vim /etc/nagios/objects/localhost.cfg
  define 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%
  }
  
  5,重启nagios,启动npcd
  
  /etc/init.d/npcd restart
  /etc/init.d/nagios restart
  六。 配置调试命令
  
  /usr/sbin/nagios -v /etc/nagios/nagios.cfg
  
  # /usr/sbin/nagios -v /etc/nagios/nagios.cfg
  Nagios Core 3.5.1
  Copyright (c) 2009-2011 Nagios Core Development Team and Community Contributors
  Copyright (c) 1999-2009 Ethan Galstad
  Last Modified: 08-30-2013
  License: GPL
  Website: http://www.nagios.org
  Reading configuration data...
  Read main config file okay...
  Processing object config file '/etc/nagios/objects/commands.cfg'...
  Processing object config file '/etc/nagios/objects/contacts.cfg'...
  Processing object config file '/etc/nagios/objects/timeperiods.cfg'...
  Processing object config file '/etc/nagios/objects/templates.cfg'...
  Processing object config file '/etc/nagios/objects/localhost.cfg'...
  Processing object config file '/etc/nagios/objects/switch.cfg'...
  Processing object config directory '/etc/nagios/conf.d'...
  Read object config files okay...
  Running pre-flight check on configuration data...
  Checking services...
  Checked 16 services.
  Checking hosts...
  Checked 3 hosts.
  Checking host groups...
  Checked 2 host groups.
  Checking service groups...
  Checked 0 service groups.
  Checking contacts...
  Checked 1 contacts.
  Checking contact groups...
  Checked 1 contact groups.
  Checking service escalations...
  Checked 0 service escalations.
  Checking service dependencies...
  Checked 0 service dependencies.
  Checking host escalations...
  Checked 0 host escalations.
  Checking host dependencies...
  Checked 0 host dependencies.
  Checking commands...
  Checked 25 commands.
  Checking time periods...
  Checked 5 time periods.
  Checking for circular paths between hosts...
  Checking for circular host and service dependencies...
  Checking global event handlers...
  Checking obsessive compulsive processor commands...
  Checking misc settings...
  Total Warnings: 0
  Total Errors:   0
  Things look okay - No serious problems were detected during the pre-flight check
  
  七、问题总结
  
  1.安装过程很顺利,但是在配置完成后,重启nagios服务时出现报错,大概意思就是配置文件错误,请检查配置文件(Invalid object definition type ' host' in file '/etc/nagios/objects/template)。使用/usr/sbin/nagios -v /etc/nagios/nagios.cfg命令检查,发现templates.cfg 文件配置错误,后来一直检查也没发现问题,最后发现问题出在字体格式上面,因为我是直接从网页上复制黏贴的,服务器可能无法识别字体或者特殊符号(手动敲一遍,问题解决。。。汗)
  2.nagios重启完成后,登录网页,可以看到如下图所示,点击网络表格的图表,没有弹出页面图表,报错信息如下:"/var/lib/pnp4nagios/localhost" for host "localhost" does not exist,将commands.cfg更改为上面的内容后,重启nagios恢复正常(我出错之前的配置并不是这样的),重启完要等一会才能看到图的。
https://s1.运维网.com/wyfs02/M01/93/A6/wKioL1kK_cfQ4rSGAAB05cZSdd4835.png
https://s3.运维网.com/wyfs02/M01/93/AA/wKioL1kK_4SwK6YNAAKyyTGFMsY708.png
  3.将服务迁移到生产机器时(之前是在测试机上进行测试的),发现配置完成后,打开网页,点击图标图标时,弹出的页面提示:The requested URL /pnp4nagios/index.php/graph was not found on this server.提示页面无法找到。
  解决方法:打开vim /etc/httpd/conf.d/pnp4nagios.conf,将里面的代码完全拷贝,打开vim /etc/httpd/conf/httpd.conf,将拷贝的代码粘贴到文件的最下方,然后重启nagios和apache服务。
  # service nagios restart
  # service httpd restart
  
  文章转载自:http://www.cnblogs.com/derekchen/p/3783105.html 转载请注明出处。
  。
  
  
  
  
  
  
  
  
  
  
  


页: [1]
查看完整版本: centos6.8使用yum安装nagios&pnp4nagios服务