分享

Red Hat Enterprise Linux 5.5 下安装配置 Nagios

 用勿龍潛 2012-04-13

Red Hat Enterprise Linux 5.5 下安装配置 Nagios

Nagios是一款多功能的开源网络监控工具, 由于它是以插件程序为导向,因此可以用来监控网络中的各种操作系统和设备。而如果没有可用的插件,它也会自动退回到SNMP(简单网络管理协议)标准,这也使Nagios得使用范围大大增加。在基础配置下,你可以创建一台Nagios主机来对同一网络中的各个节点进行监控。

Nagios工具对服务器的要求不是很高。如果你想监控100个以内的节点,几乎任何服务器都可以满足其需求。而如果你想用它来监控成千上万个节点,对服务器的要求就略高一些。要求服务器拥有多个CPU核,2GB的RAM以及大约40GB以上的硬盘空间。

 

1. Nagios的安装:

启用Nagios需要以下几个模块:

      Apache2

Php5

GCC编译器与开发库

GD库与开发库

本例中会按照以下规则进行安装:

       Nagios和插件将安装到/usr/local/nagios

       Nagios将被配置为监控本地系统的几个主要服务(http,ping等)

       Nagios的Web接口是URL是http://localhost/nagios/

安装apach2,php5(如果已经装了apahce可跳过此步):安装可参考Red Hat Enterprise Linux 5.5 下安装最新Apache2.2.16+PHP5.3.3+GD2

 

一:配置服务器端:
1.添加用户:
#useradd nagios
#usermod -s /sbin/nologin nagios
#groupadd nagcmd
#usermod -G nagcmd nagios
#usermod -G nagcmd apache

2.安装nagios-3.1.0
tar xzvf nagios-3.2.2.tar.gz
cd nagios-3.2.2
./configure --prefix=/usr/local/nagios --with-command-group=nagcmd --with-httpd-conf=/usr/local/apache/conf(设置apache的conf目录) --with-gd-lib=/usr/local/gd2/lib(设置gd的lib目录) --with-gd-inc=/usr/local/gd2/include(设置gd的include目录)

P.S. 这里是假设APACHE安装在/usr/local/apache;GD库安装在/usr/local/gd2的情况下.如果GD为yum自动安装可改为 --with-gd-lib=/usr/lib --with-gd-inc=/usr/include 如果提示找不到GD就 yum install gd; yum install gd-devel;

 

make all
make install
make install-init
make install-config
make install-commandmode
make install-webconf (可以自动设置httpd.conf)

3.安装nagios-plugins-1.4.13:
tar xzvf nagios-plugins-1.4.13.tar.gz
cd nagios-plugins-1.4.13
./configure --with-nagios-user=nagios --with-nagios-group=nagios --enable-redhat-pthread-workaround --prefix=/usr/local/nagios
make
make install

4.cat /usr/local/apache/conf/nagios.conf >> /usr/local/apache/conf/httpd.conf(把nagios的配置接到httpd.conf文件后面)

5. 配置Nagios管理员接受告警信息的邮箱,写入管理员邮箱
      # vi /usr/local/nagios/etc/objects/contacts.cfg
      email    admin@admin.com   ; 
      ——校验Nagios配置文件,验证配置是否有误
      #/usr/local/nagios/bin/nagios -v

           ——启动Nagios,配置在系统启动时运行Nagios
           #chkconfig --add nagios
           #chkconfig nagios on
           #chkconfig httpd on

           ——运行Nagios
           #service nagios start

6.添加用户:

/usr/local/apache/bin/htpasswd -c /usr/local/nagios/etc/htpasswd.users nagiosadmin

输入密码

7.service httpd restart                      //启动apache服务器

http://localhost/nagios 登陆到Web界面,输入用户名:nagiosadmin ,密码:”设置的密码 “就可以看到nagios的界面了。

8.改check_external_commands=0为check_external_commands=1 这行的作用是允许执行在web界面下重启nagios、停止主机/服务检查等操作。把command_check_interval的值从默认的1改成command_check_interval=10s(根据自己的情况定这个命令检查时间间隔,不要太长也不要太短)。

