码迷,mamicode.com
首页 > 移动开发 > 详细

Debian 系统安装 Nagios 服务器监控端

时间:2015-07-11 10:30:34      阅读:182      评论:0      收藏:0      [点我收藏+]

标签:

  1. 安装
    apt-get update
    apt-get install nagios* perl
    apt-get install --no-install-recommends pnp4nagios
    apt-get install apache2 apache2-utils php5 php-pear

  2. 修改npcd设置
    # vim /etc/default/npcd
    Run="yes"
    # service npcd start

  3. 添加process_perfdata.pl执行权限
    chmod +x /usr/lib/pnp4nagios/libexec/process_perfdata.pl
  4. 修改commands.cfg设置(注释旧命令)
    vi /etc/nagios3/commands.cfg
    技术分享
    # process-host-perfdata command definition
    define command{
       command_name   process-host-perfdata
       #command_line   /usr/bin/printf "%b" "$LASTHOSTCHECK$\t$HOSTNAME$\t$HOSTSTATE$\t$HOSTATTEMPT$\t$HOSTSTATETYPE$\t$HOSTEXECUTIONTIME$\t$HOSTOUTPUT$\t$HOSTPERFDATA$\n" >> /var/lib/nagios3/host-perfdata.out
       command_line   /usr/bin/perl /usr/lib/pnp4nagios/libexec/process_perfdata.pl
       }
    
    
    # process-service-perfdata command definition
    define command{
       command_name   process-service-perfdata
       #command_line   /usr/bin/printf "%b" "$LASTSERVICECHECK$\t$HOSTNAME$\t$SERVICEDESC$\t$SERVICESTATE$\t$SERVICEATTEMPT$\t$SERVICESTATETYPE$\t$SERVICEEXECUTIONTIME$\t$SERVICELATENCY$\t$SERVICEOUTPUT$\t$SERVICEPERFDATA$\n" >> /var/lib/nagios3/service-perfdata.out
       command_line   /usr/bin/perl /usr/lib/pnp4nagios/libexec/process_perfdata.pl
       }
    commands.cfg Code
  5. 修改nagios.cfg配置
    vi /etc/nagios3/nagios.cfg 修改以下3行配置
    process_performance_data=1
    host_perfdata_command=process-host-perfdata
    service_perfdata_command=process-service-perfdata
    修改check_external_commands=1 (未修改可能导致web网站无法Re-schedule监控项)
    修改enable_flap_detection=0 (虽然文档里说默认是0,但实际为1.改为0之后就解决了flapping state)
  6. 修改services_nagios2.cfg配置
    vi /etc/nagios3/conf.d/services_nagios2.cfg
    notification_interval 1
    vi /etc/nagios3/conf.d/generic-service_nagios2.cfg
    notification_interval 1
  7. 删除install.php
    # cd /usr/share/pnp4nagios/html
    # mv install.php install.php.bak

  8. Nagios插件目录: /usr/lib/nagios/plugins/
  9. 添加pnp4nagios插件
    vi /etc/nagios3/conf.d/pnp4nagos.cfg 追加如下配置
    技术分享
    define host {
            name       host-pnp
            action_url /pnp4nagios/index.php/graph?host=$HOSTNAME$class=tipsrel=/pnp4nagios/index.php/popup?host=$HOSTNAME$&srv=_HOST_
            register   0
            process_perf_data       1
    }
    
    define service {
            name       srv-pnp
            action_url /pnp4nagios/index.php/graph?host=$HOSTNAME$&srv=$SERVICEDESC$class=tipsrel=/pnp4nagios/index.php/popup?host=$HOSTNAME$&srv=$SERVICEDESC$
            register   0
            process_perf_data       1
    }
    Code
  10. 默认是没有监控内存的,若需要监控复制check_mem.sh文件到插件目录,再添加相关配置文件
    添加自定义执行命令
    vi /etc/nagios3/conf.d/custom_commond.cfg
    技术分享
    define command{
            command_name        check_mem
            command_line        $USER1$/check_mem.sh -w $ARG1$ -c $ARG2$
            }
    Code
    添加本机的check_mem服务
    vi /etc/nagios3/conf.d/localhost_nagios2.cfg  添加如下配置
    技术分享
    define service{
            use                             local-service,srv-pnp
            host_name                       localhost
            service_description             check_mem
            check_command                   check_mem!80!90
            }
    Code
  11. 监控服务器网卡流量
    apt-get install snmpd snmp-mibs-downloader
    vi /etc/snmp/snmpd.conf(可备份snmpd.conf,修改下面的localhost-IP为服务器IP,保存此文件即可)
    技术分享
    com2sec notConfigUser 127.0.0.1 public 
    com2sec notConfigUser localhost-IP public 
    
    group notConfigGroup v1 notConfigUser 
    group notConfigGroup v2c notConfigUser 
    
    view systemview included .1.3.6.1.2.1.1 
    view systemview included .1.3.6.1.2.1.2 
    view systemview included .1.3.6.1.2.1.25.1.1 
    view all included .1 
    
    access notConfigGroup "" any noauth exact all none none 
    Code

    重启snmpd服务
    下载check_traffic.sh到插件目录
    cd /usr/lib/nagios/plugins/
    测试执行
    ./check_traffic.sh -V 2c -C public -H your_ip -I 2 -w 1200,1500 -c 1700,1800 -K -B
    # vi /etc/nagios3/conf.d/custom_commond.cfg  追加

    技术分享
    define command{
            command_name    check_traffic
            command_line    $USER1$/check_traffic.sh -V 2c -C public -H $HOSTADDRESS$ -I $ARG1$ -w $ARG2$ -c $ARG3$ -M -b
    }
    Code
  12. 当服务停止时重新监控失败,运行以下2行命令
    # dpkg-statoverride --update --add nagios www-data 2710 /var/lib/nagios3/rw
    # dpkg-statoverride --update --add nagios www-data 751 /var/lib/nagios3

  13. 配置发送邮件功能
    apt-get install ssmtp   (备用:apt-get install sendmail-bin  sendmail)
    修改ssmpt.conf文件配置
    # vi /etc/ssmtp/ssmtp.conf  追加Google邮箱配置方式(勿开启2步验证)
    技术分享
    AuthUser=NagiosAdmin
    AuthPass=PassWord
    FromLineOverride=YES
    mailhub=smtp.gmail.com:587
    UseSTARTTLS=YES
    Code

    service sendmail stop
    chkconfig sendmail off
    cd /usr/sbin
    mv sendmail sendmail.bak
    ln -s /usr/sbin/ssmtp /usr/sbin/sendmail
    测试发邮件即可

  14. 添加被监控机需要注意
    监控其他主机,需要添加check_nrpe命令,但在Debian系统中,添加check_nrpe命令会提示重复,但是却找不到其他地方有配置。
    所以需要将check_nrpe改成其他名
    技术分享
    define command{
            command_name custom_check_nrpe
            command_line $USER1$/check_nrpe -H $HOSTADDRESS$ -c $ARG1$
            }
    Code

Debian 系统安装 Nagios 服务器监控端

标签:

原文地址:http://www.cnblogs.com/Mrhuangrui/p/4638083.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!