设为首页收藏本站

LinuxTone | 运维专家网论坛 - 最棒的Linux运维与开源架构技术交流社区!

 找回密码
 注册

用新浪微博连接

一步搞定

QQ登录

只需一步,快速开始

查看: 9711|回复: 15

nagios 3.X 简单部署及应用   [复制链接]

LT管理团队

守住每一天

Rank: 9Rank: 9Rank: 9

签到
195
注册时间
2008-5-30
最后登录
2012-5-23
在线时间
641 小时
阅读权限
200
积分
16234
帖子
1273
主题
176
精华
11
UID
31
发表于 2008-6-3 13:19:55 |显示全部楼层
################################
# 欢迎与我交流                 #
# 作者:守住每一天             #
# QQ: 48431359                #
# BLOG: liuyu.blog.51cto.com   #
################################
本文主要参考官方文档。
1、准备工作
所需要的软件包:
gcc
gd
glibc
httpd
yum install cc
yum install glibc glibc-common
yum install gd gd-devel
httpd 可以参照其它文档
设置 nagios用户  用户组
/usr/sbin/useradd nagios
为了安全性设置为nologin
/usr/sbin/usermod -s /sbin/nologin nagios
/usr/sbin/groupadd nagcmd
/usr/sbin/usermod -G nagcmd nagios
/usr/sbin/usermod -G nagcmd apache
2、下载软件:
wget http://osdn.dl.sourceforge.net/sourceforge/nagios/nagios-3.0.2.tar.gz
wget http://osdn.dl.sourceforge.net/sourceforge/nagiosplug/nagios-plugins-1.4.11.tar.gz

3、tar xzf nagios-3.0.2.tar.gz
cd nagios-3.0.2
./configure --with-command-group=nagcmd
make all
make install
make install-init
make install-config
make install-commandmode
make install-webconf  ---可以自动配置httpd.conf

4、vi /usr/local/nagios/etc/objects/contacts.cfg
改变E-MAIL 地址

5、APACHE 设置:
htpasswd -c /usr/local/nagios/etc/htpasswd.users nagiosadmin
service httpd restart
就可以看到nagios界面了。
6、安装插件:
tar xzf nagios-plugins-1.4.11.tar.gz
cd nagios-plugins-1.4.11
./configure --with-nagios-user=nagios --with-nagios-group=nagios
make
make install
7、设置nagios启动
chkconfig --add nagios
chkconfig nagios on
检查配置文件是否正确 :/usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg
service nagios start
注意:如果你开启了selinux 需要配置如下二步:
chcon -R -t httpd_sys_content_t /usr/local/nagios/sbin/
chcon -R -t httpd_sys_content_t /usr/local/nagios/share/

8、3.X与2.X的配置文件区别
安装方法没有太多不同的地方。主要是配置文件的变化,3.X部署比较方便,特别是多服务器时。
配置文件默认都在/usr/local/nagios/etc/objects/
主控制配置文件在/usr/local/nagios/etc/
这次不需要手动创建那么多的文件。
也没有hosts groups 等配置文件。
这些内容直接写在被监控机的配置文件里面。写这多也不好理解。直接看例子吧。

9、监控其它机子
添加被监控机A(linux)
在/usr/local/nagios/etc/objects/ 目录下新建文件:a.cfg
官方说明:在Nagios里每个要监控的服务都必须给出一个绑定在刚才定义出的主机上的一个服务对象。可以把服务对象放在任何一个由
cfg_file域指向的对象配置文件里或是放在cfg_dir域所指向的目录下。
也就是说只需要在nagios.cfg 的配置文件里指定cfg_dir 就可以实现监控机器的目的。
把A.cfg添加到nagios主机:
echo "cfg_file=/usr/local/nagios/etc/objects/A.cfg" >> /usr/local/nagios/etc/nagios.cfg
如果要再添加B机器方法炮制就可以了
修改文件:
########################################################################
#
# 2008.05.05 add by 守住每一天
# blog: liuyu.blog.51cto.com
# NRPE COMMAND
#
################################################################
define host{
use                   generic-server                                                               
        host_name             A
        alias                 A
        address               A 的IP
        }
