阿里云-云小站(无限量代金券发放中)
【腾讯云】云服务器、云数据库、COS、CDN、短信等热卖云产品特惠抢购

Nagios监控系统安装及配置

177次阅读
没有评论

共计 4859 个字符,预计需要花费 13 分钟才能阅读完成。

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

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

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

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

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

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

nagios 安装

一、安装 nagios 需要的 rpm 包:

# yum -y install httpd php mysql-devel php-mysql 

二、添加 nagios 运行所需要的用户和组

# groupadd nagcmd

# useradd -G nagcmd nagios

# passwd nagios

把 apache 加入到 nagcmd 组,以便于在通过 web interface 操作 nagios 时能够具有足够的权限

# usermod -a -G nagcmd apache

三、编译 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 数据库的

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

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

五、创建一个登录 nagios web 程序的用户,这个账号在以后通过 web 登陆 nagios 认证是所用:

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

六、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

七、如果源码安装 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++

八、编译、安装 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

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

# chkconfig –add nagios

# chkconfig nagios on 2345

十、启动 nagios

# /etc/init.d/nagios start

到此为止 nagios 的页面就可以访问了可以登录

http://ngiosserverip/ngios 访问了

利用 nrpe 监控 linux 主机

一、安装 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

二、安装 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

三、启动 nrpe 进程

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

四、编写 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

五、服务端也要安装 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

Nagios 监控系统安装及配置

Allowed hosts:允许谁检测

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

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

Nagios 监控系统安装及配置

在 Ubuntu 下配置 Mrtg 监控 Nginx 和服务器系统资源 http://www.linuxidc.com/Linux/2013-08/88417.htm 

使用 snmp+Mrtg 监控 Linux 系统 http://www.linuxidc.com/Linux/2012-11/73561.htm 

Mrtg 服务器搭建(监控网络流量)http://www.linuxidc.com/Linux/2012-07/64315.htm 

网络监控器 Nagios 全攻略 http://www.linuxidc.com/Linux/2013-07/87067.htm

Nagios 搭建与配置详解 http://www.linuxidc.com/Linux/2013-05/84848.htm 

Nginx 环境下构建 Nagios 监控平台 http://www.linuxidc.com/Linux/2011-07/38112.htm 

在 RHEL5.3 上配置基本的 Nagios 系统(使用 Nagios-3.1.2) http://www.linuxidc.com/Linux/2011-07/38129.htm

CentOS 5.5+Nginx+Nagios 监控端和被控端安装配置指南 http://www.linuxidc.com/Linux/2011-09/44018.htm

Ubuntu 13.10 Server 安装 Nagios Core 网络监控运用 http://www.linuxidc.com/Linux/2013-11/93047.htm

Nagios 系统监控基本安装配置过程详解 http://www.linuxidc.com/Linux/2017-01/139758.htm

Nagios 的详细介绍:请点这里
Nagios 的下载地址:请点这里 

本文永久更新链接地址:http://www.linuxidc.com/Linux/2017-01/140004.htm

正文完
星哥说事-微信公众号
post-qrcode
 0
星锅
版权声明:本站原创文章,由 星锅 于2022-01-21发表,共计4859字。
转载说明:除特殊说明外本站文章皆由CC-4.0协议发布,转载请注明出处。
【腾讯云】推广者专属福利,新客户无门槛领取总价值高达2860元代金券,每种代金券限量500张,先到先得。
阿里云-最新活动爆款每日限量供应
评论(没有评论)
验证码
【腾讯云】云服务器、云数据库、COS、CDN、短信等云产品特惠热卖中