第二个要修改的配置文件是cgi.cfg,它的作用是控制相关cgi脚本,先确保use_authentication=1。曾看过不少的文章,都是建议把use_authentication的值设置成”0”来取消验证,这是一个十分糟糕的想法。default_user_name=xxx

如果需要创建多用户:

/usr/local/apache/bin/htpasswd /usr/local/nagios/etc/htpasswd xxx

修改 etc/cgi.cfg

1
2
3
4
5
6
7
8
9
10
11
authorized_for_system_information=nagiosadmin,xxx
  
authorized_for_configuration_information=nagiosadmin,xxx
  
authorized_for_system_commands=xxx //多个用户之间用逗号隔开
  
authorized_for_all_services=nagiosadmin,xxx
  
authorized_for_all_hosts=nagiosadmin,xxx
  
authorized_for_all_service_commands=nagiosadmin,xxx

 然后etc/objects/contacts.cfg:修改监视管理员的联系方式,以及通知方式,下面的添加模板.

define contact {
        contact_name         xxx
        alias                system administrator
        service_notification_period    24x7
        host_notification_period       24x7
        service_notification_options   w,u,c,r
        host_notification_options       d,u,r
        service_notification_commands  service-notify-by-email
        host_notification_commands     host-notify-by-email(邮件)
        email                         xxx.hotmail.com
        }<BR>

 

服务通知选项(service_notification_options)与主机通知选项(host_notification_options)的几个选项在这里说明一下:w-warning,u-unknown,c-critical,r-recovery;d-down,u-unreachable,注意一下,主机报警和服务报警有些差异。

nagios也为我们准备了一个配置全局模板的地方:

define contact {
     
     use  generic-contact
     
}

 这表示这里是该用户应用了etc/objects/templates.cfg 里面的,修改此处可以更改全局的联系方式:

define contact{
        name                            generic-contact        ; The name of this contact template
        service_notification_period     24x7                        ; service notifications can be sent anytime
        host_notification_period        24x7                         ; host notifications can be sent anytime
        service_notification_options    w,u,c,r,f,s                 ; send notifications for all service states, flapping events, and scheduled downtime events
        host_notification_options       d,u,r,f,s           ; send notifications for all host states, flapping events, and scheduled downtime events
        service_notification_commands   notify-service-by-email     ; send service notifications via email
        host_notification_commands      notify-host-by-email        ; send host notifications via email
        register                        0                      ; DONT REGISTER THIS DEFINITION - ITS NOT A REAL CONTACT, JUST A TEMPLATE!
}

 

同时contacts.cfg也为我们准备了contactgroup的修改可以方便我们对管理员分类

接下来是最关键的host(监控机器)相关的配置.

Nagios为我们准备了一个sample:etc/objects/localhost.cfg

下面是我自己监控局域网内的某台机器的实例,IP:192.168.2.217

vi /usr/local/nagios/etc/objects/1921682217.cfg

define host{
       use                   linux-server
       host_name             1921682217
       alias                 1921682217
       address               192.168.2.217
}
define service{
    use                   generic-service         ; Name of service template to use
    host_name            1921682217
    service_description     HTTP
    check_command           check_http
    notifications_enabled    0
}

 

其他配置文件功能:
etc/objects/commands.cfg:这个文件的主要功能是用来发送报警短信和报警邮件.
etc/objects/timeperiods.cfg:修改监控时间,默认是7*24小时监控.

8.echo "cfg_file=/usr/local/nagios/etc/objects/1921682217.cfg" >> /usr/local/nagios/etc/nagios.cfg (将配置文件include到主配置文件里)

9.启动相关服务:
/usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg //检查配置文件是否正确
/usr/local/nagios/bin/nagios -d /usr/local/nagios/etc/nagios.cfg //手动启动nagios
/usr/local/nagios/bin/nagios -s /usr/local/nagios/etc/nagios.cfg //评估启动时间
/etc/init.d/nagios start //启动
/etc/init.d/nagios reload //重启

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多