(详细配置请查看我的另一篇文章:https://blog.51cto.com/12173069/2070827)

  1. Nagios安装 - 服务端(192.168.8.81)
    安装nagios相关的包

    yum  -y  install  nagios  nagios-plugins  nagios-plugins-all  nagios-plugins-nrpe  nrpe

    设置登录nagios后台的用户和密码:

    htpasswd  -c  /etc/nagios/passwd  lee

    改变nagios相关目录权限:

    chown  nagios.nagios  /etc/logrotate.d/nagios
    chmod  g+w  /etc/logrotate.d/nagios
    chown  -R  nagios.nagios  /etc/nagios
    vim  /etc/nagios/nagios.cfg(nagios主配置文件)
    nagios -v /etc/nagios/nagios.cfg 检测主配置文件的语法

    启动服务:

    systemctl  start  httpd
    systemctl  start  nagios

    浏览器访问: 192.168.8.81/nagios

  2. Nagios安装 - 客户端(192.168.8.82)
    安装nrpe服务
    yum  -y  install  nagios-plugins  nagios-plugins-nrpe  nrpe

    修改 nrpe 主配置文件:vim /etc/nagios/nrpe.cfg
    找到“allowed_hosts=127.0.0.1” 改为 “allowed_hosts=127.0.0.1,192.168.8.81” 后面的ip为服务端ip
    centos安装nagios服务(测试可用)_第1张图片
    修改/etc/hosts.allow增加监控机ip:

    echo  'nrpe:192.168.8.82'  >>  /etc/hosts.allow

    查看 nrpe 端口是否开启:

    netstat  -nutlp  |  grep  5666

    启动客户端

    systemctl  start  nrpe
  3. 在服务端添加客户端主机(192.168.8.82)
    添加命令:vim /etc/nagios/objects/commands.cfg
    define command{
    command_name  check_nrpe
    command_line  $USER1/check_nrpe  -H  $HOSTADDRESS  -c  $ARG1
    }

    vim /etc/nagios/conf.d/lee.cfg
    //加入:

    define host{
    use  linux-server            
    host_name  lee
    alias  lee
    address  192.168.8.82
    }
    define service{
    use generic-service
    host_name lee
    service_description load
    check_command check_nrpe!check_load
    }
    define service{
    use generic-service
    host_name lee
    service_description PING
    check_command check_ping!100.0,20%!200.0,50%
    max_check_attempts 5
    check_interval 1
    }
    define service{
    use generic-service
    host_name lee
    service_description FTP
    check_command check_ftp!21
    max_check_attempts 5
    check_interval 1
    }
    define service{
    use generic-service
    host_name lee
    service_description SSH
    check_command check_ssh
    max_check_attempts 5
    check_interval 1
    }
    define service{
    use generic-service
    host_name lee
    service_description HTTP
    check_command check_http
    max_check_attempts 5
    check_interval 1
    }
  4. 最后加上个配置成功后的画面:
    centos安装nagios服务(测试可用)_第2张图片
    #5. nagios 的通知脚本在 /etc/nagios/objects/contacts.cfg里面:
    centos安装nagios服务(测试可用)_第3张图片
    #6. 可以在 /etc/nagios/objects/commands.cfg里面修改命令:
    centos安装nagios服务(测试可用)_第4张图片