Chinaunix首页 | 论坛 | 博客
  • 博客访问: 274884
  • 博文数量: 41
  • 博客积分: 2560
  • 博客等级: 少校
  • 技术积分: 465
  • 用 户 组: 普通用户
  • 注册时间: 2010-07-01 15:56
文章分类

全部博文(41)

文章存档

2011年(10)

2010年(31)

我的朋友

分类: LINUX

2010-07-21 14:54:21

一、
环境:
IP:192.168.202.18(监控服务器)
IP:192.168.202.19(被监控服务器)
软件:
wget
wget
wget
yum -y install openssl-devel
监控服务器:
1. 安装nagios-3.2.1.tar.gz
useradd nagios
tar -zxvf nagios-3.2.1.tar.gz
cd nagios-3.2.1
 ./configure --prefix=/usr/local/nagios --with-gd-lib=/usr/local/lib --with-gd-inc=/usr/local/include --with-nagios-user=nagios --with-nagios-group=nagios
#./configure --prefix=/usr/local/nagios --with-nagios-user=nagios --with-nagios-group=nagios
make all
make install
make install-init
make install-commandmode
make install-config
2.安装nagios-plugins-1.4.14.tar.gz
tar -zxvf nagios-plugins-1.4.14.tar.gz
cd nagios-plugins-1.4.14
./configure --prefix=/usr/local/nagios --with-nagios-user=nagios --with-nagios-group=nagios
make
make install
3.nrpe的程序的安装:
tar zxvf nrpe-2.12.tar.gz
cd nrpe-2.12
./configure --enable-command-args(nrpe参数传递)
make all
make install-plugin
make install-daemon
make install-daemon-config

被监控机器:
1.安装nagios-plugins-1.4.14.tar.gz
tar -zxvf nagios-plugins-1.4.14.tar.gz
cd nagios-plugins-1.4.14
./configure --prefix=/usr/local/nagios --with-nagios-user=nagios --with-nagios-group=nagios
make
make install
2.nrpe的程序的安装:
tar zxvf nrpe-2.12.tar.gz
cd nrpe-2.12 --enable-command-args
./configure
make all
make install-plugin
make install-daemon
make install-daemon-config
make install-xinetd


ok,安装好了,可以到/usr/local/nagios/下面检查一下,应该生成了4个目录:bin、etc、libexec、share。之后我们要配置一下,目的是让NRPE可以以守护进程的形式监听5666端口,为特定地址的nagios平台提供服务。在官方的NRPE文档中,详细说明了如何将NRPE嵌入xinetd服务中,我在这里就不啰嗦了。有些情况,我们的服务器上没有xinetd或者inetd这样的服务,我在这里介绍一种更加通用的方法。
首先,需要修改/usr/local/nagios/etc/nrpe.cof。
找到“allowed_hosts=127.0.0.1”将其改为:nagios监控平台的地址或域名
启动NRPE守护进程:(可以将此命令加入/etc/rc.local,以便开机自动启动)
vi /etc/service
增加:nrpe            5666/tcp
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       = 192.168.202.18 127.0.0.1(允许监控的机器IP)


/usr/local/nagios/bin/nrpe –c /usr/local/nagios/etc/nrpe.cfg –d或 /etc/init.d/xinetd restart

/usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg (检查配置文件)
[root@xen_202_18 etc]# /etc/init.d/nagios start
[root@xen_202_18 etc]# /usr/local/nagios/libexec/check_nrpe -H 192.168.202.19
NRPE v2.12
说明nrpe已经成功
二、apache安装

配置:
ScriptAlias /nagios/cgi-bin "/usr/local/nagios/sbin"


   Options ExecCGI
   AllowOverride None
   Order allow,deny
   Allow from all
   AuthName "Nagios Access"
   AuthType Basic
   AuthUserFile /usr/local/nagios/etc/htpasswd.user
   Require valid-user


Alias /nagios "/usr/local/nagios/share"


   Options None
   AllowOverride None
   Order allow,deny
   Allow from all
   AuthName "Nagios Access"
   AuthType Basic
   AuthUserFile /usr/local/nagios/etc/htpasswd.user
   Require valid-user

