Chinaunix首页 | 论坛 | 博客
  • 博客访问: 6551589
  • 博文数量: 1005
  • 博客积分: 8199
  • 博客等级: 中将
  • 技术积分: 13071
  • 用 户 组: 普通用户
  • 注册时间: 2010-05-25 20:19
个人简介

脚踏实地、勇往直前!

文章分类

全部博文(1005)

文章存档

2020年(2)

2019年(93)

2018年(208)

2017年(81)

2016年(49)

2015年(50)

2014年(170)

2013年(52)

2012年(177)

2011年(93)

2010年(30)

分类: LINUX

2015-02-10 16:18:11

环境:
OS:Red Hat Linux As 5
nagios-4.0.8.tar.gz
nagios-plugins-2.0.3.tar.gz
nrpe2.15.tar.gz

平时维护系统都是采用命令输出的形式对系统进行监控,但是很不直观,听说nagios这款监控软件功能比较强大,今天尝试了安装使用了下,感觉还不错哦,记录下安装的过程。

###########################第一步安装apache#######################
因为nagios是基于web界面监控的软件,所以需要在linux下安装apache

1.安装apache
[root@host02 soft]# mkdir -p /usr/local/apache2
[root@host02 soft]# tar -zxvf httpd-2.2.27.tar.gz
[root@host02 soft]# cd httpd-2.2.27
[root@host02 httpd-2.2.27]#./configure --prefix=/usr/local/apache2 --enable--module=so
[root@host02 httpd-2.2.27]# make
[root@host02 httpd-2.2.27]# make install
[root@host02 conf]# /usr/local/apache2/bin/apachectl start


2.配置apache
编辑/usr/local/apache2/conf/httpd.conf,
找到

    DirectoryIndex index.html

修改为

    DirectoryIndex index.html index.php

在最后添加如下内容:
AddType application/x-httpd-php .php
ScriptAlias /nagios/cgi-bin "/usr/local/nagios/sbin"
Alias /nagios "/usr/local/nagios/share"

#############################第二步安装php#########################
[root@host02 soft]# mkdir -p /usr/local/php5
[root@host02 soft]# tar -zxvf php-5.5.21.tar.gz
[root@host02 soft]# cd php-5.5.21
[root@host02 soft]#./configure --prefix=/usr/local/php5 --with-apxs2=/usr/local/apache2/bin/apxs --with-config-file-path=/usr/local/lib --enable-track-vars --with-xml --with-mysql --enable-sockets
[root@host02 php-5.5.21]# make
[root@host02 php-5.5.21]# make install

#############################第三步安装nagios#########################

1.安装基础包
[root@host02 nagios]# yum install -y gcc glibc glibc-common gd gd-devel xinetd openssl-devel

2.创建nagios用户和用户组
[root@host02 nagios]# useradd nagios
[root@host02 nagios]# mkdir /usr/local/nagios
[root@host02 nagios]# chown -R nagios.nagios /usr/local/nagios

3.编译安装Nagios
[root@host02 nagios]# tar -zxvf nagios-4.0.8.tar.gz
[root@host02 nagios]# cd nagios-4.0.8
[root@host02 nagios]#./configure --prefix=/usr/local/nagios

[root@host02 nagios-4.0.8]# make all
[root@host02 nagios-4.0.8]# make install
[root@host02 nagios-4.0.8]# make install-init
[root@host02 nagios-4.0.8]# make install-commandmode
[root@host02 nagios-4.0.8]# make install-config
[root@host02 nagios-4.0.8]# chkconfig --add nagios
[root@host02 nagios-4.0.8]# chkconfig --level 35 nagios on
[root@host02 nagios-4.0.8]# chkconfig --list nagios


4.安装Nagios插件
[root@host02 nagios]# tar -zxvf nagios-plugins-2.0.3.tar.gz
[root@host02 nagios]# cd nagios-plugins-2.0.3
[root@host02 nagios-plugins-2.0.3]# ./configure --prefix=/usr/local/nagios
[root@host02 nagios-plugins-2.0.3]# make && make install


5.启动nagios
[root@host02 nagios]#service nagios start

#########################第四步配置需要被监控的机器##############################
1.在被监控的机器上安装插件
nagios-plugins-2.0.3
安装过程跟前面一致
#tar -zxvf nagios-plugins-2.0.3.tar.gz
#cd nagios-plugins-2.0.3
#./configure --prefix=/usr/local/nagios
#make && make install

2.安装nrpe
# tar -xvf nrpe-2.15.tar.gz
# cd nrpe-2.15
# ./configure
# make all
# make install-plugin
# make install-daemon
# make install-daemon-config
# make install-xinetd


4.编辑文件/etc/xinetd.d/nrpe
vi /etc/xinetd.d/nrpe
修改后的内容如下:
# default: on
# description: NRPE (Nagios Remote Plugin Executor)
service nrpe
{
        flags           = REUSE
        socket_type     = stream
        port            = 5666
        wait            = no
        user            = nagios
        group           = nagios
        server          = /usr/local/nagios/bin/nrpe
        server_args     = -c /usr/local/nagios/etc/nrpe.cfg --inetd
        log_on_failure  += USERID
        disable         = no
        only_from       = 127.0.0.1 192.168.56.112
}
这里的192.168.56.112是监控主机的ip地址

