黑帽联盟

 找回密码
 会员注册
查看: 2539|回复: 0

[运维监控] nagios监控linux服务器(定位原创)

[复制链接]

906

主题

38

听众

3375

积分

管理员

Rank: 9Rank: 9Rank: 9

  • TA的每日心情
    无聊
    8 小时前
  • 签到天数: 1697 天

    [LV.Master]伴坛终老

    nagios监控linux服务器

    监控端(linux主机)   被监控端(linux主机)

    那么他们如何通信呢?
    他们之间是通过nrpe来完成通信的。

    首先客户端(被监控端)进行配置:

    安装顺序:先安装插件程序,再安装nrpe程序,因为nrpe程序依赖插件程序

    添加nagios用户
    useradd -s /sbin/nologin nagios

    安装nagios插件
    tar xf nagios-plugins-2.0.3.tar.gz
    cd nagios-plugins-2.0.3
    ./configure --with-nagios-user=nagios --with-nagios-group=nagios
    make all
    make install

    安装nrpe程序
    tar xf nrpe-2.15.tar.gz
    cd nrpe-2.15
    ./configure --with-nrpe-user=nagios --with-nrpe-group=nagios --with-nagios-user=nagios --with-nagios-group=nagios --enable-command-args --enable-ssl
    make all
    make install-plugin
    make install-daemon
    make install-daemon-config

    配置nrpe
    vim /usr/local/nagios/etc/nrpe.cfg
    修改allowed_hosts=192.168.10.129            (监控端的ip)
    通过nrpe检测本地磁盘使用大小:
    修改nrpe配置文件:
    command[check_sda1]=/usr/local/nagios/libexec/check_disk -w 20% -c 10% -p /dev/sda1
    command[check_sda2]=/usr/local/nagios/libexec/check_disk -w 20% -c 10% -p /dev/sda2

    sda1和sda2是被监控端上的磁盘。

    添加nrpe服务启动脚本
    vim /etc/init.d/nrped

    #! /bin/bash
    # chkconfig: 2345 88 12
    # description: NRPE DAEMON

    NRPE=/usr/local/nagios/bin/nrpe
    NRPECONF=/usr/local/nagios/etc/nrpe.cfg

    case "$1" in
      start)
        echo -n "Starting NRPE daemon..."
        $NRPE -c $NRPECONF -d
        echo " done."
        ;;
      stop)
        echo -n "Stopping NRPE daemon..."
        pkill -u nagios nrpe
        echo " done."
        ;;
      restart)
        $0 stop
        sleep 2
        $0 start
        ;;
      *)
        echo "Usage: $0 start|stop|restart"
        ;;
      esac
    exit 0

    再者就是启动nrpe服务
    service nrped start
    chkconfig nrped on


    下面再安装监控端相应的程序:
    nagios程序和插件程序安装完成之后,再安装nrpe程序,这里nrpe的版本号是4.0.7

    tar xf nrpe-2.15.tar.gz
    cd nrpe-2.15
    ./configure --prefix=/service/nagios --datadir=/service/apache2.2/htdocs/nagios --sysconfdir=/service/nagios/etc --with-nrpe-user=nagios --with-nrpe-group=nagios --with-nagios-user=nagios --with-nagios-group=nagios --enable-command-args --enable-ssl
    make all
    make install-plugin

    在commands.cfg里添加相应的命令,即check_nrpe
    define command{
            command_name    check_nrpe
            command_line    $USER1$/check_nrpe -H "$HOSTADDRESS$" -c $ARG1$
    }

    在/service/nagios/etc/objects/路径下单独新建一个控制linux主机(被监控端)配置文件
    vim linhost.cfg

    define host {
            use             linux-server
            host_name       linhost            (这里的主机名称不要和其它主机名称一样,不然冲突)
            alias           My Linux Host
            address         192.168.10.130    (被监控端的ip地址)
    }

    define service{
            use                     generic-service
            host_name               linhost
            service_description     CHECK USERS
            check_command           check_nrpe!check_users
    }

    define service{
            use                     generic-service
            host_name               linhost
            service_description     Load
            check_command           check_nrpe!check_load
    }


    define service{
            use                     generic-service
            host_name               linhost
            service_description     CHECK sda1
            check_command           check_nrpe!check_sda1
    }

    define service{
            use                     generic-service
            host_name               linhost
            service_description     CHECK sda2
            check_command           check_nrpe!check_sda2
    }


    define service{
            use                     generic-service
            host_name               linhost
            service_description     Zombie
            check_command           check_nrpe!check_zombie_procs
    }

    define service{
            use                     generic-service
            host_name               linhost
            service_description     Total procs
            check_command           check_nrpe!check_total_procs
    }


    接着在nagios主配置文件当中添加一条信息,引用linhost.cfg配置文件,加载进来
    vim /service/nagios/etc/nagios.cfg

    cfg_file=/service/nagios/etc/objects/linhost.cfg        (添加的信息)


    最后在检查nagios配置文件语法对错:
    /service/nagios/bin/nagios -v /etc/nagios/nagios.cfg

    没出错,就重启nagios服务
    service nagios restart

    验证:

    nagios监控

    nagios监控



    相关文章:nagios安装配置
    您需要登录后才可以回帖 登录 | 会员注册

    发布主题 !fastreply! 收藏帖子 返回列表 搜索
    回顶部