naigos实现监控 短信报警


一、nagios在服务端的安装

    # vim nagios-install

    #!/bin/bash

    #### nagios客户端安装请注释了install nagios这段###

    ##install nagios

    tar zxvf nagios-3.0.6.tar.gz cd nagios-3.0.6 ./configure --prefix=/usr/local/nagios --with-nagios-user=nagios --with-nagios-group=nagios

    make all

    make install

    make install-init

    make install-config

    make install-commandmode

    make install-webconf

    cd ..

    ##install nagios-plugins

    tar zxvf nagios-plugins-1.4.13.tar.gz cd nagios-plugins-1.4.13 ./configure --prefix=/usr/local/nagios

    make

    make install

    cd ..

    ##install nrpe

    tar zxvf nrpe-2.12.tar.gz cd nrpe-2.12 ./configure --enable-ssl  --enable-command-args

    make all

    mkdir -p /usr/local/nagios/etc

    mkdir -p /usr/local/nagios/bin

    cp sample-config/nrpe.cfg /usr/local/nagios/etc/

    cp src/nrpe /usr/local/nagios/bin/

    sed -i 's/127.0.0.1/127.0.0.1,192.168.1.253/' /usr/local/nagios/etc/nrpe.cfg sed -i 's/usr\/local/nagios/g' /usr/local/nagios/etc/nrpe.cfg

    二、启动nrpe

    # /usr/local/nagios/bin/nrpe -c /usr/local/nagios/etc/nrpe.cfg -d如需重启nrpe,先killall -9 nrpe再执行启动

    三、配置nagios

    Nagios安装成功后,在/usr/local/nagios下有几个目录,分别是:

    bin etc libexec sbin share var

    1、在/usr/local/nagios/etc 下建立一个linux的目录,并建立一个hosts.cfg文件。

    这个文件里面的内容,是分三大块:(1)、定义主机,即host (2)、定义监控组,即 hostgroup (3)、定义监控主机的服务,即server

    例:

    # Define webgroup host for the testers machine ##定义主机

    define host{

    host_name web01

    alias                    web01.com address                  192.168.1.10

    check_command check-host-alive

    max_check_attempts 10

    check_period 24x7

    notification_interval 20

    notification_period 24x7

    notification_options                d,r

    contact_groups admins

    name web01

    }

    define host{

    host_name web02

    alias                    web02.com address                  192.168.1.20

    check_command check-host-alive

    max_check_attempts 10

    check_period 24x7

    notification_interval 20

    notification_period 24x7

    notification_options                d,r

    contact_groups admins

    name web02

    }

    define host{

    host_name web03

    alias                    web03.com address                  192.168.1.20

    check_command check-host-alive

    max_check_attempts 10

    check_period 24x7

    notification_interval 20

    notification_period 24x7

    notification_options                d,r

    contact_groups admins

    name web02

    }

    ##----------------------------------------------------------------------------------------##

    ### Define all hostgroup for the whole machine ##定义监控组

    # Define web group

    define hostgroup{

    hostgroup_name Web01 Server

    alias webserver

    members                 web01,web02 #监控多个机器用逗号隔开

    define hostgroup{

    hostgroup_name Web02 Server

    alias webserver

    members web03 #监控多个机器用逗号隔开

    ##----------------------------------------------------------------------------------------##

    #########定义监控主机的服务###########

    define service{

    host_name                   web01,web02,web03

    service_description check-procs

    is_volatile 0

    check_period 24x7

    max_check_attempts 1

    normal_check_interval 1

    retry_check_interval 1

    notification_options                 w,u,c,r

    notification_interval 1

    notification_period 24x7

    check_command                   check_nrpe!check_total_procs

    contact_groups admins #联系人组

    notifications_enabled                1   #此处设定为0,则不报警

    }

    define service{

    host_name                   web01,web02,web03

    service_description check-swap

    is_volatile 0

    check_period 24x7

    max_check_attempts 1

    normal_check_interval 1

    retry_check_interval 1

    notification_options                 w,u,c,r

    notification_interval 1

    notification_period 24x7

    check_command                   check_nrpe!check_swap

    contact_groups admins

    notifications_enabled 1

    }

    (4)、配置nagios.cfg文件

    # cd /usr/local/nagios/etc

    # vim nagios.cfg找到cfg_file=/usr/local/nagios/etc/objects/localhost.cfg 这行,并把它注释

    添加cfg_dir=/usr/local/nagios/etc/linux

    (5)、配置commands.cfg命令配置文件

    # cd /usr/local/nagios/etc/objects

    # vim commands.cfg,在文件最后添加

    define command {

    command_name service-notify-by-fei

    command_line /usr/local/fetion/fetion --mobile=1381137*** --pwd=***** --to=$CONTACTPAGER$ --msg-utf8="$HOSTNAME$ $SERVICEDESC$ is $SERVICESTATE$ on $TIME$ resu

    lt is $SERVICEOUTPUT$" $CONTACTPAGER$

    }

    define command {

    command_name host-notify-by-fei

    command_line            /usr/local/fetion/fetion --mobile=1381137****  --pwd=**** --to=$CONTACTPAGER$ --msg-utf8="Host $HOSTSTATE$ alert for $HOSTNAME$! on '$LO

    NGDATETIME


« 
» 
快速导航

Copyright © 2016 phpStudy | 豫ICP备2021030365号-3