Chinaunix首页 | 论坛 | 博客
  • 博客访问: 745698
  • 博文数量: 256
  • 博客积分: 3502
  • 博客等级: 中校
  • 技术积分: 3988
  • 用 户 组: 普通用户
  • 注册时间: 2012-04-17 21:13
文章分类

全部博文(256)

文章存档

2014年(11)

2013年(134)

2012年(111)

我的朋友

分类:

2012-11-01 13:40:10

CentOS 5.5 x86_64

服务器平台

nagios-3.2.3.tar.gz

NAGIOS 核心

nagios-plugins-1.4.15.tar.gz

NAGIOS 插件

rrdtool-1.4.4.tar.gz

绘图引擎

pnp4nagios-0.6.7.tar.gz

以图形方式显示nagios监控

nrpe-2.12.tar.gz

监控插件

 

         系统按默认,完成后需要安装gcc等包

# yum install gcc openssl-devel libxml2 libxml2-devel cairo-devel pango-devel

 

NAGIOS安装】

# useradd nagios               创建nagios 用户

# passwd nagios                nagios用户添加密码

# groupadd nagcmd         创建用户组用于Web接口执行外部命令

# usermod –G nagcmd nagios                   nagios 用户加入nagcmd

# usermod –G nagcmd apache        apache 用户加入nagcmd

 

# tar -zxvf nagios-3.2.3.tar.gz

# cd nagios-3.2.3

# ./configure --with-command-group=nagcmd

*** Configuration summary for nagios 3.2.3 10-03-2010 ***:

 

 General Options:

 -------------------------

        Nagios executable:  nagios

        Nagios user/group:  nagios,nagios

       Command user/group:  nagios,nagcmd

            Embedded Perl:  no

             Event Broker:  yes

        Install ${prefix}:  /usr/local/nagios

                Lock file:  ${prefix}/var/nagios.lock

   Check result directory:  ${prefix}/var/spool/checkresults

           Init directory:  /etc/rc.d/init.d

  Apache conf.d directory:  /etc/httpd/conf.d

             Mail program:  /bin/mail

                  Host OS:  linux-gnu

 

 Web Interface Options:

 ------------------------

                 HTML URL:  

                  CGI URL:  cgi-bin/

 Traceroute (used by WAP):  /bin/traceroute

 

 

Review the options above for accuracy.  If they look okay,

type 'make all' to compile the main program and CGIs.

 

 

# make all

*** Compile finished ***

 

If the main program and CGIs compiled without any errors, you

can continue with installing Nagios as follows (type 'make'

without any arguments for a list of all possible options):

 

  make install

     - This installs the main program, CGIs, and HTML files

 

  make install-init

     - This installs the init script in /etc/rc.d/init.d

 

  make install-commandmode

     - This installs and configures permissions on the

       directory for holding the external command file

 

  make install-config

     - This installs *SAMPLE* config files in /usr/local/nagios/etc

       You'll have to modify these sample files before you can

       use Nagios.  Read the HTML documentation for more info

       on doing this.  Pay particular attention to the docs on

       object configuration files, as they determine what/how

       things get monitored!

 

  make install-webconf

     - This installs the Apache config file for the Nagios

       web interface

 

# make install

# make install-init

# make install-commandmode

# make install-config

