一、监控服务器安装
1.关闭SELINUX
# vi /etc/selinux/config
SELINUX=disabled
2. 使用yum 安装依赖包
# yum install -y gcc glibc glibc-common gd gd-devel xinetd openssl-devel
# yum install -y libxml2-devel
3.创建nagios用户和用户组
# useradd -s /sbin/nologin nagios
# mkdir /usr/local/nagios
# chown -R nagios.nagios /usr/local/nagios
4. 编译安装Nagios
# wget http://sourceforge.net/projects/nagios/files/nagios-3.x/nagios-3.5.1/nagios-3.5.1.tar.gz
# tar zxvf nagios-3.5.1.tar.gz
# cd nagios
# ./configure --prefix=/usr/local/nagios
# make all
# make install
# make install-init
# make install-commandmode
# make install-config
# chkconfig --add nagios
# chkconfig --level 35 nagios on
# chkconfig --list nagios


5. 安装Nagios 插件

# wget http://prdownloads.sourceforge.net/sourceforge/nagiosplug/nagios-plugins-1.4.16.tar.gz

# tar zxvf nagios-plugins-1.4.16.tar.gz

# cd nagios-plugins-1.4.16

# ./configure --prefix=/usr/local/nagios

# make && make install


6. 安装与配置Apache和Php

Apache 和Php 不是安装nagios 所必须的,但是nagios提供了web监控界面,通过web监控界面可以清晰的看到被监控主机、资源的运行状态,因此,安装一个web服务是很必要的。
需要注意的是,nagios在nagios3.1.x版本以后,配置web监控界面时需要php的支持。这里我们下载的nagios版本为nagios-3.5.1,因此在编译安装完成apache后,还需要编译php模块,这里选取的php版本为php5.5.3。

a. 安装Apache

# wget http://archive.apache.org/dist/httpd/httpd-2.2.25.tar.gz
# tar zxvf httpd-2.2.25.tar.gz
# cd httpd-2.2.25
# ./configure --prefix=/usr/local/apache2
# make && make install

b. 安装Php

# wget http://cn2.php.net/distributions/php-5.5.3.tar.gz
# tar zxvf php-5.5.3.tar.gz
# cd php-5.5.3
# ./configure --prefix=/usr/local/php --with-apxs2=/usr/local/apache2/bin/apxs
# make && make install

c. 配置apache
找到apache 的配置文件/usr/local/apache2/conf/httpd.conf
# vim /usr/local/apache2/conf/httpd.conf


找到:

User daemon
Group daemon

修改为

User nagios
Group nagios

然后找到


  DirectoryIndex index.html


修改为


  DirectoryIndex index.html index.php


接着增加如下内容:

AddType application/x-httpd-php .php

为了安全起见,一般情况下要让nagios 的web 监控页面必须经过授权才能访问,这需要增加验证配置,即在httpd.conf 文件最后添加如下信息

#setting for nagios
ScriptAlias /nagios/cgi-bin "/usr/local/nagios/sbin"

    AuthType Basic
    Options ExecCGI
    AllowOverride None
    Order allow,deny
    Allow from all
    AuthName "Nagios Access"
    AuthUserFile /usr/local/nagios/etc/htpasswd            
    Require valid-user

Alias /nagios "/usr/local/nagios/share"

    AuthType Basic
    Options None
    AllowOverride None
    Order allow,deny
    Allow from all
    AuthName "nagios Access"
    AuthUserFile /usr/local/nagios/etc/htpasswd
    Require valid-user



d. 创建apache目录验证文件

在上面的配置中,指定了目录验证文件htpasswd,下面要创建这个文件:

# /usr/local/apache2/bin/htpasswd -c /usr/local/nagios/etc/htpasswd admin
设置admin的密码

这样就在/usr/local/nagios/etc 目录下创建了一个htpasswd 验证文件,当通过http://192.168.1.108/nagios/ 访问时就需要输入用户名和密码了。

e. 查看认证文件的内容

# cat /usr/local/nagios/etc/htpasswd

启动服务
/usr/local/apache2/bin/apachectl start
检查
/usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg
/usr/local/nagios/bin/nagios -d /usr/local/nagios/etc/nagios.cfg

h.
如果出现
It appears as though you do not have permission to view information for any of the hosts you requested...
编辑cgi.cfg文件
此文件用来控制相关cgi脚本,如果想在nagios的web监控界面执行cgi脚本,例如重启nagios进程、关闭nagios通知、停止nagios主机检测等,这时就需要配置cgi.cfg文件了。
由于nagios的web监控界面验证用户为admin所以只需在cgi.cfg文件中添加此用户的执行权限就可以了,需要修改的配置信息如下:
default_user_name=admin
authorized_for_system_information=nagiosadmin,admin
authorized_for_configuration_information=nagiosadmin,admin
authorized_for_system_commands=admin
authorized_for_all_services=nagiosadmin,admin
authorized_for_all_hosts=nagiosadmin,admin
authorized_for_all_service_commands=nagiosadmin,admin  
authorized_for_all_host_commands=nagiosadmin,admin

7.安装HP的check_hpasm
#wget http://labs.consol.de/download/shinken-nagios-plugins/check_hpasm-4.6.3.2.tar.gz
#tar zxvf check_hpasm-4.6.3.tar.gz
#cd check_hpasm-4.6.3
#./configure --prefix=/usr/local/nagios
#make&&make install


8.安装dell的check_openmanage
# wget http://folk.uio.no/trondham/software/check_openmanage.html#download
# tar zxvf check_openmanage-3.7.11.tar.gz
# cd check_openmanage-3.7.11
# cp check_openmanage /usr/local/nagios/libexec/


9.安装snmp
yum --nogpgcheck install http://download.fedoraproject.org/pub/epel/6/i386/epel-release-6-5.noarch.rpm
yum install perl-Net-SNMP





二、HP服务器的客户端安装

1.下载软件包http://downloads.linux.hp.com/SDR/downloads/

hp-health-8.7.0.22-17.rhel6.x86_64.rpm

hpacucli-8.70-8.0.noarch.rpm
hp-snmp-agents-8.7.0.23-17.rhel6.x86_64.rpm
2.安装hp检测hp服务器硬件健康状态包和检测hp服务器磁盘阵列状态包
# rpm -ivh hp-health-8.7.0.22-17.rhel6.x86_64.rpm
# rpm -ivh hpacucli-8.70-8.0.noarch.rpm

提示安装依赖包

# yum installlibc.so.6 libgcc_s.so.1libstdc++.so.6


安装成功,启动服务

/etc/init.d/hp-health start

/etc/init.d/hp-asrd start

3.安装pciutils

# yum installpciutils*

4.安装SNMP

# yum install net-snmp


# vim /etc/snmp/snmpd.conf

增加一行

dlmod cmaX /usr/lib64/libcmaX64.so

修改


view  all included   .1

view  systemview  included       .1.3.6.1.2.1.1

view  systemview  included      .1.3.6.1.2.1.25.1.1


access notConfigGroup ""any noauth exact all all none


# service snmpd start

# chkconfig snmpd on

# rpm -ivh hp-snmp-agents-8.7.0.23-17.rhel6.x86_64.rpm

/etc/init.d/hp-snmp-agents start

然后在监控服务器测试

/usr/local/nagios/libexec/check_hpasm -H 172.16.8.15 -C public


.安装dell服务器

1.下载dell osma

# wget -q-O - http://linux.dell.com/repo/hardware/latest/bootstrap.cgi | bash

# yum install srvadmin-all –y

启动服务

/opt/dell/srvadmin/sbin/srvadmin-services.sh start

2. 安装snmp

# yum -y install net-snmp

# vim /etc/snmp/snmpd.conf

修改

view  all included   .1

view  systemview  included       .1.3.6.1.2.1.1

view  systemview  included      .1.3.6.1.2.1.25.1.1

access notConfigGroup ""any noauth exact all all none

启动服务器

/etc/init.d/snmpd restart

然后在监控服务器测试

/usr/local/nagios/libexec/check_openmanage -H 172.16.8.18 -C public


windows的就不介绍了

dell的去官网下载OM-SrvAdmin-Dell-Web

hp的在smartstart盘安装psp软件包

启动snmp服务器即可

安装已完成


配置

定义主机

vim /usr/local/nagios/etc/objects/linux.cfg

# hp server
define host{
        use                     linux-server            ; Name of host template to use
                                                        ; This host definition will inherit all variables that are defined
                                                        ; in (or inherited by) the linux-server host template definition.
        host_name               KVM152
        alias                   KVM152
        address                 172.16.8.152
        }
define host{
        use                     linux-server            ; Name of host template to use
                                                        ; This host definition will inherit all variables that are defined
                                                        ; in (or inherited by) the linux-server host template definition.
        host_name               KVM153
        alias                   KVM153
        address                 172.16.8.153
        }
define host{
        use                     linux-server            ; Name of host template to use
                                                        ; This host definition will inherit all variables that are defined
                                                        ; in (or inherited by) the linux-server host template definition.
        host_name               KVM154
        alias                   KVM154
        address                 172.16.8.154
        }
# dell server
define host{
        use                     linux-server            ; Name of host template to use
                                                        ; This host definition will inherit all variables that are defined
                                                        ; in (or inherited by) the linux-server host template definition.
        host_name               KVM155
        alias                   KVM155
        address                 172.16.8.155
        }
define host{
        use                     linux-server            ; Name of host template to use
                                                        ; This host definition will inherit all variables that are defined
                                                        ; in (or inherited by) the linux-server host template definition.
        host_name               KVM156
        alias                   KVM156
        address                 172.16.8.156
        }

定义命令

vim /usr/local/nagios/etc/objects/commands.cfg

#DELL OMSA
define command {
    command_name    check_hardware
    command_line    $USER1$/check_openmanage -H $HOSTADDRESS$ -C public -b $ARG1$
               }
