最新消息:

在 RHEL 5.5 下配置 Nagios 3.2.3

监控 admin 2766浏览 0评论

本周的工作是做 Nagios 监控系统的初期调研,看了大量的网上资料,我初步确定 Nagios 的功能确实很强大,相比之前我搭建的 Cacti 监控系统,Nagios 监控服务器的状态更强大,并且报警功能也很不错,但对像流量这样的持续数据的展现能力却比较弱,不像 Cacti 监控系统将服务器的点状态和线状态都清晰的展现出来。所以我的研究表明,公司同时使用这两种监控系统是有必要的,而且我从网上找到了一种将 Nagios 整合到 Cacti 监控系统中的方法,如果这个方法行得通的话,公司的监控系统就完美了!具体的实现方法我会在自己测试后以博文的形式发布到我的博客里,下面就请大家跟我一起开始 Nagios 的安装旅程吧!

  1. 建立安装所需的系统用户和组,其中创建的 nagcmd 组用于从 Web 接口执行外部命令,所以需要将 Apache 服务的执行用户加入到该组中去。
    [root@pubservicedb nagios]# groupadd -g 9000 nagios
    [root@pubservicedb nagios]# groupadd -g 9001 nagcmd
    [root@pubservicedb nagios]# useradd -u 9000 -g nagios -G nagcmd -s /sbin/nologin -c “Nagios Admin” nagios
    [root@pubservicedb nagios]# grep “^User” /usr/local/apache/conf/httpd.conf
    User daemon
    [root@pubservicedb nagios]# usermod -G nagcmd daemon
  2. 编译 Nagios 源程序包
    [root@pubservicedb nagios-3.2.3]# ./configure –with-command-group=nagcmd –with-httpd-conf=/usr/local/apache/conf/conf.d/ –with-gd-lib=/usr/local/lib/ –with-gd-inc=/usr/local/includechecking for a BSD-compatible install… /usr/bin/install -c
    … …
    checking for mail… /bin/mail
    We’ll use default routines (in xdata/xsddefault.*) for status data I/O…
    We’ll use default routines (in xdata/xcddefault.*) for comment data I/O…
    We’ll use default routines (in xdata/xrddefault.*) for retention data I/O…
    We’ll use template-based routines (in xdata/xodtemplate.*) for object data I/O…
    We’ll use default routines (in xdata/xpddefault.*) for performance data I/O…
    We’ll use default routines (in xdata/xdddefault.*) for scheduled downtime data I/O…
    checking ltdl.h usability… no
    … …
    config.status: creating include/cgiutils.h

    Creating sample config files in sample-config/ …

    *** Configuration summary for nagios 3.2.3 10-03-2010 ***:

    General Options:
    ————————-
    Nagios executable: nagios
    Nagios user/group: nagios,nagios
    Command user/group: nagios,nagcmd
    Embedded Perl: no
    Event Broker: yes
    Install ${prefix}: /usr/local/nagios
    Lock file: ${prefix}/var/nagios.lock
    Check result directory: ${prefix}/var/spool/checkresults
    Init directory: /etc/rc.d/init.d
    Apache conf.d directory: /etc/httpd/conf.d
    Mail program: /bin/mail
    Host OS: linux-gnu

    Web Interface Options:
    ————————
    HTML URL: http://localhost/nagios/
    CGI URL: http://localhost/nagios/cgi-bin/
    Traceroute (used by WAP): /bin/traceroute

    Review the options above for accuracy. If they look okay,
    type ‘make all’ to compile the main program and CGIs.

    [root@pubservicedb nagios-3.2.3]# make all
    [root@pubservicedb nagios-3.2.3]# make install

  3. 安装 Nagios 二进制程序、初始化脚本、配置文件示例并设置运行目录权限
    [root@pubservicedb nagios-3.2.3]# make install
    [root@pubservicedb nagios-3.2.3]# make install-init
    /usr/bin/install -c -m 755 -d -o root -g root /etc/rc.d/init.d
    /usr/bin/install -c -m 755 -o root -g root daemon-init /etc/rc.d/init.d/nagios*** Init script installed ***

    [root@pubservicedb nagios-3.2.3]# make install-config
    /usr/bin/install -c -m 775 -o nagios -g nagios -d /usr/local/nagios/etc
    /usr/bin/install -c -m 775 -o nagios -g nagios -d /usr/local/nagios/etc/objects
    /usr/bin/install -c -b -m 664 -o nagios -g nagios sample-config/nagios.cfg /usr/local/nagios/etc/nagios.cfg
    /usr/bin/install -c -b -m 664 -o nagios -g nagios sample-config/cgi.cfg /usr/local/nagios/etc/cgi.cfg
    /usr/bin/install -c -b -m 660 -o nagios -g nagios sample-config/resource.cfg /usr/local/nagios/etc/resource.cfg
    /usr/bin/install -c -b -m 664 -o nagios -g nagios sample-config/template-object/templates.cfg /usr/local/nagios/etc/objects/templates.cfg
    /usr/bin/install -c -b -m 664 -o nagios -g nagios sample-config/template-object/commands.cfg /usr/local/nagios/etc/objects/commands.cfg
    /usr/bin/install -c -b -m 664 -o nagios -g nagios sample-config/template-object/contacts.cfg /usr/local/nagios/etc/objects/contacts.cfg
    /usr/bin/install -c -b -m 664 -o nagios -g nagios sample-config/template-object/timeperiods.cfg /usr/local/nagios/etc/objects/timeperiods.cfg
    /usr/bin/install -c -b -m 664 -o nagios -g nagios sample-config/template-object/localhost.cfg /usr/local/nagios/etc/objects/localhost.cfg
    /usr/bin/install -c -b -m 664 -o nagios -g nagios sample-config/template-object/windows.cfg /usr/local/nagios/etc/objects/windows.cfg
    /usr/bin/install -c -b -m 664 -o nagios -g nagios sample-config/template-object/printer.cfg /usr/local/nagios/etc/objects/printer.cfg
    /usr/bin/install -c -b -m 664 -o nagios -g nagios sample-config/template-object/switch.cfg /usr/local/nagios/etc/objects/switch.cfg

    *** Config files installed ***

    Remember, these are *SAMPLE* config files. You’ll need to read
    the documentation for more information on how to actually define
    services, hosts, etc. to fit your particular needs.

    [root@pubservicedb nagios-3.2.3]# make install-commandmode
    /usr/bin/install -c -m 775 -o nagios -g nagcmd -d /usr/local/nagios/var/rw
    chmod g+s /usr/local/nagios/var/rw

    *** External command directory configured ***

    [root@pubservicedb nagios-3.2.3]#

  4. 客户化配置,将 contacts.cfg 配置文件中的 Email 信息修改为系统管理员的 Email 地址
    [root@pubservicedb nagios-plugins-1.4.15]# vi /usr/local/nagios/etc/objects/contacts.cfg
  5. 配置 Web 接口
    [root@pubservicedb nagios-3.2.3]# make install-webconf
    /usr/bin/install -c -m 644 sample-config/httpd.conf /usr/local/apache/conf/conf.d//nagios.conf*** Nagios/Apache conf file installed ***

    [root@pubservicedb nagios-3.2.3]# /usr/local/apache/bin/htpasswd -c /usr/local/nagios/etc/htpasswd.users nagiosadmin
    New password:
    Re-type new password:
    Adding password for user nagiosadmin

  6. 重启 httpd 服务
    [root@pubservicedb nagios-3.2.3]# /usr/local/apache/bin/apachectl -k restart
    httpd: Could not reliably determine the server’s fully qualified domain name, using 10.10.6.201 for ServerName
    [root@pubservicedb nagios-3.2.3]#
  7. 编译并安装 Nagios 插件源代码包
    [root@pubservicedb nagios]# tar -zxf nagios-plugins-1.4.15.tar.gz
    [root@pubservicedb nagios]# cd nagios-plugins-1.4.15
    [root@pubservicedb nagios-plugins-1.4.15]# ./configure –with-nagios-user=nagios –with-nagios-group=nagios
    [root@pubservicedb nagios-plugins-1.4.15]# make
    [root@pubservicedb nagios-plugins-1.4.15]# make install
  8. 配置 Nagios 服务
    [root@pubservicedb nagios-plugins-1.4.15]# chkconfig –add nagios
    [root@pubservicedb nagios-plugins-1.4.15]# chkconfig nagios on
  9. 验证 Nagios 示例配置文件
    [root@pubservicedb nagios-plugins-1.4.15]# /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfgNagios Core 3.2.3
    Copyright (c) 2009-2010 Nagios Core Development Team and Community Contributors
    Copyright (c) 1999-2009 Ethan Galstad
    Last Modified: 10-03-2010
    License: GPL

    Website: http://www.nagios.org
    Reading configuration data…
    Read main config file okay…
    Processing object config file ‘/usr/local/nagios/etc/objects/commands.cfg’…
    Processing object config file ‘/usr/local/nagios/etc/objects/contacts.cfg’…
    Processing object config file ‘/usr/local/nagios/etc/objects/timeperiods.cfg’…
    Processing object config file ‘/usr/local/nagios/etc/objects/templates.cfg’…
    Processing object config file ‘/usr/local/nagios/etc/objects/localhost.cfg’…
    Read object config files okay…

    Running pre-flight check on configuration data…

    Checking services…
    Checked 8 services.
    Checking hosts…
    Checked 1 hosts.
    Checking host groups…
    Checked 1 host groups.
    Checking service groups…
    Checked 0 service groups.
    Checking contacts…
    Checked 1 contacts.
    Checking contact groups…
    Checked 1 contact groups.
    Checking service escalations…
    Checked 0 service escalations.
    Checking service dependencies…
    Checked 0 service dependencies.
    Checking host escalations…
    Checked 0 host escalations.
    Checking host dependencies…
    Checked 0 host dependencies.
    Checking commands…
    Checked 24 commands.
    Checking time periods…
    Checked 5 time periods.
    Checking for circular paths between hosts…
    Checking for circular host and service dependencies…
    Checking global event handlers…
    Checking obsessive compulsive processor commands…
    Checking misc settings…

    Total Warnings: 0
    Total Errors: 0

    Things look okay – No serious problems were detected during the pre-flight check
    [root@pubservicedb nagios-plugins-1.4.15]#

  10. 启动 Nagios 服务
    [root@pubservicedb nagios-plugins-1.4.15]# service nagios start
    Starting nagios:This account is currently not available.
    done.
    [root@pubservicedb nagios-plugins-1.4.15]# service nagios status
    nagios (pid 20180) is running…
    [root@pubservicedb nagios-plugins-1.4.15]#
  11. 关于 SELinux 的相关设置
    如果你所用的 Linux 系统开启了 SElinux 设置,那么这会使你在尝试访问 Nagios 的 CGI 时导致一个“内部服务错误”消息。你可以更改 /etc/sysconfig/selinux 文件,设置为 disabled 然后重启系统,通过彻底关闭该功能来避免上述问题。
    当然,你也可以通过让 CGI 模块在 SELinux 模式下制定强制目标模式来解决该问题,方法如下:# chcon -R -t httpd_sys_content_t /usr/local/nagios/sbin/
    # chcon -R -t httpd_sys_content_t /usr/local/nagios/share/
  12. 登录 Web 接口
    在浏览器中浏览 http://host_ip/nagios/ 根据提示输入之前设置的用户名和口令即可访问 Nagios Web 界面。
  13. 大功告成!

总的来说,我安装 Nagios 的过程没有安装 Cacti 时那么曲折,但这并不意味着 Nagios 的安装步骤简单容易,而是因为很多东西,比如 libpng, libjpeg, libgd, Apache 等组件,我之前安装 Cacti 时都安装过了,如果有朋友在安装 Nagios 的过程中遇到了上述组件的安装困难的话,请参考这篇 文章 来解决。安装好 Nagios 后,我接下来的工作就是研究 Nagios 的基本配置以及相关监控插件的使用,我会在我的博客上及时更新我的学习过程的。请感兴趣的朋友常来我的博客看看!(#^_^#)

 

转载请注明:爱开源 » 在 RHEL 5.5 下配置 Nagios 3.2.3

您必须 登录 才能发表评论!