设为首页 收藏本站
查看: 837|回复: 0

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

[复制链接]

尚未签到

发表于 2019-1-12 13:17:24 | 显示全部楼层 |阅读模式
  一、安装环境
  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
    [root@localhost objects]# 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
  
  [root@bogon ~]# /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恢复正常(我出错之前的配置并不是这样的),重启完要等一会才能看到图的。


  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服务。
  [root@m ~]# service nagios restart
  [root@m ~]# service httpd restart
  
  文章转载自:http://www.cnblogs.com/derekchen/p/3783105.html 转载请注明出处。
  
  
  
  
  
  
  
  
  
  
  
  



运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-662393-1-1.html 上篇帖子: Linux下nagios的搭建及相关配置 下篇帖子: nagios 草稿
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表