define service{
use   generic-service  
host_name  A
service_description HTTP
check_command  check_http
}
依次添加其它服务。

方法是不是比2.X 要简单多了?
直接写好一个,再COPY HOHO 很舒服的。
10、监控linux主机信息
这里需要nrpe 插件的支持。
与2.X一样。
tar -zxvf nrpe-2.8.1.tar.gz
cd nrpe-2.8.1
./configure
make all
make install-daemon
make install-daemon-config
10.1 修改配置文件,设置允许连接的IP
vi /usr/local/nagios/etc/nrpe.conf
allowed_hosts=127.0.0.1,A的IP(最好使用内网IP)
10.2 测试NAGIOS主机与被监控机的连接
/usr/local/nagios/libexec/check_nrpe -H A的IP
10.3 启动nrpe
/usr/local/nagios/bin/nrpe -c /usr/local/nagios/etc/nrpe.cfg -d
查看相应的端口:netstat -net |grep 5666
防火墙开启5666 允许局域网IP或固定IP连接
10.4 commands.cfg 添加nrpe的定义
########################################################################
#
# 2008.05.05 add by 守住每一天
# blog: liuyu.blog.51cto.com
# NRPE COMMAND
#
########################################################################
# 'check_nrpe ' command definition
define command{
        command_name check_nrpe
        command_line $USER1$/check_nrpe -H $HOSTADDRESS$ -c $ARG1$
        }
10.5 监控方法
########################################################################
#
# 2008.05.05 add by 守住每一天
# blog: liuyu.blog.51cto.com
# NRPE COMMAND
#
################################################################
define service{
use   generic-service  
host_name  A
service_description load
check_command  check_nrpe!check_load
}
就是多加一个check_nrpe

11、监控WIN
安装 NSClient++
http://sourceforge.net/projects/nscplus
双击安装再启动。
allowed_hosts允许连接的IP
防火墙开端口12489,你也可以换成别的
监控:在nagios.cfg里cfg_dir去掉windods.cfg的注释。
更改IP 就可以进行监控了。
里面的内容跟其它的差不多,可以自行添加。

总结:nagios 总体安装比较简单。特别是3.X 更加人性化。部署起来也没有2.X麻烦,只要安装过2.X的再安装3.X更加速度~
默认的邮箱也是自带的,不需要再配置sendmail。
PNP的安装还没有完成呢。等完成了我再写。
大伙可能会遇到一个很麻烦的问题。错误如下:
CHECK_NRPE: Error - Could not complete SSL handshake
看官网FAQ 就知道。有如下一段:
Title: Debugging "CHECK_NRPE: Error - Could not complete SSL handshake" errors
FAQ ID: F0191
Submitted By: Greg Haygood, Ethan Galstad and Others
Last Updated: 11/03/2004
Description: When attempting to use the check_nrpe plugin, the following error message is printed:
CHECK_NRPE: Error - Could not complete SSL handshake
Solution: This error message could be due to several problems:
    * Different versions. Make sure you are using the same version of the check_nrpe plugin and the NRPE daemon. Newer
versions of NRPE are usually not backward compatible with older versions.
    * SSL is disabled. Make sure both the NRPE daemon and the check_nrpe plugin were compiled with SSL support and that
neither are being run without SSL support (using command line switches).
    * Incorrect file permissions. Make sure the NRPE config file (nrpe.cfg) is readable by the user (i.e. nagios) that
executes the NRPE binary from inetd/xinetd.
    * Pseudo-random device files are not readable. Greg Haygood noted the following... "After wringing my hair out and
