nagios监控系统安装及配置

Nagios一般由一个主程序(Nagios)、一个插件程序(Nagios-plugins)和四个可选的ADDON(NRPE、NSCA、NSClient++和NDOUtils)组成。Ngios的监控工做都是经过插件实现的,所以,Nagios和Nagios-plugins是服务器端工做所必须的组件,而四个ADDON中php

一、NRPE:用来监控远程linux/unix主机上执行脚本插件以实现对这些主机资源的监控mysql

二、NSCA:用来让被监控的远程linux/unix主机主动将监控信息发送给Nagios服务器(这在冗余监控模式中特别要用到)linux

三、NSClient++:用来监控windows主机是安装在windows主机上的组件ios

四、NDOUtils:是用来将Nagios的配置信息和个event产生的数据存入数据库,以实现这些数据的快速检索和处理c++

这四个ADDON(附件)中,NRPE和NSClient++工做与客户端,NDOUtils工做于服务器端,而NSCA则于鏊同事安装在服务器端和客户端web

nagios安装

1、安装nagios须要的rpm包:sql

# yum -y install httpd php mysql-devel php-mysql 数据库

2、添加nagios运行所须要的用户和组apache

# groupadd nagcmdvim

# useradd -G nagcmd nagios

# passwd nagios

把apache加入到nagcmd组,以便于在经过web interface操做nagios时可以具备足够的权限

# usermod -a -G nagcmd apache

3、编译nagios:

# tar -zxvf nagios-3.5.0.tar.gz

# ./configure --sysconfdir=/etc/nagios --with-command-group=nagcmd --enable-event-broker

# make all

# make install

# make install-init

# make install-commandmode

# make install-config

在httpd的配置文件目录(conf.d)中建立nagios的Web程序配置文件

# make install-webconf

--sysconfdir=/etc/nagios  配置文件的位置

--enable-event-broker     可使用你NDOUtils链接mysql数据库的

4、为email指定您想用来接收nagios警告信息的邮件地址,默认是本机的nagios用户

# vim /etc/nagios/objects/contacts.cfg

5、建立一个登陆nagios web程序的用户,这个帐号在之后经过web登录nagios认证是所用:

# htpasswd -c /etc/nagios/htpasswd.users nagiosadmin

6、selinux会组织cgi脚本的运行,要么关闭selinux

# setenforce 0

或者执行下面的两个命令

# chcon -R -t httpd_sys_content_t /usr/local/nagios/sbin

# chcon -R -t httpd_sys_content_t /usr/local/nagios/share

启动apache服务:

# /etc/init.d/httpd start

7、若是源码安装apache是遇到以下问题

./configure --prefix=/usr/local/apache 报错

error: Bundled APR requested but not found at ./srclib/. Download and unpack the corresponding apr and apr-util packages to ./srclib/.

解决方法

cp -fr apr-1.4.8 ./httpd-2.4.6/srclib/apr

cp -fr apr-util-1.5.2 ./httpd-2.4.6/srclib/apr-util

./configure --prefix=/usr/local/apache 继续报错

解决办法安装pcre

安装pcre报错error: You need a C++ compiler for C++ support.

安装c++编译器

yum install -y gcc gcc-c++

8、编译、安装nagios-plugins

nagios的全部监控工做都是经过插件完成的,所以,在启动nagios以前还须要为其安装官方提供的插件

# tar zxvf nagios-plugins-1.4.16.tar.gz

# cd nagios-plugins-1.4.16

# ./configure --with-nagios-user=nagios --with-nagios-group=nagios

# make

# make install

9、将nagios添加到服务列表中并设置为开机自启动

# chkconfig --add nagios

# chkconfig nagios on 2345

10、启动nagios

# /etc/init.d/nagios start

到此为止nagios的页面就能够访问了能够登陆

http://ngiosserverip/ngios访问了

利用nrpe监控linux主机

1、安装nagios-plugins

# tar -zxvf nagios-plugins-1.4.16.tar.gz

# cd nagios-plugins-1.4.16

# useradd -s /sbin/nologin -r nagios

# ./configure --with-nagios-user=nagios --with-nagios-group=nagios

# make all

# make install

2、安装nrpe

# tar -zxvf nrpe-2.15.tar.gz

# cd nrpe-2.15

# ./configure --with-nrep-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

3、启动nrpe进程

# /usr/local/nagios/bin/nrpe -c /usr/local/nagios/etc/nrpe.cfg –d

4、编写nrped启动脚本,设置开机自启动

# vim /etc/init.d/nrped 加入以下内容

#!/bin/sh

nrpe_num=`ps aux | grep /bin/nrpe | grep -v grep | wc -l`

case $1 in

  start)

    if [ $nrpe_num -eq 1 ]

    then

       echo "Error:nrpe is running."

    else

       /usr/local/nagios/bin/nrpe -c /usr/local/nagios/etc/nrpe.cfg -d

       echo "nrpe started successfully."

    fi

  ;;

  stop)

    if [ $nrpe_num -eq 1 ]

    then

       nrpe_pid=`ps aux | grep /bin/nrpe | grep -v grep | awk '{print $2}'`

       kill -9 $nrpe_pid

       echo "nrpe stoped successfully."

    else

       echo "Error:nrpe is stoping."

    fi

  ;;

  restart)

    if [ $nrpe_num -eq 1 ]

    then

       nrpe_pid=`ps aux | grep /bin/nrpe | grep -v grep | awk '{print $2}'`

       kill -9 $nrpe_pid

       echo "nrpe stoped successfully."

       /usr/local/nagios/bin/nrpe -c /usr/local/nagios/etc/nrpe.cfg -d

       echo "nrpe started successfully."

    else

       echo "Error:nrpe is stoping"

       /usr/local/nagios/bin/nrpe -c /usr/local/nagios/etc/nrpe.cfg -d

       echo "nrpe started successfully."

    fi

esac

赋予nrped执行权限:

# chmod 755 nrped

# chkconfig --add nrped

# chkconfig --list nrped

若是2345是关闭

# chkconfig --level 2345 nrped on

5、服务端也要安装nrpe

# ./configure --sysconfdir=/etc/nagios --with-nrep-user=nagios --with-nrpe-group=nagios --with-nagios-user=nagios --with-nagios-group=nagios --enable-command-args --enable-ssl

本人习惯:服务端的配置文件所有都在etc目录下,client端的文件通常放在源码文件中,因此在服务端编译的时候都指定了配置文件的路径,而在客户端并未指定配置文件目录

其他部分和client端同样                                                          

利用NSClient++监控windows主机

须要准备的插件:

NSClient++-0.3.8-x64

Allowed hosts:容许谁检测

NSClient password:fanjinbao;经过什么密码来监控

运行NSClient++后检查是否开启了12489的端口

相关文章
相关标签/搜索