# make install-webconf

 

         到此为止nagios 核心安装完成

 

         定义联系人或组,当被监控机报警时可以及时的通知相关人员,最简单的方法是通过邮件通知(系统已默认安装了sendmail

# /usr/local/nagios/etc/objects/contacts.cfg

         email 处填入你的邮箱地址,既可当主机或服务报警时发邮件通知

         如果想通过短信通知可以通过139或其它手机邮箱,但曾经用过的人说会有延迟的问题,如果是公司用,可以买一个短信设备,当报警的时候通过短信设备即时发到手机,这是最快捷的方法,也是最多公司用的方法。

 

         添加nagios 认证的用户和密码,登录nagios时要用到,这里新建一个nagiosadmin的用户,如果用户名是其它需要改cgi.cfg 文件,因为cgi.cfg 中默认的认证用户是nagiosadmin

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

 

安装nagios-plugins

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

# cd nagios-plugins-1.4.15

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

            --with-apt-get-command:

              --with-ping6-command: /bin/ping6 -n -U -w %d -c %d %s

               --with-ping-command: /bin/ping -n -U -w %d -c %d %s

                       --with-ipv6: yes

                      --with-mysql: no

                    --with-openssl: no

                     --with-gnutls: no

               --enable-extra-opts: no

                       --with-perl: /usr/bin/perl

             --enable-perl-modules: no

                     --with-cgiurl: /nagios/cgi-bin

               --with-trusted-path: /bin:/sbin:/usr/bin:/usr/sbin

                   --enable-libtap: no

 

# make

# make install

 

         Nagios 加入服务列表,以使在系统启动时自动启动

# chkconfig --add nagios

# chkconfig nagios on

 

         验证nagios 样例文件,没修改过都会通过的,验证没错后可以启动Nagios 服务

# /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg

# service nagios start

 

         启动httpd ,使httpd 服务开机时启动

# chkconfig httpd on

# service httpd start

 

         现在可以通过浏览器访问 nagios ,登录的用户名和密码就是刚刚htpasswd添加的用户名和密码

 

NRPE安装】

         Nagios默认插件只能监控远程服务器的外部信息,如果要监控内部信息如:load average、内存使用情况,磁盘使用情况等,就要用到NRPE

         NRPE需要安装在监控服务器上,被监控服务器需要安装nagios-pluginsnrpe,大概原理是监控机通过SSL发送nrpe的指令给被监控机,要求被监控在本地执行某个内部检测命令,如check_disk,监控机把check_disk命令返回的信息发回监控服务器

Nrpe 包中有相关的安装和使用说明pdf,不过全是E文的,但不难。

 

监控机安装npre

# tar –zxvf nrpe-2.12.tar.gz

# ./configure

# make all

# make install-plugin

 

         修改commands.cfg 文件,最后加入一段

# vim /usr/local/nagios/etc/objects/commands.cfg

# 'check_nrpe' command definition

define command{

        command_name    check_nrpe

        command_line    $USER1$/check_nrpe -H $HOSTADDRESS$ -c $ARG1$

        }

 

         被监控机安装nprenagios-plugins

# useradd nagios

# passwd nagios

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

# ./configure

# make

# make install

# chown nagios.nagios /usr/local/nagios                  修改nagios目录的拥有限

# chown -R nagios.nagios /usr/local/nagios/libexec       修改插接的拥有权

 

# tar -zxvf nrpe-2.12.tar.gz

# cd nrpe-2.12

# ./configure             #如果提示Cannot find ssl headers请安装openssl-devel

# make all

# make install-plugin

# make install-daemon

# make install-daemon-config

# make install-xinetd

 

修改service ,添加以下行

# vim /etc/services

nrpe            5666/tcp                        #NRPE

         修改nrpe配置文件,加入监控机的IP,否则监控机不能连接被监控机

# vim /etc/xinetd.d/nrpe

only_from       = 127.0.0.1后加入 192.168.2.141(不同地址间加空格)

         这里提醒一下,如果nrpe不是运行在inetdxinetd下,允许来访地址的配置会在/usr/local/nagios/etc/nrpe.cfg文件里的allowed_hosts

         重启xinetd 服务

# service xinetd restart

 

         简单测试一下两台机间的SSL握手通不能,在监控机上运行

# /usr/local/nagios/libexec/check_nrpe -H hostname    #hostname为被监控机地址

NRPE v2.12                正常的话会显示对方的NRPE版本

 

# /usr/local/nagios/libexec/check_nrpe -H hostname -c check_load

OK - load average: 0.00, 0.00, 0.00|load1=0.000;15.000;30.000;0; load5=0.000;10.000;25.000;0; load15=0.000;5.000;20.000;0;

 

         Nagios 中添加一台host和几个service

         修改Nagios主配置文件

# vim /usr/local/nagios/etc/nagios.cfg

cfg_file=/usr/local/nagios/etc/objects/client.cfg  #加入nagios配置中

         新建一个定义主机和服务器配置文件

# vim /usr/local/nagios/etc/objects/client.cfg

define host{                                                              #定义主机

        host_name                client                  #此名字显示在Nagios的页面上

        use                               linux-server      #如果use改其它名字,需要在templates.cfg在重新定义

        address                      IP                        #ip为被监控服务器的IP地址

        check_period            24x7                            #检查的周期

        check_interval          5                          #检查的时间间隔

        retry_interval           1                          #重试时间间隔

        max_check_attempts      10              #最大尝试次数

        check_command      check-host-alive       #检测的命令

        notification_period  24x7                            #通知的周期

        notification_interval         30              #通知的时间间隔

        notification_options         d,u             #通知选项dDOWN机,uUNREACHABLE

        contact_groups                 admins     #通知的组

}

 

define service{                                                         #定义服务

        host_name                         client        #主机名为client

        use                                        generic-service         #如果修改同样要在templates.cfg中定义

        check_command               check_nrpe!check_load  #通过check_nrpe检测远程服务器

        service_description          check_load       #服务的描述,可以随便写

        notifications_enabled      1                          #通知启用

        event_handler_enabled  1                          #事件处理启用

        notification_period           24x7                            #通知周期

        check_period                      24x7                            #检测周期

        max_check_attempts      3                          #最大尝试次数

        check_interval                   5                          #检测间隔时间

        contact_groups                 admins              #联系组

        retry_check_interval        2                          #重试间隔时间

        notification_options         w,u,c                  #通知选项w警告,uUnknowc为危险

}

~                                           

         说明:check_load服务5分钟检测一次,当警告,或未知,或危险情况的时候尝试3次,3次期间是2分钟一次,每4次的时候就通知相关的联系组

 

PNP4NAGIOS安装】

         安装pnp4nagios前先安装rrdtools,不安装rrdtools 安装pnp4nagios的时候会提示找不到rrdtools

         首先改一下pkgconfig 的环境变量,否则安装rrdtools会说找不到pkgconfig

# export PKG_CONFIG_PATH=${INSTALL_DIR}/lib64/pkgconfig

#我的系统是64位的,如果是32位的朋友请把lib64改为lib

# export PATH=$INSTALL_DIR/bin:$PATH

 

# tar -zxvf rrdtool-1.4.4.tar.gz

# ./configure --prefix=/usr/local/rrdtool-1.4.4

# make && make install

 

# tar -zxvf pnp4nagios-0.6.7.tar.gz

# ./configure --prefix=/usr/local/pnp4nagios-0.6.7 --with-rrdtool=/usr/local/rrdtool-1.4.4/bin/rrdtool

# make all

# make install

# make install-webconf

# make install-config

# make install-init

 

         因为pnp4nagios 需要php5.2或以上的版本,所以要先删除系统自带的5.1

# yum erase php php-cli php-common php-ldap

         再安装5.2或以上的版本,如果想通过yum 安装,可以参考我blog 里的一篇关于yum 安装5.2 的文章

http://blog.163.com/buypc_hao/blog/static/107920775200992921121218/

 

# yum install php php-gd

# rpm -qa |grep php

php-5.2.14-jason.1

php-cli-5.2.14-jason.1

php-gd-5.2.14-jason.1

php-common-5.2.14-jason.1

 

         安装完成后打开会看到pnp4nagios 环境测试结果,如果按以上方法来安装,全部都会pass ,最后有一行绿色低的英文

    Your environment passed all requirements. Remove or rename the install.php file now.

# rm /usr/local/pnp4nagios-0.6.7/share/install.php       #删除install.php文件

 

         修改nagios 的模板文件,在对应的主机和服务定义字段里加入以下内容,

# vim /usr/local/nagios/etc/objects/templates.cfg

因为我nagios 中主机的name linux-server ,所以我在name linux-server 中加入

        action_url /pnp4nagios/index.php?host=$HOSTNAME$

        process_perf_data               1

nagios 中服务的的name generic-service ,所以我在name generic-service 中加入

        action_url /pnp4nagios/index.php?host=$HOSTNAME$&srv=$SERVICEDESC$

        process_perf_data               1

 

         修改nagios 配置文件

# vim /usr/local/nagios/etc/nagios.cfg

process_performance_data=0 改为 process_performance_data=1

#host_perfdata_command=process-host-perfdata

#service_perfdata_command=process-service-perfdata

前面的两个注释去掉

 

# cd /usr/local/pnp4nagios-0.6.7/etc

# cp process_perfdata.cfg-sample process_perfdata.cfg

# cp npcd.cfg-sample npcd.cfg

# cp rra.cfg-sample rra.cfg

 

         如果pnp4nagios 不能正常显示,请按以下方法修改一下

         打开/usr/local/pnp4nagios-0.6.7/etc/misccommands.cfg-sample

拷贝并修改Synchronous mode相应的命令行到nagioscommand.cfg 内部,把command原来定义的process-service-perfdataprocess-host-perfdata注释掉

# vim /usr/local/nagios/etc/objects/commands.cfg

define command {

       command_name    process-service-perfdata

       command_line    /usr/bin/perl /usr/local/pnp4nagios-0.6.7/libexec/process_

perfdata.pl

}

 

define command {

       command_name    process-host-perfdata

       command_line    /usr/bin/perl /usr/local/pnp4nagios-0.6.7/libexec/process_

perfdata.pl -d HOSTPERFDATA

}

 

 

 

         保存退出后重启nagios  httpd ,再重新打开nagios 页面,会发现所有的service  hosts 旁边多了一个小太阳的图标,这说明定义正确了.

         Nagios 配置也到这里结束了,有什么问题可以发邮件或加QQ大家一起讨论一下。

 

         下面记录了部份的关于nagios 的配置文件和文件夹的说明 ,给大家参考一下

 

bin

Nagios 执行程序

etc

Nagios 配置文件

sbin

Nagios cgi文件所在目录,也就是执行外部命令所需要文件所在的目录

share

Nagios 网页文件所在的目录

var

Nagios 日志文件、spid等文件所在的目录

var/archive

存放存档日志的空目录

var/rw

为外部命令保留的空目录

 

 

htpasswd.users

Nagios 用户名和密码

nagios.cfg

Nagios 主配置文件

contacts.cfg

定义联系人和联系人组

cgi.cfg

cgi 相关的设置

resource.cfg

资源配置文件,包含很少的参数设置

command.cfg

命令配置文件,只有在这里定义过的才能在nagios中调用

templates.cfg

模板文件,内含各种模板

timeperiods.cfg

时间配置文件,定义时间段

阅读(931) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~