digging around with truss, I figured out the problem on my Solaris 8 boxen. The files /devices/pseudo/random* (linked through
/dev/*random, and provided by Sun patch 112438) were not readable by the nagios user I use to launch NRPE. Making the
character devices world-readable solved it."
    * Unallowed address. If you're running the NRPE daemon under xinetd, make sure that you have a line in the xinetd config
file that say "only_from = xxx.xxx.xxx.xxx", where xxx.xxx.xxx.xxx is the IP address that you're connected to the NRPE daemon
from.

Dave van Nierop added that "Fortunately, for HPUX 11.i (11.11) and later Nagios users, HP now supports /dev/random and
/dev/urandom via a kernel loadable module. Prior to running the NRPE 2.0 configure script, you will need to download this
program from http://www.software.hp.com/cgi-bin/swdepot_parser.cgi/cgi/displayProductInfo.pl?productNumber=KRNG11I.
Installation does require a server reboot. For detailed information, consult

也就是有5点需要注意的。
石头大哥(http://www.itnms.net/discuz/)的翻译如下:
简单说一下,大概的内容,不是严格翻译。
     1.  确认check_nrpe 和 nrpe daemon的版本一定要一致。
     2.  确认 check_nrpe和nrpe deamon端同时启用或者禁用ssl支持。
     3.  确认nrep.cfg可以被nrpe(或者nagios,反正是执行nrep或者xinetd/inetd程序的)用户正常读取。
     4.  有关伪随机设备的问题。这个只会在solaris 8上出现,需要一个补丁Sun patch 112438。
     5.  确定nagios主机在xinetd的 only_from中,如果没有使用xinetd,则要确认nrpe.cfg中的配置。
另外,赠送l两个,
1. 检查一下你的Windows或者Linux自带的防火墙,是否把端口给filter掉了。
2. 把nrpe的的log打开,可以发现更多有用的信息。

nagios 3.X的中文文档:http://www.itnms.net/docs/nagios/cn/build/html/index.html
已有 1 人评分积分 收起 理由
linuxtone + 10 原创内容

总评分: 积分 + 10   查看全部评分

<-sina_sign,1054764633,7->

LT管理团队

社区首席勤杂工

Rank: 9Rank: 9Rank: 9

注册时间
2008-5-19
最后登录
2012-5-3
在线时间
1762 小时
阅读权限
200
积分
14979
帖子
2524
主题
1200
精华
25
UID
1

LT总司令

发表于 2008-6-3 13:50:11 |显示全部楼层
支持原创,不过只是一个基本的安装,希望作者能够写更深入的配置方法。
如:nagios各类配置文件的介绍,各类服务的监控配置方法,结合短信告警,插件安装。。。。等等,其待作者更精彩的文章!
感谢大家对linuxtone的支持!

使用道具 举报

Rank: 1

注册时间
2008-6-18
最后登录
2008-9-12
在线时间
11 小时
阅读权限
10
积分
6
帖子
11
主题
1
精华
0
UID
88
发表于 2008-6-18 16:09:52 |显示全部楼层
路过,顶顶顶顶顶顶顶!

使用道具 举报

Rank: 1

注册时间
2009-6-9
最后登录
2012-3-18
在线时间
1 小时
阅读权限
10
积分
1
帖子
1
主题
0
精华
0
UID
3495
发表于 2009-6-11 20:18:53 |显示全部楼层
大哥,第九步里面是不是应该这样的
9、监控其它机子
添加被监控机A(linux)
在/usr/local/nagios/etc/objects/ 目录下新建文件:[color=RedA.cfg]。把小弟看得有点晕,呵呵,

使用道具 举报

Rank: 1

注册时间
2009-2-24
最后登录
2010-8-12
在线时间
16 小时
阅读权限
10
积分
7
帖子
9
主题
1
精华
0
UID
1578
发表于 2009-7-6 16:03:59 |显示全部楼层
从9步开始我也晕了

使用道具 举报

Rank: 8Rank: 8

注册时间
2009-3-31
最后登录
2012-5-23
在线时间
321 小时
阅读权限
90
积分
19540
帖子
337
主题
48
精华
1
UID
2237
发表于 2009-10-29 11:45:19 |显示全部楼层
支持顶下!!

使用道具 举报

Rank: 4

注册时间
2009-11-4
最后登录
2012-5-6
在线时间
50 小时
阅读权限
50
积分
918
帖子
16
主题
1
精华
0
UID
6382
发表于 2009-12-25 11:33:27 |显示全部楼层
我到了安装这一步make install-webconf出现如下错误,请教中
附件: 你需要登录才可以下载或查看附件。没有帐号?注册

使用道具 举报

Rank: 2

注册时间
2010-8-5
最后登录
2010-10-8
在线时间
6 小时
阅读权限
20
积分
72
帖子
21
主题
3
精华
0
UID
10020
发表于 2010-8-10 08:35:58 |显示全部楼层
define host{
use                   generic-server   

提示出错:
Error: Template 'generic-server' specified in host definition could not be not found (config file '/usr/local/nagios/etc/objects/rserver1.cfg', starting on line 1)
vi rserver1
define host{
        use             generic-server  #貌似genric-server不能通过编译,求解
        host_name       rserver1
        alias           rserver1

使用道具 举报

高级会员

吃饱找事干!

Rank: 4

注册时间
2010-7-13
最后登录
2011-9-29
在线时间
44 小时
阅读权限
50
积分
930
帖子
74
主题
3
精华
0
UID
9790
发表于 2010-11-2 13:55:55 |显示全部楼层
呵呵,很详细,看了深受启发

使用道具 举报

Rank: 8Rank: 8

注册时间
2011-2-11
最后登录
2012-4-18
在线时间
81 小时
阅读权限
90
积分
3431
帖子
18
主题
1
精华
0
UID
11970
发表于 2011-2-11 17:28:26 |显示全部楼层
很好,很强大,晕了

使用道具 举报

Rank: 3Rank: 3

注册时间
2011-3-7
最后登录
2012-3-13
在线时间
28 小时
阅读权限
30
积分
384
帖子
71
主题
3
精华
0
UID
12283
发表于 2011-3-15 12:06:28 |显示全部楼层
好像少了一步安装php的步骤

使用道具 举报

Rank: 4

注册时间
2008-11-12
最后登录
2012-5-10
在线时间
44 小时
阅读权限
50
积分
719
帖子
354
主题
0
精华
0
UID
528
发表于 2011-3-26 16:53:21 |显示全部楼层
支持。。。。。

使用道具 举报

Rank: 8Rank: 8

注册时间
2011-2-23
最后登录
2012-5-23
在线时间
49 小时
阅读权限
90
积分
7403
帖子
61
主题
6
精华
0
UID
12124
发表于 2011-4-8 00:08:22 |显示全部楼层
困难重重啊。

使用道具 举报

Rank: 2

注册时间
2011-4-12
最后登录
2011-11-26
在线时间
3 小时
阅读权限
20
积分
124
帖子
3
主题
0
精华
0
UID
12782
发表于 2011-4-12 19:50:44 |显示全部楼层
回复 game54chai 的帖子

generic-server  这个服务器的模板没有配置

使用道具 举报

Rank: 6Rank: 6

注册时间
2011-2-17
最后登录
2012-5-9
在线时间
66 小时
阅读权限
70
积分
1135
帖子
50
主题
8
精华
0
UID
12050
发表于 2011-5-23 12:33:31 |显示全部楼层
呵呵,很详细,看了深受启发

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

IT运维专家网感谢红之盟网络提供带宽支持

合作联系: QQ:67888954/MSN:cnseek@msn.com/mail:netseek@linuxtone.org

Archiver|手机版|感谢所有关心和支持过LinuxTone的朋友们 转载本站内容请注明原作者名及出处 ( 京ICP备08103151 )   |

GMT+8, 2012-5-23 10:32 , Processed in 0.142825 second(s), 13 queries , Memcache On.

Powered by Discuz! X2

© 2001-2011 Comsenz Inc.

回顶部