Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1456762
  • 博文数量: 408
  • 博客积分: 10036
  • 博客等级: 上将
  • 技术积分: 4440
  • 用 户 组: 普通用户
  • 注册时间: 2006-04-06 13:57
文章分类

全部博文(408)

文章存档

2011年(1)

2010年(2)

2009年(1)

2008年(3)

2007年(7)

2006年(394)

我的朋友

分类: LINUX

2006-09-13 15:38:24

Nagios是一个不错的软件,工作需要学习了下。

nagios是一款功能强大,扩展性强的开源软件。

nagios下载载

nagios的官方网址

下载:nagios-2.0b4.tar.gz

#wget

下载:nagios-plugins-1.4.2.tar.gz

#wget

Nagios安装


1.将软件放至某个目录,比如/tmp

#cd /tmp


2解压缩编译


#tar zxvf nagios-2.0.b4.tar.gz

#cd nagios-2.0.b4.tar.gz

#./configure –prefix=/usr/local/nagio

#make all


3安装nagios


#make install

#make install-init

#make install-commandmode

#make install-config


4 安装nagios-plugin


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

#cd nagios-plugis-1.4.2

#./configure –prefix=/usr/local/nagios-plugins

#make all #make install


安装完成后/usr/local/nagios-plugins会产生一个libexec的目录,将该目录全部移动到/usr/local/nagios/目录下


#cp -r /usr/local/nagios-plugins/libexec /usr/local/nagios


至此nagios的基本安装就结束了。


第二部分 配置nagios

1.配置apache服务器

Suse9apache服务器用的是apache2配置文件的安排与apache1.3的差别还是比较大的。

我们直接编辑Suse默认的apache服务器的配置文件。

# vim /etc/apache2/default-server.conf

添加如下内容:


ScriptAlias /nagios/cgi-bin /usr/local/nagios/sbin

AllowOverride AuthConfig

Options +ExecCGI

Order allow,deny

Allow from all

Alias /nagios /usr/local/nagios/share

Options None

AllowOverride AuthConfig

Order allow,deny

Allow from all


2.配置nagios

/usr/local/nagios/etc/目录下,有很多以example后缀的文件,将所有的文件按如下形式修

# cp nagios.cfg.example nagios.cfg

...


生成一个dependencies.cfg的配置文件


#touch dependencies.cfg

检查配置是否成功


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

如果出现如下的提示:

Total Warnings: 0
Total Errors: 0


说明nagios的配置已经没有问题了。

在浏览器中输入:


第三部分:监控服务与设备

nagios的配置文件中hosts.cfg checkcommand.cfg services.cfg contacts.cfg 是比较重要的

我们以添加一台 IP 192.0.0.160B)的机器为例看看怎么监控一台服务器

我们的nagios 安装在192.0.0.175A)上,

#cd /usr/local/nagios/etc目录下添加hosts.cfg配置文件

#vim hosts.cfg

添加如下内容:


define host{

name my_host

notifications_enabled 1

event_handler_enabled 1

flap_detection_enabled 1

register 0

}

define host{

use my_host

host_name linux160

alias web1 of yeepay

address 192.0.0.160

max_check_attempts 10

contact_groups admin

notification_interval 120

notification_period 24x7

notification_options d,u,r

}


其中第一个define定义的实际是一个模板,第二个define使用了第一个模板,这样可以减少配置的工作量,具体的各项参数nagios有相关的文档可以查看比较简单。


添加checkcommands.cfg文件,这个文件的主要作用是定制各个检查和服务的命令。比如我们可 以定义一个check_host_cpu的命令

格式如下:


define command{

command_name check_host_cpu

commnad_line $USER1$/check_cpu -w 20% -c 30%

}


其中check_cpu/usr/local/nagios/libexec/目录下的一个插件,nagios使用这些插件实现各种服务的监控

Nagios的各种插件的使用方法如下,进入/usr/local/nagios/libexec/目录下


./check_cpu --help


其它的插件也是这样查看使用方法的。


Services.cfg文件的作用是地址要检查的服务项目,我们定义了主机,定义了检查的命令,那么我们还需要一个文件把这两个文件结合起来,service.cfg的作用就是在这里了。根据前面的两个定义我们可以定义这样一个服务。

define service{

host_name linux160

service_description 160disks

is_volatile 0

check_period 24x7

max_check_attempts 3

normal_check_interval 5

retry_check_interval 1

contact_groups admin

notification_interval 120

notification_period 24x7

notification_options w,u,c,r

check_command check_host_cpu

}

在上面的配置中我们使用了我们定义的主机,定义的check_command,还有一个非常重要的contact_groups我们没有定义。

Contacts.cfg的作用是定义通知对象,当系统或者服务出现问题的时候,我们可以定义一定的告警信息,并将这些信息发送给特定的人员。Constacts.cfg的作用就是定义这些人员的联系方式。

我们可以向下面这样定义。

define contact{

contact_name hwy

alias hwyadmin

host_notification_period 24x7

service_notification_period 24x7

host_notification_options d,r

service_notification_options w,r

service_notification_commands notify-by-email

host_notification_commands host-notify-by-email

email weiyi.huang@yeepay.com

}

Contactgroups.cfg的作用其实是contacts.cfg的集合,是为了方便定义通知对象的分组管理。

可以这样定义

define contactgroup{

contactgroup_name admin

alias yeepayadmin

members hwy

}

这样在services.cfg里的contact_groups的参数就可以使用admin这个组了,一旦出现问题,告警信件就会发送到admin组的hwy的信箱中。

Nagios的使用

nagios启动

/etc/init/nagios {start|stop|restart}

Nagios的权限设置

chwon -R nagios /usr/local/nagios

chgrp -R nagios /usr/local/nagios


当然你的当前系统里面必须有nagios用户和组,因为默认情况下nagiosnagios用户运行。

当你在nagios中添加了自己的配置文件的时候,比如添加了hosts.cfg文件,那么相应的nagios.cfg文件中就应该将这个配置文件前面的注释取消,以便使自己的配置生效。

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