联系客服:400-805-1963

yum安装nagios(centos 6.2)
更新:HHH   时间:2023-1-7


前提先自行安装好Apache+php
测试环境
主监控机:CentOS 6.2  172.16.1.8
被监控机:CentOS 6.2  172.16.5.11
主监控机设置:
1、安装epel
# cat /etc/issue
CentOS release 6.2 (Final)
Kernel \r on an \m
# rpm -ivh rpm -ivh http://dl.iuscommunity.org/pub/ius/stable/Redhat/6/x86_64/epel-release-6-5.noarch.rpm                         这里应该对应你服务器的版本
2、安装nagios、nagios-plugin与nrpe (nagios 3.3.1版本)
# yum install nagios nagios-plugins nagios-plugins-all nagios-plugins-nrpe nrpe
3、创建一个nagiosadmin 的用户用于Nagios的WEB接口登录,用户认证配置useradd nagiosadmin
# htpasswd -c /etc/nagios/passwd nagiosadmin
New password:
Re-type new password:
Adding password for user nagiosadmin
4、修改cgi.cfg文件,找到use_authentication=1 这行,把1改成0
#find -name cgi.cfg -print    查找
#vi /etc/nagios/cgi.cfg
5、启动apache与nagios
# /etc/init.d/httpd restart
# /etc/init.d/nagios start
6、登陆http://localhost/nagios/,输入用户密码后查看是否正常运行
注:别忘记了nagios后面那个/
被监控机设置:
1、安装需要软件
# yum install nagios-plugins nagios-plugins-nrpe nrpe
2、配置nrpe
# vi /etc/nagios/nrpe.cfg 修改监控机的地址或域名
allowed_hosts=127.0.0.1,192.168.1.8
3、修改/etc/hosts.allow增加监控机ip
# echo ‘nrpe:192.168.1.8′ >> /etc/hosts.allow
4、检查 NRPE 是否正常:
监控机上:
# /usr/lib64/nagios/plugins/check_nrpe -H 192.168.5.11
NRPE v2.12
查看相应的端口:netstat -an |grep 5666
防火墙开启5666 允许局域网IP或固定IP连接
5、启动 NRPE 守护进程:
# /usr/sbin/nrpe -c /etc/nagios/nrpe.cfg –d     或者
#/etc/init.d/nrpe start
6、关闭selinux:
#setenforce 0
在回到监控机:
添加nrpe的定义
# vi commands.cfg
# ‘check_nrpe’ command definition
define command{
command_name check_nrpe
command_line $USER1$/check_nrpe -H $HOSTADDRESS$ -c $ARG1$
}
增加主机监控配置项www.cfg

 

  1. ###### define hosts ################################### 
  2. define host { 
  3.         host_name               cancer-ts4 
  4.         address                 172.16.5.4 
  5.         check_command           check-host-alive 
  6.         check_interval          5 
  7.         max_check_attempts      2 
  8.         contact_groups          admins 
  9. } 
  10.  
  11. define host { 
  12.         host_name               cancer-ts11 
  13.         address                 172.16.5.11 
  14.         check_command           check-host-alive 
  15.         check_interval          5 
  16.         max_check_attempts      2 
  17.         contact_groups          admins 
  18. } 
  19.  
  20. define host { 
  21.         host_name               cancer-ts12 
  22.         address                 172.16.5.12 
  23.         check_command           check-host-alive 
  24.         check_interval          5 
  25.         max_check_attempts      2 
  26.         contact_groups          admins 
  27. } 
  28.  
  29. define host { 
  30.         host_name               cancer-hz4 
  31.         address                 172.16.3.4 
  32.         check_command           check-host-alive 
  33.         check_interval          5 
  34.         max_check_attempts      2 
  35.         contact_groups          admins 
  36. } 
  37.  
  38. define host { 
  39.         host_name               cancer-hz5 
  40.         address                 172.16.3.5 
  41.         check_command           check-host-alive 
  42.         check_interval          5 
  43.         max_check_attempts      2 
  44.         contact_groups          admins 
  45. } 
  46.  
  47. define host { 
  48.         host_name               cancer-hz12 
  49.         address                 172.16.3.12 
  50.         check_command           check-host-alive 
  51.         check_interval          5 
  52.         max_check_attempts      2 
  53.         contact_groups          admins 
  54. } 
  55.  
  56. define host { 
  57.         host_name               cancer-hz13 
  58.         address                 172.16.3.13 
  59.         check_command           check-host-alive 
  60.         check_interval          1 
  61.         max_check_attempts      2 
  62.         contact_groups          admins 
  63. } 
  64.  
  65. ######## define service ###################### 
  66. define service{ 
  67.         host_name                       cancer-ts4,cancer-ts11,cancer-ts12,cancer-hz4,cancer-hz5,cancer-hz12,cancer-hz13 
  68.         service_description             Users 
  69.         check_period                    24x7 
  70.         normal_check_interval           5 
  71.         retry_check_interval            2 
  72.         max_check_attempts              5  
  73.         notification_period             24x7 
  74.         contact_groups                  admins 
  75.         check_command                   check_nrpe!check_users  
  76.         } 
  77. define service{ 
  78.         host_name                       cancer-ts4,cancer-ts11,cancer-ts12,cancer-hz4,cancer-hz5,cancer-hz12,cancer-hz13 
  79.         service_description             Load 
  80.         check_period                    24x7 
  81.         normal_check_interval           5 
  82.         retry_check_interval            2 
  83.         max_check_attempts              5 
  84.         notification_period             24x7  
  85.         contact_groups                  admins 
  86.         check_command                   check_nrpe!check_load  
  87.         } 
  88. define service{ 
  89.         host_name                       cancer-ts4,cancer-ts11,cancer-ts12,cancer-hz4,cancer-hz5,cancer-hz12,cancer-hz13 
  90.         service_description             disk 
  91.         check_period                    24x7 
  92.         normal_check_interval           5 
  93.         retry_check_interval            2 
  94.         max_check_attempts              5 
  95.         notification_period             24x7  
  96.         contact_groups                  admins 
  97.         check_command                   check_nrpe!check_hda1  
  98.         } 
  99.  
  100. define service{ 
  101.         host_name                       cancer-ts11,cancer-ts12,cancer-ts4,cancer-hz4,cancer-hz5,cancer-hz13,cancer-hz12 
  102.         service_description             nginx 
  103.         check_period                    24x7 
  104.         normal_check_interval           5 
  105.         retry_check_interval            2 
  106.         max_check_attempts              5 
  107.         notification_period             24x7  
  108.         contact_groups                  admins 
  109.         check_command                   check_nrpe!check_nginx 
  110.         } 

并把www.cfg添加到nagios主配置项
# echo “cfg_file=/etc/nagios/objects/www.cfg” >> /etc/nagios/nagios.cfg
其他机器如法炮制即可

返回移动开发教程...