免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 2624 | 回复: 3

nagios 3.X 简单部署及应用。非常简单的文档 [复制链接]

论坛徽章:
0
发表于 2008-06-03 13:19 |显示全部楼层
################################
# 欢迎与我交流                 #
# 作者:守住每一天             #
# 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 11243 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

[ 本帖最后由 守住每一天 于 2008-6-3 13:22 编辑 ]

论坛徽章:
0
发表于 2008-06-03 14:22 |显示全部楼层
监控windows的话可以用snmp,那个nrpe_nt在windows server 2003打过sp2补丁以后就不好使了

论坛徽章:
0
发表于 2008-06-03 14:22 |显示全部楼层
貌似有点复杂啊,觉得cacti比较简单

论坛徽章:
0
发表于 2008-06-03 20:21 |显示全部楼层
哦,2003 我还没有遇到你所说的情况。
谢谢指点哈~~

监控方式不一样嘛。NAGIOS报警还是不错的。
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP