nagios监控网络服务器和网络服务故障解决篇

安全 网站安全
nagios是一个完全GPL协议的开源软件包,包含有nagios主程序和它的各个插件,配置非常灵活,可以监视的项目很多,可以自定义shell脚本进行监控服务,非常适合大型网络。那么在nagios添加主机和服务可能出现的问题该如何解决?

nagios添加主机和服务可能出现的问题有如下情况:

1:配置参数出现问题,如果你没有检查配置就启动nagios,可能会启动成功,但是显示会不正常;

解决方法:调整配置参数

2:Connection refused

当出现这个问题的时候,我开始以为是ssh的无密码登录没有成功,但是其实我的服务器没有启动该服务造成的,启动服务即可。但是这些是有端口的服务,没有使用端口的状态任何检测?使用nrpe,ok,我们现在在服务器上安装nrpe:

一、远程主机的配置 

1、安装nrpe与配置 

  1. fetch http://ufpr.dl.sourceforge.net/sourceforge/nagios/nrpe-2.5.2.tar.gz   
  2. tar zxvf nrpe-2.5.2.tar.gz   
  3. cd nrpe-2.5.2   
  4. ./configure --enable-ssl --enable-command-args    
  5. make all    
  6. mkdir -p /usr/local/nagios/etc   
  7. mkdir /usr/local/nagios/bin    
  8. mkdir /usr/local/nagios/libexec    
  9. pw addgroup nagios   
  10. pw useradd nagios -g nagios -d /usr/local/nagios/ -s /sbin/nologin    
  11. chown -R nagios:nagios /usr/local/nagios    
  12. cp ./sample-config/nrpe.cfg /usr/local/nagios/etc    
  13. cp src/nrpe /usr/local/nagios/bin   

2、启动nrpe,端口为5666 

  1. /usr/local/nagios/bin/nrpe -c /usr/local/nagios/etc/nrpe.cfg -d   
  2. netstat -ant | grep 5666   
  3. tcp4     0     0 *.5666           *.*             LISTEN  

二、监控服务器上的配置 

1、安装nrpe(主要是使用check_nrpe模块)

  1. fetch http://ufpr.dl.sourceforge.net/sourceforge/nagios/nrpe-2.5.2.tar.gz   
  2. tar zxvf nrpe-2.5.2.tar.gz   
  3. cd nrpe-2.5.2   
  4. ./configure --enable-ssl --enable-command-args   
  5. make all    
  6. cp src/check_nrpe /usr/local/nagios/libexec   

2、nagios文件的配置 

vi checkcommands.cfg 

定义check_nrpe命令

  1. # 'check_nrep' command definition   
  2. define command{   
  3.     command_name check_nrpe   
  4.     command_line /usr/local/nagios/libexec/check_nrpe -H $HOSTADDRESS$ -c $ARG1$    
  5.     }  

三、上面我们已经配置了一部分参数

