黑帽联盟

 找回密码
 会员注册
查看: 1574|回复: 0
打印 上一主题 下一主题

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

[复制链接]

852

主题

38

听众

3175

积分

白金VIP

Rank: 8Rank: 8

  • TA的每日心情
    开心
    2024-3-7 12:52
  • 签到天数: 1538 天

    [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安装配置
    帖子永久地址: 

    黑帽联盟 - 论坛版权1、本主题所有言论和图片纯属会员个人意见,与本论坛立场无关
    2、本站所有主题由该帖子作者发表,该帖子作者与黑帽联盟享有帖子相关版权
    3、其他单位或个人使用、转载或引用本文时必须同时征得该帖子作者和黑帽联盟的同意
    4、帖子作者须承担一切因本文发表而直接或间接导致的民事或刑事法律责任
    5、本帖部分内容转载自其它媒体,但并不代表本站赞同其观点和对其真实性负责
    6、如本帖侵犯到任何版权问题,请立即告知本站,本站将及时予与删除并致以最深的歉意
    7、黑帽联盟管理员和版主有权不事先通知发贴者而删除本文

    勿忘初心,方得始终!
    您需要登录后才可以回帖 登录 | 会员注册

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