define command {
    command_name    check_hardware_alertlog
    command_line    $USER1$/check_openmanage -H $HOSTADDRESS$ -C public --only=alertlog
               }
define command{
command_name omsa_status
command_line $USER1$/check_openmanage -H $HOSTADDRESS$ -C public
}
define command{
command_name omsa_cpu
command_line $USER1$/check_openmanage -H $HOSTADDRESS$ -C public --only cpu -p
}
define command{
command_name omsa_temp
command_line $USER1$/check_openmanage -H $HOSTADDRESS$ -C public --only temp -w $ARG1$ -c $ARG2$ -p
}
define command{
command_name omsa_storage
command_line $USER1$/check_openmanage -H $HOSTADDRESS$ -C public --only storage -p
}
define command{
command_name omsa_intrusion
command_line $USER1$/check_openmanage -H $HOSTADDRESS$ -C public --only intrusion -p
}
define command{
        command_name    omsa_fans
        command_line    $USER1$/check_openmanage -H $HOSTADDRESS$ -C public --only fans -p
}
define command{
        command_name    omsa_memory
        command_line    $USER1$/check_openmanage -H $HOSTADDRESS$ -C public --only memory -p
}
# HP
define command{
        command_name    hpasm
        command_line    $USER1$/check_hpasm -H $HOSTADDRESS$ -v -C public
}


定义服务
vim /usr/local/nagios/etc/objects/services.cfg

# HP
define service {
        use generic-service
        host_name       KVM152,KVM153,KVM154,KVM155,KVM156,KVM157,KVM158,KVM160,KVM166,KVM167,KVM169
        service_description hp
        check_command  hpasm
}
# DELL
define service {
        use generic-service
        host_name           KVM168,KVM158,KVM160,KVM166,KVM167,KVM169
        service_description omsa_status
        check_command omsa_status
}
define service {
        use                 generic-service
        host_name           KVM168,KVM158,KVM160,KVM166,KVM167,KVM169
        service_description  omsa_cpu
        check_command       omsa_cpu
}
define service {
        use                 generic-service
        host_name           KVM168,KVM158,KVM160,KVM166,KVM167,KVM169
        service_description  omsa_temp
        check_command       omsa_temp
}
define service {
        use                 generic-service
        host_name          KVM168,KVM158,KVM160,KVM166,KVM167,KVM169
        service_description  omsa_storage
        check_command       omsa_storage
}
define service {
        use                 generic-service
        host_name          KVM168,KVM158,KVM160,KVM166,KVM167,KVM169
        service_description  omsa_intrusion
        check_command       omsa_intrusion
}
define service {
        use                 generic-service
        host_name           KVM168,KVM158,KVM160,KVM166,KVM167,KVM169
        service_description  omsa_fans
        check_command       omsa_fans
}
define service {
        use                 generic-service
        host_name          KVM168,KVM158,KVM160,KVM166,KVM167,KVM169
        service_description  omsa_memory
        check_command       omsa_memory
}
        service_description omsa_status
        check_command omsa_status
}
define service {
        use                 generic-service
        host_name           KVM168,KVM158,KVM160,KVM166,KVM167,KVM169
        service_description  omsa_cpu
        check_command       omsa_cpu
}
define service {
        use                 generic-service
        host_name          KVM168,KVM158,KVM160,KVM166,KVM167,KVM169
        service_description  omsa_temp
        check_command       omsa_temp
}
define service {
        use                 generic-service
        host_name          KVM168,KVM158,KVM160,KVM166,KVM167,KVM169
        service_description  omsa_storage
        check_command       omsa_storage
}
define service {
        use                 generic-service
        host_name          KVM168,KVM158,KVM160,KVM166,KVM167,KVM169
        service_description  omsa_intrusion
        check_command       omsa_intrusion
}
define service {
        use                 generic-service
        host_name          KVM168,KVM158,KVM160,KVM166,KVM167,KVM169
        service_description  omsa_fans
        check_command       omsa_fans
}
define service {
        use                 generic-service
        host_name           KVM168,KVM158,KVM160,KVM166,KVM167,KVM169
        service_description  omsa_memory
        check_command       omsa_memory
}

配置nagios.cfg

vim /usr/local/nagios/etc/nagios.cfg

cfg_file=/usr/local/nagios/etc/objects/commands.cfg
cfg_file=/usr/local/nagios/etc/objects/contacts.cfg
cfg_file=/usr/local/nagios/etc/objects/timeperiods.cfg
cfg_file=/usr/local/nagios/etc/objects/templates.cfg
cfg_file=/usr/local/nagios/etc/objects/services.cfg
# Definitions for monitoring the local (Linux) host
cfg_file=/usr/local/nagios/etc/objects/localhost.cfg
cfg_file=/usr/local/nagios/etc/objects/linux.cfg


重启服务service nagios stop

测试有无报错

/usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg

无报错就可以启动服务

service nagios start

Nagios监控HP、Dell服务器的硬件状态_第1张图片