nagios 3.X 简单部署及应用

简介:
################################
# 欢迎与我交流                 #
# 作者:守住每一天             #
# 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

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++
[url]http://sourceforge.net/projects/nscplus[/url]
双击安装再启动。
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
Installation does require a server reboot. For detailed information, consult

也就是有5点需要注意的。
石头大哥(
[url]http://www.itnms.net/discuz/[/url] )的翻译如下:
 简单说一下,大概的内容,不是严格翻译。
     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打开,可以发现更多有用的信息。

本文转自守住每一天51CTO博客,原文链接:http://blog.51cto.com/liuyu/80066,如需转载请自行联系原作者
相关文章
|
Web App开发 开发工具 机器学习/深度学习
|
Web App开发 开发工具 机器学习/深度学习
|
Linux Apache 数据安全/隐私保护
|
关系型数据库 MySQL 数据库