nagios安装以及NRPE的安装

nagios不检测任何具体数值指示(如操作系统上的进程个数),它只描述四种被监控对象的状态:OK,WARNING,CRITICAL和UNKNOWN。于是,我们只需要对魔种监控对象的WARNING和CRITICAL状态的阈值进行关注,nagios将阈值传递给插件,由插件负责具体对象的监控以及结果分析,其返回四中状态信息

nagios监控的不同对象的不同方式
   linux/UNIX: SNMP,NRPE,send-nsca
   switch: SNMP
   print: SNMP
   windows: SNMP,NSClient++ :它包含nrpe,nsca的功能

      nrpe:  0.0.0.0:5666
      需要在nagios以及监控对象上同时安装nrpe 以及nagios plugins

      nsca:
      被动模式,由监控对象主动向nagios发送消息

      nsclient++: 是一个客户端,监听在0.0.0.0:12489
 

安装nagios之前的准备
  安装依赖关系:(此处因为需要对mysql进行检测,所以需要安装mysql)
    # yum -y install httpd gcc glibc glibc-common gd gd-devel php php-mysql mysql mysql-devel mysql-server

  创建用户以及组
    # groupadd nagcmd
    # useradd -G nagcmd nagios
    # passwd nagios

  将组附加给apache用户
    # usermod -a -G nagcmd apache

编译安装nagios
  # tar zxf nagios-3.3.1.tar.gz
  # cd nagios-3.3.1
  # ./configure --with-command-group=nagcmd --enable-event-broker
  # make all
  # make install
  # make install-init
  # make install-commandmode
  # make install-config
  # make install-webconf

创建一个登陆nagios web的用户
  # htpasswd -c /usr/local/nagios/etc/htpasswd.user nagiosadmin

以上配置完成后启动httpd
  # service httpd restart

安装nagios插件(nagios检测完全依赖于各种插件)
  # tar zxf nagios-plugins-1.4.15.tar.gz
  # cd nagios-plugins-1.4.15
  # ./configure --with-nagios-user=nagios --with-nagios-group=nagios
  # make
  # make install


将nagios加入服务并配置为开机启动
  # chkconfig --add nagios
  # chkconfig --level 345 nagios on

检查配置文件语法是否正确
  # /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg

启动nagios
  # service nagios start

关闭selinux或者设置标签
# chcon -R -t httpd_sys_content_t /usr/local/nagios/sbin
# chcon -R -t httpd_sys_content_t /usr/local/nagios/share

至此,nagios的安装完成,可以通过web进行访问 http://ip/nagios





基于NRPE监控远程linux主机
NRPE用于在远端服务器上运行监测命令的守护进程,它用于让nagios监控端基于安装的方式触发远端主机上的检测命令,并将检测结果输出至监控端,其执行开销远低于ssl,检测过程不需要远程主机上的账号等信息,所以安全性也高于ssh

安装配置被监控端

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

  NRPE依赖于nagios plugins,需要先安装
    # tar zxf nagios-plugins-1.4.15.tar.gz
    # cd nagios-plugins-1.4.15
    # ./configure --with-nagios-user=nagios --with-nagios-group=nagios
    # make
    # make install

  安装NRPE
    # tar -zxvf nrpe-2.12.tar.gz
    # cd nrpe-2.12
    # ./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.conf

    log_facility=daemon
    pid_file=/var/run/nrpe.pid
    server_address=127.0.0.1   ;listener address
    server_port=5666
    nrpe_user=nagios
    nrpe_group=nagios
    allowed_hosts=172.16.10.1     ;nagios server address
    command_timeout=60
    connection_timeout=300
    debug=0

    command[cmd_name]=/usr/local/nagios/


启动NRPE
  # /usr/local/nagios/bin/nrpe -c /usr/local/nagios/etc/nrpe.cfg -d

定义一个服务的脚本
vim /etc/rc.d/init.d/nrped


#!/bin/bash
#
# chkconfig: 2345 88 12
# description: NRPE DAEMON
#
.  /etc/rc.d/init.d/functions

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 "Stoping NRPE daemon..."
    pkill -u nagios nrpe
    echo "done."
    ;;
  restart)
    $0 stop
    sleep 1
    $0 start
    ;;
  *)
    echo "Usage: $0 start|stop|restart"
    ;;
  esca
exit 0



服务端配置(nagios监控端)

  安装NRPE
    # tar -zxvf nrpe-2.12.tar.gz
    # cd nrpe-2.12
    # ./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
 
  检测与监控对象间的连接是否可用
    # cd /usr/local/nagios/libexec/
    # ./check_nrpe -H 172.16.100.11
    NRPE v2.12

posted @ 2016-01-15 14:42  Mr.hale  阅读(359)  评论(0编辑  收藏  举报