下面是配置的最终结果:

  1. define host{   
  2.     use               generic-host         ; Name of host template to use   
  3.     host_name           test_nrpe   
  4.     alias             client   
  5.     address           10.5.1.156   
  6.     check_command       check-host-alive   
  7.     max_check_attempts     1   
  8.     check_period         24x7   
  9.     notification_interval   120   
  10.     notification_period   24x7   
  11.     notification_options   d,r   
  12.     contact_groups admins   
  13.     }   
  14.  
  15. # 'check_load' command definition   
  16. define command{   
  17.     command_name   check_load   
  18.     command_line   $USER1$/check_load -w $ARG1$ -c $ARG2$    
  19.     }   
  20.  
  21. # 'check_load' command definition   
  22. define command{   
  23.     command_name   check_disk   
  24.     command_line   $USER1$/check_disk -w $ARG1$ -c $ARG2$    
  25.     }   
  26. define service{   
  27.     use                   generic-service       ; Name of service template to use   
  28.     host_name               test_nrpe   
  29.     service_description         PING   
  30.     is_volatile               0   
  31.     check_period             24x7   
  32.     max_check_attempts         1   
  33.     normal_check_interval       1   
  34.     retry_check_interval         1   
  35.     contact_groups             admins   
  36.     notification_options         w,u,c,r   
  37.     notification_interval       960   
  38.     notification_period         24x7   
  39.     check_command             check_ping!100.0,20%!500.0,60%   
  40.     }   
  41.  
  42. define service{   
  43.     use                   generic-service       ; Name of service template to use   
  44.     host_name               test_nrpe   
  45.     service_description         apache   
  46.     is_volatile               0   
  47.     check_period             24x7   
  48.     max_check_attempts         1   
  49.     normal_check_interval       1   
  50.     retry_check_interval         1   
  51.     contact_groups             admins   
  52.     notification_options         w,u,c,r   
  53.     notification_interval       960   
  54.     notification_period         24x7   
  55.     check_command             check_http!100.0,20%!500.0,60%   
  56.     }   
  57.  
  58. define service{   
  59.     use                   generic-service       ; Name of service template to use   
  60.     host_name               test_nrpe   
  61.     service_description         mysql   
  62.     is_volatile               0   
  63.     check_period             24x7   
  64.     max_check_attempts         1   
  65.     normal_check_interval       1   
  66.     retry_check_interval         1   
  67.     contact_groups             admins   
  68.     notification_options         w,u,c,r   
  69.     notification_interval       960   
  70.     notification_period         24x7   
  71.     check_command             check_mysql!100.0,20%!500.0,60%   
  72.     }   
  73.  
  74. define service{   
  75.     use                   generic-service       ; Name of service template to use   
  76.     host_name               test_nrpe   
  77.     service_description         ntp    
  78.     is_volatile               0   
  79.     check_period             24x7   
  80.     max_check_attempts         1   
  81.     normal_check_interval       1   
  82.     retry_check_interval         1   
  83.     contact_groups             admins   
  84.     notification_options         w,u,c,r   
  85.     notification_interval       960   
  86.     notification_period         24x7   
  87.     check_command             check_ntp!100.0,20%!500.0,60%   
  88.     }   
  89.  
  90. define service{   
  91.     use                   generic-service       ; Name of service template to use   
  92.     host_name               test_nrpe   
  93.     service_description         qmail_smtp      
  94.     is_volatile               0   
  95.     check_period             24x7   
  96.     max_check_attempts         1   
  97.     normal_check_interval       1   
  98.     retry_check_interval         1   
  99.     contact_groups             admins   
  100.     notification_options         w,u,c,r   
  101.     notification_interval       960   
  102.     notification_period         24x7   
  103.     check_command             check_smtp!100.0,20%!500.0,60%    
  104.     }   
  105.  
  106. define service{   
  107.     use                   generic-service       ; Name of service template to use   
  108.     host_name               test_nrpe   
  109.     service_description         qmail_pop3      
  110.     is_volatile               0   
  111.     check_period             24x7   
  112.     max_check_attempts         1   
  113.     normal_check_interval       1   
  114.     retry_check_interval         1   
  115.     contact_groups             admins   
  116.     notification_options         w,u,c,r   
  117.     notification_interval       960   
  118.     notification_period         24x7   
  119.     check_command             check_pop!100.0,20%!500.0,60%    
  120.     }   
  121.  
  122. define service{   
  123.     use                   generic-service       ; Name of service template to use   
  124.     host_name               test_nrpe   
  125.     service_description         test_load   
  126.     is_volatile               0   
  127.     check_period             24x7   
  128.     max_check_attempts         1   
  129.     normal_check_interval       1   
  130.     retry_check_interval         1   
  131.     contact_groups             admins   
  132.     notification_options         w,u,c,r   
  133.     notification_interval       960   
  134.     notification_period         24x7   
  135.     check_command             check_load!100.0,20%!500.0,60%   
  136.     }   
  137.  
  138. define service{   
  139. use                   generic-service       ; Name of service template to use   
  140.     host_name               test_nrpe   
  141.     service_description         test_disk    
  142.     is_volatile               0   
  143.     check_period             24x7   
  144.     max_check_attempts         1   
  145.     normal_check_interval       1   
  146.     retry_check_interval         1   
  147.     contact_groups             admins   
  148.     notification_options         w,u,c,r   
  149.     notification_interval       960   
  150.     notification_period         24x7   
  151.     check_command             check_disk!100.0,20%!500.0,60%      
  152.     }  

四、检查配置参数并重启nagios

如何在nagios中使用外部命令

  1. vi /usr/local/nagios/etc/nagios.cfg   
  2. check_external_commands=1   
  3.  
  4. mkdir /usr/local/nagios/var/rw   
  5. chown nagios.nagcmd /usr/local/nagios/var/rw   
  6. chmod u+rw /usr/local/nagios/var/rw   
  7. chmod g+rw /usr/local/nagios/var/rw   
  8. chmod g+s /usr/local/nagios/var/rw   
  9.  
  10. svc -t /service/nagios/   
  11. /usr/local/apache2/bin/apachectl restart 

nagios监控网络服务器和网络服务问题的解决就结束了,有关nagios的基础内容您可以参考:概念篇安装篇配置篇

责任编辑:佚名 来源: ChinaUnix
相关推荐

2011-08-22 11:00:17

nagios

2011-08-22 11:00:14

nagios

2011-08-22 11:00:10

nagios

2011-03-22 15:17:14

Nagios安装

2011-03-22 15:17:13

Nagios监控

2011-03-22 15:17:14

Nagios安装

2011-03-21 11:21:04

LinuxNagios

2011-02-22 11:23:48

vsFTPDLinux服务器

2011-07-14 15:28:11

服务器

2014-06-26 14:10:44

2011-07-14 14:17:33

网络服务器配置DNS服务器

2011-09-05 09:23:50

2011-07-14 14:45:01

网络服务器配置DHCP服务器

2011-02-22 11:23:48

vsFTPDLinux服务器

2010-03-24 11:39:01

2011-07-14 14:58:19

网络服务器配置服务器

2011-03-22 13:50:53

2018-08-09 09:10:54

2011-07-14 14:01:29

网络服务器配置服务器

2012-10-25 13:57:46

点赞
收藏

51CTO技术栈公众号