seemebaby 发表于 2019-1-16 13:33:11

nagios 安装配置(修正版)

  nagios 安装配置
  安装 APACHE+PHP
  最简单 直接yum
yum install httpd*
yum install php*
  一:先安装Apache+PHP(省略),然后修改apache的配置文件:
主要修改apache配置文件httpd.conf
把下面的内容追加到httpd.conf文件的末尾:
    Scriptalias /nagios/cgi-bin /usr/local/nagios/sbin

    Authtype basic
    Options execcgi
    Allowoverride none
    Order allow,deny
    Allow from all
    Authname "nagios access"
    Authuserfile /usr/local/nagios/etc/nagios.password
    Require valid-user
  
Alias /nagios /usr/local/nagios/share

    Authtype basic
    Options none
    Allowoverride none
    Order allow,deny
    Allow from all
    Authname "nagios access"
    Authuserfile /usr/local/nagios/etc/nagios.password
    Require valid-user

  增加访问控制验证用户:(第一次创建时要加参数c)
#/usr/local/apache/bin/htpasswd -c /usr/local/nagios/etc/nagios.password nagiosadmin
输入密码:123456
如果你是rpm安装的apache 和php 就
#htpasswd -c /usr/local/nagios/etc/nagios.password nagiosadmin
这个可以不写,是怕前面不行才强行添加的:vim /usr/local/nagios/etc/nagios.password加入 nagiosadmin
  
  创建用户维护Nagios的用户和组
#/usr/sbin/useradd nagios
#passwd nagios
#/usr/sbin/groupadd nagcmd
#/usr/sbin/usermod -a -G nagcmd nagios
  
  安装Nagios和插件
安装Nagios
#tar zxvf nagios-3.2.1.tar.gz
#cd nagios-3.2.1
#./configure --prefix=/usr/local/nagios --with-command-group=nagcmd
#make all
#make install                  
  #make install-init            
#make install-config            安装的路径是/usr/local/nagios/etc
#make install-commandmode       配置目录权限
  
  安装Nagios-plugins
#tar zxvf nagios-plugins-1.4.14.tar.gz
#cd nagios-plugins-1.4.14
#./configure --prefix=/usr/local/nagios --with-nagios-user=nagios --with-nagios-group=nagios
#make && make install
  
  编辑 /usr/local/nagios/etc/nagios.cfg
cfg_file=/usr/local/nagios/etc/objects/commands.cfg
cfg_file=/usr/local/nagios/etc/objects/contacts.cfg
cfg_file=/usr/local/nagios/etc/objects/timeperiods.cfg
cfg_file=/usr/local/nagios/etc/objects/templates.cfg
  # Definitions for monitoring the local (Linux) host
#cfg_file=/usr/local/nagios/etc/objects/localhost.cfg   ---------这个注释掉,如果要监控本机就不注释)
cfg_file=/usr/local/nagios/etc/objects/hosts.cfg
cfg_file=/usr/local/nagios/etc/objects/hostgroups.cfg
cfg_file=/usr/local/nagios/etc/objects/contactgroups.cfg
cfg_file=/usr/local/nagios/etc/objects/services.cfg

  #下面几个行可以不用理会。
  check_external_commands=1
  command_check_interval=10s
  interval_length=60
  normal_check_interval=10
max_check_attempts=3
retry_check_interval=1
  #这样就实现在10分钟一次检测,重试3次,重试时间1分钟
  
  修改cgi配置文件cgi.cfg.跟修改nagios.cfg一样,只贴出被修改之处:(这里也可以不用理会,默认就是这样)
#如有多个用户,中间用逗号隔开
authorized_for_system_information=nagiosadmin
authorized_for_configuration_information=nagiosadmin
authorized_for_system_commands=nagiosadmin
authorized_for_all_services=nagiosadmin
authorized_for_all_hosts=nagiosadmin
authorized_for_all_service_commands=nagiosadmin
authorized_for_all_host_commands=nagiosadmin
在这里指定的用户”nagiosadmin”可以通过浏览器操纵nagios服务的关闭、重启等各种操作。
  vim /usr/local/nagios/etc/object/hosts.cfg
  define host {
       host_name                   mysql1.dog.com      被监控IP 或 域名
       alias                        mysql1             这个随便
       address                     10.1.1.4            被监控的IP罗
       contact_groups               doggroup            这个在contactgroups.cfg添加的
       check_command                check-host-alive
       check_period               24x7
       max_check_attempts             5                  失败后重试次数
       notification_interval         10         每隔多久提醒一次,我觉得这是分钟意思            
       notification_period         24x7               
       notification_options          d,u,r         什么情况下提醒 d = down 机
       }
  
  几个值的意思是 d-down,u-unreacheable,r-recovery.
  
  vim /usr/local/nagios/etc/objects/hostgroups.cfg
  
      define hostgroup {
      hostgroup_namemy-hosts
      alias         myhosts
     members         mysql1.dog.com      多台用逗号隔开******,注意,这个我直接用IP提示错误的。               
      }
  
  vim /usr/local/nagios/etc/objects/contacts.cfg
  shit +g 在最后加入
  
define contact {
   contact_name         userA
   alias                system administrator
   service_notification_period    24x7
   host_notification_period       24x7
   service_notification_options   w,u,c,r
   host_notification_options       d,u,r
   service_notification_commandsnotify-service-by-email
   host_notification_commands   notify-host-by-email
   email                        root@dog.com
    }
  define contact {
   contact_name         userB
   alias                system administrator
   service_notification_period    24x7
   host_notification_period       24x7
   service_notification_options   w,u,c,r
   host_notification_options       d,u,r
   service_notification_commandsnotify-service-by-email
   host_notification_commands   notify-host-by-email
   email                        alex@dog.com
}

  出问题的话就发给上面那2个人userA和userB 注意,都不同的邮箱哦。
  
  vim /usr/local/nagios/etc/objects/contactgroups.cfg
  define contactgroup {
      contactgroup_name    doggroup
      alias                system administrator group
      members             userA,userB
      }

  这个很重要:
  vim /usr/local/nagios/etc/objects/services.cfg
  
  define service {
host_name mysql1.dog.com
service_description PING
check_period      24x7
notification_interval       3
normal_check_interval       1
max_check_attempts          3
retry_check_interval      1
check_command check_ping!100.0,20%!500.0,60%----------ping 监控
contact_groups         doggroup
                      }

define service {
host_name mysql1.dog.com
max_check_attempts          5
check_period            24x7
notification_interval       10
normal_check_interval       1
retry_check_interval      1
service_description HTTP
check_command check_http                        ----就是监控apache
notification_period    24x7
notification_options    w,u,c,r
contact_groups         doggroup
                     }

  

  好了。完工
  /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg
  这命令式检查你的配置有没有错的,当出现
Total Warnings: 0
Total Errors:   0
就表示没错了
  
  重启nagios
service nagios stop
  service nagios start
  重启apache


下一篇:nagios利用NRPE监控CPU负载 磁盘 & mysql nginx 的一些方法
http://dogdogcom.blog.运维网.com/2402458/433155



页: [1]
查看完整版本: nagios 安装配置(修正版)