zoukankan      html  css  js  c++  java
  • linux上nagios安装完整版

    监控server端的安装部署
    一、apache的安装
    下载httpd-2.2.15.tar.gz
    gunzip httpd-2.2.15.tar.gz
    tar xvf httpd-2.2.15.tar
    cd httpd-2.2.15
    ./configure --prefix=/usr/local/apache2 --enable-so --enable-mods-shared=all --enable-cgi --enable-rewrite --enable-deflate --with-mpm=worker
    make
    make install
    安装完后添加nagios用户
    groupadd nagios
    useradd -g nagios -d /home/nagios -m nagios
    passwd nagios
    改动httpd.conf中的user group为以下的參数
    User nagios
    Group nagios
    改动ServerName=ip(server的ip地址):80
    mkdir /usr/local/nagios
    chown nagios:nagios /usr/local/nagios

    二、安装php+mysql(mysql能够不用安装,为了以后使用最好先安装)
    安装mysql
    rpm -ivh MySQL-server-community-5.1.46-1.rhel5.i386.rpm
    rpm -ivh MySQL-devel-community-5.1.46-1.rhel5.i386.rpm
    rpm -ivh MySQL-client-community-5.1.46-1.rhel5.i386.rpm

    安装php前先安装下面软件:
    安装zlib (安装libpng和gd前须要先安装zlib),
    gunzip zlib-1.2.3.tar.gz
    tar xvf  zlib-1.2.3.tar
    cd zlib-1.2.3
    ./configure  --prefix=/usr/local/zlib
    make
    make install

    安装libpng,
    gunzip libpng-1.2.18.tar.gz
    tar xvf libpng-1.2.18.tar
    cd libpng-1.2.18
    ./configure --prefix=/usr/local/libpng
    make
    make install

    安装freetype
    gunzip freetype-2.3.12.tar.gz
    tar xvf freetype-2.3.12.tar
    cd freetype-2.3.12
    ./configure --prefix=/usr/local/freetype
    make
    make install

    4. 安装jpeg
    gunzip jpegsrc.v6b.tar.gz
    tar xvf jpegsrc.v6b.tar
    cd jpeg-6b
    mkdir /usr/local/jpeg
    mkdir /usr/local/jpeg/bin
    mkdir /usr/local/jpeg/lib
    mkdir /usr/local/jpeg/include
    mkdir /usr/local/jpeg/man
    mkdir /usr/local/jpeg/man/man1
    ./configure --prefix=/usr/local/jpeg --enable-shared --enable-static
    make
    make install

    5. 安装gd,
    gunzip gd-2.0.35.tar.gz
    tar xvf gd-2.0.35.tar
    cd gd-2.0.35
    ./configure --prefix=/usr/local/gd --with-jpeg=/usr/local/jpeg --with-freetype=/usr/local/freetype --with-png --with-zlib
    //编译过程中会看到例如以下信息
    ** Configuration summary for gd 2.0.35:
    Support for PNG library: yes
    Support for JPEG library: yes
    Support for Freetype 2.x library: yes
    Support for Fontconfig library: no
    Support for Xpm library: no
    Support for pthreads: yes
    //能够看到png 、 jpeg 、 freetype都已经安装上了
    make
    make install

    上面软件都安装好后,如今就能够安装php了
    gunzip php-5.3.2.tar.gz
    tar xvf php-5.3.2.tar
    cd php-5.3.2
    ./configure --prefix=/usr/local/php5 --with-mysql --with-apxs2=/usr/local/apache2/bin/apxs --with-gd=/usr/local/gd --with-zlib --with-libpng=/usr/local/libpng --with-jpeg=/usr/local/jpeg --with-freetype=/usr/local/freetype --enable-sockets --with-iconv --enable-mbstring --enable-track-vars --enable-force-cgi-redirect --with-config-file-path=/usr/local/php5/etc
    make
    make install
    安装完后运行
    cp php.ini-development  /usr/local/php5/etc/php.ini
    最后改动httpd.conf,使apache能使用php,添加例如以下參数
        AddType application/x-httpd-php .php
        AddType application/x-httpd-php-source .phps

    三、安装nagios软件
    下载nagios-3.2.1.tar.gz
    gunzip nagios-3.2.1.tar.gz
    tar xvf nagios-3.2.1.tar
    cd nagios-3.2.1
    ./configure --prefix=/usr/local/nagios   --with-gd-lib=/usr/local/lib --with-gd-inc=/usr/local/include
    make all                             //编译nagios
    make install                        //安装基本的程序,CGI及HTML文件
    make install-init                  //在/etc/rc.d/init.d安装启动脚本
    make install-commandmode          //给外部命令訪问nagios配置文件的权限
    make install-config              //将配置文件的样例拷贝到nagios的安装文件夹

    验证程序是否被正确安装
    看是否存在etc,bin,sbin,share,var五个文件夹
    bin     Nagios运行程序所在文件夹,nagios文件即为主程序
    etc     Nagios配置文件位置
    sbin    Nagios cgi文件所在文件夹,运行外部命令所需文件所在的文件夹
    share  Nagios网页文件所在的文件夹
    var     Nagios日志文件,spid等文件所在的文件夹

    四、安装nagios插件
    下载nagios-plugins-1.4.14.tar.gz
    gunzip nagios-plugins-1.4.14.tar.gz
    tar xvf nagios-plugins-1.4.14.tar
    cd nagios-plugins-1.4.14
    ./configure --prefix=/usr/local/nagios-plugins
    make all
    make install
    安装完毕以后在/usr/local/nagios-plugins会产生一个libexec的文件夹,将该文件夹所有移动到/usr/local/nagios文件夹下
    cp -r /usr/local/nagios-plugins/libexec /usr/local/nagios/libexec
    chown -R nagios:nagios /usr/local/nagios/

    五、安装imagepak-base
    下载imagepak-base.tar.gz
    gunzip imagepak-base.tar.gz
    tar xvf imagepak-base.tar
    解压以后是一个base文件夹,将该文件夹复制到 /usr/local/nagios/share/images/logos文件夹下
    cp -r base /usr/local/nagios/share/images/logos
    chown -R nagios:nagios /usr/local/nagios/share/images/logos

    六、配置httpd.conf使用nagios
    在httpd.conf后面增加例如以下内容
    vi /usr/local/apache2/conf/httpd.conf       
    #Setting for nagios
    ScriptAlias /nagios/cgi-bin /usr/local/nagios/sbin
    <Directory "/usr/local/nagios/sbin">
        Options ExecCGI
        AllowOverride None
        Order allow,deny
        Allow from all
        AuthName "Nagios Access"
        AuthType Basic
        AuthUserFile /usr/local/nagios/etc/htpasswd
        Require valid-user
    </Directory>

    Alias /nagios /usr/local/nagios/share
    <Directory "/usr/local/nagios/share">
        Options None
        AllowOverride None
        Order allow,deny
        Allow from all
        AuthName "Nagios Access"
        AuthType Basic
        AuthUserFile /usr/local/nagios/etc/htpasswd
        Require valid-user
    </Directory>

    对添加后的參数进行验证
    /usr/local/apache2/bin/apachectl -t           //检查配置文件是否正确
    生成apache訪问的认证文件并启动apache进行验证
    /usr/local/apache2/bin/htpasswd -c /usr/local/nagios/etc/htpasswd nagios
    cat /usr/local/nagios/etc/htpasswd            //查看认证文件内容
    /usr/local/apache2/bin/apachectl start       //启动apache
    到眼下为止,监控主机上的nagios的所有安装已经所有完毕,接下来就是要配置详细的监控项目了

    七、配置nagios(主要是定义监控的对象所存放的是哪些文件)
    预备知识 :
    在Nagios里面定义了一些主要的对象,一般用到的有:
    监控时间段    timeperiod        7X24小时不间断还是周一至周五,或是自己定义的其它时间段
    联系人        contact           出了问题向谁报告?一般当然是系统管理员了
    被监控主机    Host              所须要监控的server,当然能够是监控机自己
    监控命令      command           nagios发出的哪个指令来运行某个监控,这也是自己定义的
    被监控的服务  Service           比如主机是否存活,80port是否开,磁盘使用情况或者自己定义的服务等
    注意:多个被监控主机能够定义为一个主机组,多个联系人能够被定义为一个联系人组

    改动Nagios的配置文件:
    ------------------------------------------------------------------------
    vi /usr/local/nagios/etc/nagios.cfg                                     //改动nagios的主配置文件
    #cfg_file=/usr/local/nagios/etc/objects/localhost.cfg      //凝视此行
    cfg_file=/usr/local/nagios/etc/objects/timeperiods.cfg     //监视时段配置文件路径
    cfg_file=/usr/local/nagios/etc/objects/contacts.cfg        //联系人配置文件路径
    cfg_file=/usr/local/nagios/etc/objects/commands.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/services.cfg        //服务配置文件路径
    cfg_file=/usr/local/nagios/etc/objects/contactgroups.cfg    //联系组配置文件路径

    check_external_commands=0     //将 0 改成 1,同意在web界面下运行重新启动Nagios
    command_check_interval=60s    //改成 60s, 命令检查时间间隔
    check_external_commands=0     //将0改为1,同意在web界面运行external_commands

    然后检查配置文件是否出错
    /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg
    假设正常就显演示样例如以下信息
            Total Warnings: 0
            Total Errors:   0
    由于默认的nagios配置文件没有 hosts.cfg、hostgroups.cfg等文件,因此在检查的时候会报错,这时须要手工的去创建这些文件:
    cd    /usr/local/nagios/etc/objects
    touch   hosts.cfg
    touch   hostgroups.cfg
    ..........
    建完后再检查是否报错:
    /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg

    八、配置cgi.cfg (主要是)
    vi cgi.cfg                         //改动cgi脚本控制文件
    use_authentication=1               //确保值为 1
    default_user_name=nagios           //改动为认证用户
    //后面改动内容例如以下:
    authorized_for_system_information=nagiosadmin,nagios
    authorized_for_configuration_information=nagiosadmin,nagios
    authorized_for_system_commands=nagios         //多个用户之间用逗号隔开
    authorized_for_all_services=nagiosadmin,nagios
    authorized_for_all_hosts=nagiosadmin,nagios
    authorized_for_all_service_commands=nagiosadmin,nagios
    authorized_for_all_host_commands=nagiosadmin,nagios
    -------------------------------------------------------------------------
    九、配置misccommands.cfg
    vi misccommands.cfg                //主要功能是用于发送报警短信和报警邮件

    #host-notify-by-sms              //发送短信报警
    define command {
           command_name      host-notify-by-sms
           command_line      /usr/local/bin/sms_send "Host $HOSTSTATE$ alert for $HOSTNAME$! on '$DATETIME$' " $CONTACTPAGER$
           }

    #service notify by sms        //发送短信报警
    define command {
           command_name     service-notify-by-sms
           command_line     /usr/local/bin/sms_send "'$HOSTADDRESS$' $HOSTALIAS$/$SERVICEDESC$ is $SERVICESTATE$" $CONTACTPAGER$
           }
          
    十、定义nagios各对象的详细配置文件:
    vi /usr/local/nagios/etc/objects/timeperiods.cfg           //定义监控时间段,名称是24*7,监控时间是全天24小时
    define timeperiod {
            timeperiod_name         24x7     //时间段的名称,这个地方不要有空格
            alias                   24 Hours A Day,7Days A Week
            sunday                  00:00-24:00
            monday                  00:00-24:00
            tuesday                 00:00-24:00
            wednesday               00:00-24:00
            thursday                00:00-24:00
            friday                  00:00-24:00
            saturday                00:00-24:00
            }
           
    vi contacts.cfg     //定义联系人

    define contact {
            contact_name         sa                     //不要有空格
            alias                system administrator
            service_notification_period    24x7      //服务出了状况通知的时间段,由timeperiods.cfg中定义的.
            host_notification_period       24x7      //主机出了状况通知的时间段,由timeperiods.cfg中定义的.
            service_notification_options   w,u,c,r   //当服务出现问题
            host_notification_options       d,u,r     //当主机出现问题
            service_notification_commands  service-notify-by-sms,service-notify-by-email  //命令读配置miscommands.cfg
            host_notification_commands     host-notify-by-email,host-notify-by-sms      //命令读配置miscommands.cfg
            email                          monitor@xxx.com
            pager                          132********
            }
     
    define contact {
            contact_name         ritto
            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_commands  notify-by-email   
                           //notify-by-mail是在commands.cfg中定义的,给联系人发邮件
            host_notification_commands     host-notify-by-email 
                           //主机出现问题时,给联系人发邮件
            email                          ritto.zhao@xxx.com    //联系人邮件地址
            pager                          132********   
                          //联系人的手机,假设支持短信通知的话,会非常有用
            }

    //假设不须要手机报警的话,则改成例如以下:
    service_notification_commands   notify-by-email
    host_notification_commands      host-notify-by-email

    //上面的文件定义了2个联系人,假设有很多其它联系人的话,照这个格式在后面追加就可以。
    //服务通知选项(service_notification_options)
    //与主机通知选项(host_notification_options)的几个选项在这里说明一下:
    //w-warning 报警 , u-unknown 未知, c-critical 严重 , r-recovery 从异常情况恢复正常 ; d-down 关机了,
    //u-unreachable,注意一下,主机报警和服务报警有些差异。

    -----------------------------------------------------------------------------
    vi contactgroups.cfg       //将多个联系人定义一个联系人组

    define contactgroup{
            contactgroup_name       sagroup
            alias                   System Administrators
            members                 sa,ritto
            }

    -----------------------------------------------------------------------------
    vi hosts.cfg              //定义被监控主机

    #define monitor  host
    define host {
           host_name                  nagios-server
           alias                      nagios server
           address                    192.168.4.226
           contact_groups             sagroup             
                                 //多个联系组用逗号分隔,数据来源于contactgroups.cfg
           check_command              check-host-alive
                                //这个命令来自commands.cfg,用来监控主机是否存活
           max_check_attempts         5          //检查失败后重试的次数
           notification_interval      10             //提醒的时间,每隔10秒提醒一次
           notification_period        24x7                
                                //提醒的周期,24*7,来自之前timeperiods.cfg中定义的
           notification_options       d,u,r               
                                //指定什么情况下提醒,来自contacts.cfg中定义的
           }
     
    define host {
           host_name                  mail12.supertalent.com
           alias                          nagios test client
           address                      192.168.4.41
           contact_groups             sagroup
           check_command           check-host-alive
           max_check_attempts    5
           notification_interval      10
           notification_period        24x7
           notification_options       d,u,r
           }

    ------------------------------------------------------------------------------
    vi hostgroups.cfg          //将多个主机定义一个主机组

    define hostgroup{
            hostgroup_name          sa-servers   //主机组名称
            alias                         sa Servers   //别名
            members                    nagios-server
                         //组的成员主机,多个主机以逗号相隔,必须是上面hosts.cfg中定义的
            }

    ------------------------------------------------------------------------------
    vi services.cfg           //定义监控的服务

    #service definition

    define service{
            host_name               nagios-server      //要监控的主机, 必须是hosts.cfg 中定义的                         
            service_description     check-host-alive   //定义的是监控这个主机是不是存活,给监控项目起个名字,随意起都能够,如check ftp    
            check_command           check-host-alive   //所用的命令,是commands.cfg中定义的,所用的命令,必须是commands.cfg中定义的   
            check_period            24x7               //监控的时间段,是timeperiods.cfg中定义的                
            max_check_attempts      5
            normal_check_interval   3
            retry_check_interval    2
            contact_groups          sagroup    //联系人组, contactgroups.cfg中定义的
            notification_interval   10
            notification_period     24x7        //通知的时间段, ,是timeperiods.cfg中定义的
            notification_options    w,u,c,r                                    
            }


    define service {
            host_name               mail12.supertalent.com
            service_description     check_http
          check_command             check_http       //检查tcp 80port服务是否正常
            check_period            24x7
            max_check_attempts      4
            normal_check_interval   3
            retry_check_interval    2
            contact_groups          sagroup
            notification_interval   10
            notification_period     24x7
            notification_options    w,u,c,r
            }


    //书写时要注意的是,check_tcp与要监控的服务port之间要用”!”做分隔符。假设服务太多,以考虑用脚本来生成。

    -----------------------------------------------------------------------------

    /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg   //检查全部配置文件的正确性

    /usr/local/nagios/bin/nagios -d /usr/local/nagios/etc/nagios.cfg   //作为守护进程后台启动Nagios

    echo "/usr/local/nagios/bin/nagios -d /usr/local/nagios/etc/nagios.cfg" >> /etc/rc.local    //开机自己主动执行

    -----------------------------------------------------------------------------

    使用命令和插件监控很多其它信息
    cd /usr/local/nagios/libexec        //插件默认的安装路径

    ./check_disk -w 10% -c 5% /     
    //检查根分区的使用情况,若剩余10%下面,为警告状态(warning)
     //若剩余 5%下面,为严重状态(critical)

    设置并熟悉以上的配置后,以下就须要进行详细的监控工作了

    被监控主机上的安装部署配置
    十一、监控一台主机
    在hosts.cfg中定义主机名 --- 在services.cfg中定义监控内容

    ------------------------------------------------------------------------------

    使用NRPE监控Linux上的"本地信息"
    对系统为Linux的主机进行例如以下监控: CPU负载,磁盘容量,登陆用户数,总进程数,僵尸进程数,swap分区使用情况

    在被监控主机上.
    useradd nagios
    passwd nagios

    tar zxvf nagios-plugins-1.4.9.tar.gz
    cd nagios-plugins-1.4.9
    ./configure --prefix=/usr/local/nagios
    make
    make install
    chown nagios.nagios /usr/local/nagios
    chown -R nagios.nagios /usr/local/nagios/libexec/

    tar zxvf nrpe-2.8.1.tar.gz
    cd nrpe-2.8.1
    ./configure                      //NRPE port: 5666
    make all
    make install-plugin             
    make install-daemon              //安装daemon
    make install-daemon-config       //安装配置文件

    ls /usr/local/nagios/
    bin/     etc/     libexec/ share/     //如今nagios文件夹会有4个文件夹了

    将NRPE daemon作为xinetd下的一个服务执行
    yum -y install xinetd
    service xinetd start
    chkconfig --level 3 xinetd on

    make install-xinetd          //安装xinetd脚本

    vi /etc/xinetd.d/nrpe
    only_from  = 127.0.0.1 192.168.4.226   //在后面添加监控主机的地址,以空格间隔

    vi /etc/services
    nrpe            5666/tcp                        # nrpe    //添加这一行

    service xinetd restart

    netstat -at | grep nrpe     //查看NRPE是否已经启动
    netstat -an | grep 5666     //查看5666port是否被监听

    vi /etc/sysconfig/iptables   //添加一条5666的端口
    -A RH-Firewall-1-INPUT -m state --state NEW -m tcp -p tcp --dport 5666 -j ACCEPT

    /usr/local/nagios/libexec/check_nrpe -H 127.0.0.1     //測试NRPE是否正常工作
    NRPE v2.8.1           //正常的结果会显示当前NRPE的版本

    查看NRPE的监控命令
    cd /usr/local/nagios/etc
    vi nrpe.cfg
    command[check_users]=/usr/local/nagios/libexec/check_users -w 5 -c 10
    command[check_load]=/usr/local/nagios/libexec/check_load -w 15,10,5 -c 30,25,20
    command[check_hda1]=/usr/local/nagios/libexec/check_disk -w 20 -c 10 -p /dev/hda1
    command[check_zombie_procs]=/usr/local/nagios/libexec/check_procs -w 5 -c 10 -s Z
    command[check_total_procs]=/usr/local/nagios/libexec/check_procs -w 150 -c 200

    [***]中是命令名,也就是check_nrpe的-c參数能够接的内容,=后面是实际运行的插件程序
    /usr/local/nagios/libexec/check_nrpe -H 127.0.0.1 -c check_users        //检測登陆用户数
    /usr/local/nagios/libexec/check_nrpe -H 127.0.0.1 -c check_load         //CPU负载
    /usr/local/nagios/libexec/check_nrpe -H 127.0.0.1 -c check_zombie_procs //僵尸进程
    /usr/local/nagios/libexec/check_nrpe -H 127.0.0.1 -c check_total_procs  //总进程数
    /usr/local/nagios/libexec/check_nrpe -H 127.0.0.1 -c check_disk  //磁盘使用量

    当中:
    //check_load -w 15,10,5 -c 30,25,20
    //在unix里面负载的均值通常表示是1分钟,5分钟,15分钟内平均有多少进程处于等待状态
    //当1分钟多于15个进程等待,5分钟多于10个,15分钟多于5个则为warning状态
    //当1分钟多于30个进程等待,5分钟多于25个,15分钟多于20个则为critical状态


    记住监測磁盘时,先用
    fdisk -l   //查看磁盘的分区,假设sda, 则应该改成以下的形式,把默认的hda1改成sda1
       Device Boot      Start         End      Blocks   Id  System
    /dev/sda1   *           1          13      104391   83  Linux
    /dev/sda2              14         268     2048287+  82  Linux swap / Solaris
    /dev/sda3             269       19457   154135642+  83  Linux


    command[check_sda1]=/usr/local/nagios/libexec/check_disk -w 20 -c 10 -p /dev/sda1
    command[check_sda3]=/usr/local/nagios/libexec/check_disk -w 20 -c 10 -p /dev/sda3


    /usr/local/nagios/libexec/check_nrpe -H 127.0.0.1 -c check_sda1
    DISK OK - free space: /boot 77 MB (82% inode=99%);| /boot=16MB;78;88;0;98
    /usr/local/nagios/libexec/check_nrpe -H 127.0.0.1 -c check_sda3
    DISK OK - free space: / 135169 MB (97% inode=99%);| /=3113MB;145789;145799;0;145809


    比如查看根分区的使用情况,运行
    /usr/local/nagios/libexec/check_disk -w 10% -c 5% /
    命令的含义是检查分区/的使用情况,若剩余10%下面,为警告状态(warning),5%下面为严重状态(critical),
    运行后我们会看到下面这条信息
    DISK WARNING - free space: / 135169 MB (97% inode=99%);| /=3113MB;145789;145799;0;145809
    说明当前是warning的状态,空暇空间还有97%.

     在执行Nagios的监控主机上
    由于之前已经将Nagios执行起来了,如今要做的是:
    安装check_nrpe插件
    在commands.cfg中创建check_nrpe中的命令,仅仅有在commands.cfg中定义过的命令才干在services.cfg中使用
    创建对被监控主机的监控项目

    tar zxvf nrpe-2.8.1.tar.gz
    cd nrpe-2.8.1
    ./configure
    make all
    make install-plugin    //仅仅执行这一步就可以,仅仅须要check_nrpe插件

    /usr/local/nagios/libexec/check_nrpe -H 192.168.4.30
    NRPE v2.8.1      
           //測试一下监控机使用check_nrpe与被监控机执行的nrpedaemon之間的通信
              //看到已经返回了正确的NRPE的版本号信息,说明一切正常
            //如返回"Could not complete SSL handshake",则要检查被监控机/etc/xinetd.d/nrpe中only_from这项是否同意监控机訪问

    在commands.cfg中添加对check_nrpe的定义
    vi /usr/local/nagios/etc/commands.cfg
    #################################################################
    # 2008.12.4 by ritto
    #################################################################
    # 'check_nrpe' command definition
    define command{
            command_name check_nrpe
            command_line $USER1$/check_nrpe -H $HOSTADDRESS$ -c $ARG1$
            }

    //command_name check_nrpe 定义命令名称为check_nrpe, 在services.cfg中要使用这个名称
    //command_line $USER1$/check_nrpe -H $HOSTADDRESS$ -c $ARG1$  定义实际执行的插件程序


    接下来能够在services.cfg中定义对主机CPU负载的监控
    vi services.cfg
    define service {
            host_name               mail1
            service_description     check-load
            check_command           check_nrpe!check_load
            check_period            24x7
            max_check_attempts      4
            normal_check_interval   3
            retry_check_interval    2
            notification_interval   10
            notification_period     24x7
            notification_options    w,u,c,r
            contact_groups          sagroup
            }

    define service {
            host_name               mail1
            service_description     check-users
            check_command           check_nrpe!check_users
            check_period            24x7
            max_check_attempts      4
            normal_check_interval   3
            retry_check_interval    2
            notification_interval   10
            notification_period     24x7
            notification_options    w,u,c,r
            contact_groups          sagroup
            }

    define service {
            host_name               mail1
            service_description     check-zombie-process
            check_command           check_nrpe!check_zombie_procs
            check_period            24x7
            max_check_attempts      4
            normal_check_interval   3
            retry_check_interval    2
            notification_interval   10
            notification_period     24x7
            notification_options    w,u,c,r
            contact_groups          sagroup
            }

    ----------------------------------------------------------------------

    在被监控机上添加check_swap命令的定义
    vi /usr/local/nagios/etc/nrpe.cfg
    添加以下这一行
    command[check_swap]=/usr/local/nagios/libexec/check_swap -w 20% -c 10%

    //假设在被监控机上是以daemon执行的nrpe,则须要手动重新启动
    //假设在被监控机上是以xinetd执行的,则不须要

    ----------------------------------------------------------------------

    在监控机上添加这个监控项目:
    vi /etc/services.cfg
    define service {
            host_name               mail1
            service_description     check-swap
            check_command           check_nrpe!check_swap
            check_period            24x7
            max_check_attempts      4
            normal_check_interval   3
            retry_check_interval    2
            notification_interval   10
            notification_period     24x7
            notification_options    w,u,c,r
            contact_groups          sagroup
            }


    ------------------------------------------------------------------------------

    全部配置都已经改动好,如今重新启动Nagios,杀掉Nagios进程,再重新启动,过一会就能够看到画面了
    killall nagios
    /usr/local/nagios/bin/nagios -d /usr/local/nagios/etc/nagios.cfg
    或使用
    /etc/init.d/nagis restart/start/stop/status
    如查报错,则可能是脚本路径设置错误,
    vi /etc/init.d/nagios
    将prefix=/usr/local/nagiosaa改为安装的文件夹/etc/init.d/nagios

    十二、监控一台windows机器
    nagios监控windows系统有三种实现方式:SNMP,NSClient++,NRPE,后面两种方式都须要在windows上安装agent,本文档仅仅介绍使用NSClient++方式来监控Windows
    在windowsserver上:
    ---------------------------------------------------------------------------------------------------------------------
    安装 NSClient++
    http://sourceforge.net/projects/nscplus下载近期版本号的NSClient++;解压NSClient++到C:/NSClient++文件夹;
    开启 cmd,切换到 C:/NSClient++,运行 NSClient++ /install 进行安装
    运行 NSClient++ SysTray install 注意大写和小写,这一步是安装系统小图标

    编辑 C:/NSClient++ 下的 NSC.ini 文件
    [modules] 中,全部的 .dll 凝视都全都去掉,除了 CheckWMI.dll 和 RemoteConfiguration.dll不用去掉凝视外
    [Settings] 中,'password' 这个项目是在设置password,作用是在 nagios 监控主机进行联机时,要求提供password才干进一步进行联机,这里为了方便起见,跳过它,不要设定password。
    [Settings] 中,'allowed_hosts' 选项的凝视去掉,而且加上 nagios 的监控主机的 IP,改动例如以下 allowed_hosts=127.0.0.1/32,192.168.1.11 以逗点相隔。
    [NSClient] 中,'port' 选项的凝视需要拿掉,而且它的值是 '12489',这是 NSClient 的预设 port

    设定完毕之后,启动 NSClient++
    在 cmd 中 C:/NSClient++ 下,运行 NSClient++ /start
    在 cmd 下,运行 netstat -an ,检查 port 12489 是否开启
    启动完后,在windows上的操作就结束了
    ----------------------------------------------------------------------------------------------------------------------

    在监控server上:
    -----------------------------------------------------------------------------------------------------------------------
    先到配置文件打开windows相关模块
    vi /usr/local/nagios/etc/nagios.cfg
    # Definitions for monitoring a Windows machine
    cfg_file=/usr/local/nagios/etc/objects/windows.cfg #去掉这句话的凝视

    打开模块先配置commands.cfg
    检查libexec文件夹下需要有 check_nt 运行程序。
    设定 commands.cfg
    添加:
    # 'check_nt' windows client command definition for remote service
    define command{
            command_name    check_nt
            command_line    $USER1$/check_nt -H $HOSTADDRESS$ -p 12489  -v $ARG1$ $ARG2$
            }
    该命令在安装的时候已经存在,因此不需要再添加了       

    接配置windows.cfg,主要是定义监控主机及服务
    define host{
            use             windows-server  ; Inherit default values from a template
            host_name       192.168.1.11    ; The name we're giving to this host
            alias           My Windows Server       ; A longer name associated with the host
            address         192.168.1.11    ; IP address of the host
            contact_groups             sagroup
            check_command              check-host-alive
            max_check_attempts         1
            notification_interval      2
            notification_period        24x7
            notification_options       d,u,r
            }
           
           
    define service{
            use                     generic-service
            host_name               192.168.1.11
            service_description     CPU Load
            check_command           check_nt_cpuload
            check_period            24x7
            max_check_attempts      3
            normal_check_interval   1
            retry_check_interval    2
            contact_groups          sagroup
            notification_interval   1
            notification_period     24x7
            notification_options    w,u,c,r
            }
    配置完后检查nagios的配置是否有问题,假设没有问题直接重起nagios.到此,windows的监控便已完毕

           
          

  • 相关阅读:
    Solution -「USACO 2020.12 P」Spaceship
    Solution -「USACO 2020.12 P」Sleeping Cows
    Solution -「HDU #6566」The Hanged Man
    Solution -「JOISC 2019」「LOJ #3036」指定城市
    HTML5 之required修改默认提示
    Js 之内容加密
    小程序 之生成接口签名
    Js 之Api接口验签
    View.js 之加载动画
    View.js 之跳转动画
  • 原文地址:https://www.cnblogs.com/mengfanrong/p/4277771.html
Copyright © 2011-2022 走看看