5.配置nrpe服务
编辑/etc/services文件,添加nrpe服务
# Local services
nrpe            5666/tcp                        #nrpe

重启动xinetd服务
[root@host02 etc]# service xinetd restart
Stopping xinetd: [  OK  ]
Starting xinetd: [  OK  ]

检查是否已经启动
[root@host02 etc]# netstat -an|grep 5666
tcp        0      0 0.0.0.0:5666                0.0.0.0:*                   LISTEN


#########################第五步将被监控的机器纳入到监控中###########################
1.手工创建/usr/local/nagios/etc/services.cfg文件,添加如下内容
define service{
        use                     local-service
        host_name               Nagios-Linux
        service_description     Current Load
        check_command           check_nrpe!check_load
        }

define service{
        use                     local-service
        host_name               Nagios-Linux
        service_description     Check Disk sda1
        check_command           check_nrpe!check_sda1
        }

define service{
        use                     local-service
        host_name               Nagios-Linux
        service_description     Total Processes
        check_command           check_nrpe!check_total_procs
        }

define service{
        use                     local-service
        host_name               Nagios-Linux
        service_description     Current Users
        check_command           check_nrpe!check_users
        }

define service{
        use                     local-service
        host_name               Nagios-Linux
        service_description     Check Zombie Procs
        check_command           check_nrpe!check_zombie_procs
        }

##以上的host_name=Nagios-Linux在hosts.cfg中定义

2.手工创建/usr/local/nagios/etc/objects/hosts.cfg文件


define host{
        use                     linux-server
        host_name               Nagios-Linux
        alias                   Nagios-Linux
        address                 192.168.56.111
        }

##这里192.168.56.111是定义被监控的机器的ip地址
define hostgroup{
        hostgroup_name          bsmart-servers
        alias                   bsmart servers
        members                 Nagios-Linux
        }

手工创建了如上的两个文件文件后,需要将这两个文件添加到nagios.cfg中
# You can specify individual object config files as shown below:
cfg_file=/usr/local/nagios/etc/objects/commands.cfg
cfg_file=/usr/local/nagios/etc/objects/contacts.cfg
cfg_file=/usr/local/nagios/etc/objects/timeperiods.cfg
cfg_file=/usr/local/nagios/etc/objects/templates.cfg
## add by hxl
cfg_file=/usr/local/nagios/etc/services.cfg
cfg_file=/usr/local/nagios/etc/objects/hosts.cfg


3.添加swap监控
默认情况下是没有对swap进行监控的,这个需要自己添加
vi /usr/local/nagios/etc/nrpe.cfg

添加如下行
command[check_swap]=/usr/local/nagios/libexec/check_swap -w 20% -c 10%

然后在/usr/local/nagios/etc/services.cfg文件中添加
define service{
        use                     local-service
        host_name               Nagios-Linux
        service_description     Check Swap
        check_command           check_nrpe!check_swap
        }

4.添加check_nrpe定义
编辑/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$
        }


以上步骤全部完成了,重新启动nagios.

安装遇到的问题

1.找不到cgi
The requested URL /nagios/cgi-bin/status.cgi was not found on this server.

解决办法:
确保安装了如下的包
libgd
libgd-devel
libpng
libpng-devel
libjpeg
libjpeg-devel
zlib
zlib-devel

然后进行重新编译nagios
#make devclean
./configure --prefix=/usr/local/nagios --with-gd-lib=/usr/lib --with-gd-inc=/usr/include
#make all
#make install
#make install-init
#make install-config
#make install-commandmode

在httpd.conf添加如下内容后重启动apache

ScriptAlias /nagios/cgi-bin "/usr/local/nagios/sbin"
Alias /nagios "/usr/local/nagios/share"


    #
    # Possible values for the Options directive are "None", "All",
    # or any combination of:
    #   Indexes Includes FollowSymLinks SymLinksifOwnerMatch ExecCGI MultiViews
    #
    # Note that "MultiViews" must be named *explicitly* --- "Options All"
    # doesn't give it to you.
    #
    # The Options directive is both complicated and important.  Please see
    #
    # for more information.
    #
    Options Indexes FollowSymLinks

    #
    # AllowOverride controls what directives may be placed in .htaccess files.
    # It can be "All", "None", or any combination of the keywords:
    #   Options FileInfo AuthConfig Limit
    #
    AllowOverride None

    #
    # Controls who can get stuff from this server.
    #
    Order allow,deny
    Allow from all



2.权限问题
It appears as though you do not have permission to view process information...
If you believe this is an error, check the HTTP server authentication requirements for accessing this CGI
and check the authorization options in your CGI configuration file.
解决办法:
use_authentication=1
修改为
use_authentication=0

 
-- The End --

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