My favorites | Sign in
Project Home Downloads Wiki Issues Source
Search
for
Nagios_on_RHEL5  
在 RHEL 5 上部署 Nagios 监控软件
Nagios, RHEL, Solution
Updated Feb 4, 2010 by michaelb...@gmail.com

Contact me

  • 张煌彬:
    • michaelbibby
      <at>
      gmail
      <dot>
      com

Introduce Nagios

Installation

分别从以下地址下载适合 i386/x86_64 的 Nagios 的 RPM 包:

http://mirrors.cat.pdx.edu/dag/redhat/el5/en/x86_64/dag/RPMS/
http://mirrors.cat.pdx.edu/dag/redhat/el5/en/i386/dag/RPMS/

主要有以下几个包:

  • nagios
  • nagios-plugins
  • fping

下载完成后使用 rpm 命令安装即可,需要的依赖包在 RHEL 的 ISO 和上面的链接地址内可以找到。

Configuration

Basic Configuration

Nagios 的主要配置文件都放在 /etc/nagios/ 目录下,主要有以下几个配置文件:

  • /etc/nagios/cgi.cfg
  • /etc/nagios/localhost.cfg
  • /etc/nagios/nagios.cfg

nagios.cfg 不需要配置,先修改 cgi.cfg:

use_authentication=1
authorized_for_all_host_commands=nagiosadmin
authorized_for_all_hosts=nagiosadmin
authorized_for_all_service_commands=nagiosadmin
authorized_for_all_services=nagiosadmin
authorized_for_system_commands=nagiosadmin
authorized_for_system_information=nagiosadmin

改了之后 nagiosadmin 用户才可以登录到 web 界面进行操作。

使用 htpasswd 为 nagiosadmin 生成密码文件:

# htpasswd -c /etc/nagios/htpasswd.users nagiosadmin

生成后可以重启 Apache 和 Nagios 服务:

# /etc/init.d/httpd restart
# /etc/init.d/nagios restart

Nagios 的日志默认存放在:

/var/log/nagios/nagios.log

如果在启动 Nagios 时出现问题,可以在日志文件里找信息进行排错。 如果因为配置文件语法错误而导致无法启动 Nagios,这些错误信息并不会被记录到日志文件中, 但可以通过以下命令查看具体的错误:

# nagios -v /etc/nagios/nagios.cfg

添加联系人

在 /etc/nagios/nagios.cfg 中将这两行的注释给去掉:

#
# Part of file: /etc/nagios/nagios.cfg
#

cfg_file=/etc/nagios/contactgroups.cfg
cfg_file=/etc/nagios/contacts.cfg

为了便于区别,我们在 /etc/nagios/contacts.cfg 中只加入单独的个人, 而 /etc/nagios/contactgroups.cfg 则将这些个人归位不同的组。

#
# Part of file: /etc/nagios/contacts.cfg
#

define contact{
    contact_name                    michaelz
    alias                           Michael Zhang
    service_notification_commands   notify-by-email
    service_notification_period     24x7
    service_notification_options    w,u,c,r
    host_notification_commands      notify-by-email
    host_notification_period        24x7
    host_notification_options       d,u,r
    email                           michaelbibby@gmail.com
}

这里的 notification_options 的几个值的含义是:

  • w: Warn
  • c: Critical
  • d: Down
  • u: Unreachable
  • r: Recovered/Restart

#
# Part of file: /etc/nagios/contactgroups.cfg
#

define contactgroup{
    contactgroup_name       Linux_Server
    alias                   Linux_Server
    members                 michaelz
}

添加用于监控的命令

在 /etc/nagios/localhost.cfg 中增加以下内容:

添加主机

我们将服务器添加到新建的文件中以便于管理。

将 /etc/nagios/nagios.cfg 中的这几行去掉注释:

cfg_file=/etc/nagios/hostgroups.cfg
cfg_file=/etc/nagios/hosts.cfg

定义一个主机:

#
# Part of file: /etc/nagios/hosts.cfg
#

define host{
    use                     linux-server
    host_name               IT-MichaelZh
    alias                   IT-MichaelZh
    address                 192.168.122.1
    check_command           check_ping!100.0,20%!500.0,60%
    notifications_enabled   1
    event_handler_enabled   1
    notification_period     24x7
    notification_options    d,u,r
}

将这些主机分类,归为不同的组:

#
# Part of file: /etc/nagios/hostgroups.cfg
#

define hostgroup{
    hostgroup_name  Linux_Server
    alias           Linux Servers
    members         IT-MichaelZh,linuxsrv01
}

为主机添加监控的服务

将 /etc/nagios/nagios.cfg 中的这几行去掉注释:

cfg_file=/etc/nagios/services.cfg

在 /etc/nagios/services.cfg 中添加要监控的服务:

define service{
    use                     local-service
    host_name               IT-MichaelZh
    service_description     Ping
    check_command           check_ping!100.0,20%!500.0,60%
}

这里的 check_command 是模板里的,直接用就可以了。

Resource Link

Nagios 中文化


Sign in to add a comment
Powered by Google Project Hosting