/usr/local/httpd/bin/htpasswd -c /usr/local/nagios/etc/htpasswd.user nagiosadmin
三、配置
监控服务器:
/usr/local/nagios/etc
nagios.cfg#配置文件
cgi.cfg # 控制相关的cgi脚本配置文件
resource.cfg # 外部命令资源配置文件
objects/commands.cfg # 定义一些nagios的检查命令.
#objects/localhost.cfg # 定义本机检查配置文件
#objects/switch.cfg # 定义交换机检查配置文件
#objects/printer.cfg # 定义打印机检查配置文件
#objects/windows.cfg # 定义windows主机检查配置文件
objects/timeperiods.cfg # 定义监控时段配置文件
objects/templates.cfg # 主机监控配置文件模版
objects/contacts.cfg # 联系人配置文件

在commands.cfg里添加
#check nrpe
define command{
command_name check_nrpe
command_line $USER1$/check_nrpe -H $HOSTADDRESS$ -c $ARG1$ -a $ARG2$ $ARG3$ $ARG4$ $ARG5$
}

监控机配置文件
define host{
        use                     linux-server
        host_name               192.168.202.19
        alias                   192.168.202.19
        address                 192.168.202.19
        }
define hostgroup{
        hostgroup_name  linux-servers
        alias           Linux Servers
        members         192.168.202.19
        }
define service{
        use                             local-service
        host_name                       192.168.202.19
        service_description             Root Partition
        check_command                   check_nrpe!check_disk!20%!10%!/
        }
define service{
        use                             local-service
        host_name                       192.168.202.19
        service_description             Root Partition
        check_command                   check_nrpe!check_disk!20%!10%!/dev/shm
        }
define service{
        use                             local-service
        host_name                       192.168.202.19
        service_description             Current Users
        check_command                   check_nrpe!check_users!10!20
        }
define service{
        use                             local-service
        host_name                       192.168.202.19
        service_description             Total Processes
        check_command                   check_nrpe!check_procs!800!1000!RSZDT
        }
define service{
        use                             local-service
        host_name                       192.168.202.19
        service_description             Current Load
        check_command                   check_nrpe!check_load!10,10,10!20,20,20
        }
define service{
        use                             local-service
        host_name                       192.168.202.19
        service_description             Swap Usage
        check_command                   check_nrpe!check_swap!20!10
        }
define service{
        use                             local-service
        host_name                       192.168.202.19
        service_description             SSH
        check_command                   check_ssh
        notifications_enabled           0
        }
define service{
        use                             local-service
        host_name                       192.168.202.19
        service_description             HTTP
        check_command                   check_http!-u /a.txt
        }

被监控服务器:
vi /usr/local/nagios/etc/nrpe.cfg
log_facility=daemon
pid_file=/var/run/nrpe.pid
server_port=5666
nrpe_user=nagios
nrpe_group=nagios
allowed_hosts=192.168.202.18,127.0.0.1
 
# Values: 0=do not allow arguments, 1=allow command arguments(这边采用命令传递方式)
dont_blame_nrpe=1
debug=0
command_timeout=60
connection_timeout=300
#command[check_users]=/usr/local/nagios/libexec/check_users -w 5 -c 10
command[check_users]=/usr/local/nagios/libexec/check_users -w $ARG1$ -c $ARG2$
command[check_load]=/usr/local/nagios/libexec/check_load -w $ARG1$ -c $ARG2$
command[check_disk]=/usr/local/nagios/libexec/check_disk -w $ARG1$ -c $ARG2$ -p $ARG3$
command[check_procs]=/usr/local/nagios/libexec/check_procs -w $ARG1$ -c $ARG2$ -s $ARG3$
command[check_swap]=/usr/local/nagios/libexec/check_swap -w $ARG1$ -c $ARG2$
command[check_zombie_procs]=/usr/local/nagios/libexec/check_procs -w $ARG1$ -c $ARG2$ 10 -s Z
command[check_total_procs]=/usr/local/nagios/libexec/check_procs -w $ARG1$ -c $ARG2$

[root@xen_202_18 etc]# /usr/local/nagios/libexec/check_nrpe -H 192.168.202.19
NRPE v2.12


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