一、基础环境准备

  1.yum源配置

yum -y localinstall ftp://195.220.108.108/linux/dag/redhat/el6/en/x86_64/dag/RPMS/rpmforge-release-0.5.2-1.el6.rf.x86_64.rpm

yum -y localinstall https://repo.mysql.com//mysql57-community-release-el6-11.noarch.rpm

#修改mysql源为5.7关闭,5.6 开启

  2.安装GD及LAMP平台

yum -y install httpd gd fontconfig-devel libjpeg-devel libpng-devel gd-devel perl-GD openssl-devel perl-DBD-MySQL mysql-community-server mysql-community-devel php php-devel php-mysql php-gd php-ldap php-xml php-mbstring

Perl及扩展模块

yum -y install perl-Config-IniFiles perl-DBI perl-DBD-MySQL perl-Crypt-DES perl-Digest-SHA1

  4.安装SNMP及依赖库

yum -y install perl-Digest-HMAC net-snmp-utils perl-Socket6 perl-IO-Socket-INET6 net-snmp net-snmp-libs php-snmp

  5.安装RRDTool绘图工具

yum -y install rrdtool perl-rrdtool

  6.安装其他所需基础包

yum -y install dmidecode lm_sensors perl-Net-SNMP net-snmp-perl fping cpp gcc gcc-c++ libstdc++ glib2-devel

  7.安装PEAR

yum -y install php-pear php-pear-DB

 

二、Nagios的安装

  1.下载安装包

cd /usr/local/src && wget https://assets.nagios.com/downloads/nagioscore/releases/nagios-4.3.2.tar.gz#_ga=2.75280209.2104107475.1497007184-1455607473.1497007184

  2.创建nagios用户和用户组

groupadd -g 9000 nagios && groupadd -g 9001 nagcmd && useradd -u 9000 -g nagios -G nagcmd -d /home/nagios -c "Nagios Admin" nagios && usermod -G nagcmd apache

#执行上面的语句限于在Centos6,验证httpd运行用户:grep "^User" /etc/httpd/conf/httpd.conf

  3.编译安装nagios

configure配置参数清单

序号

属性名

参数值

configure参数

1

nagios安装目录

/usr/local/nagios

--prefix

2

nagios配置文件目录

/usr/local/nagios/etc

--sysconfdir

3

nagios运行数据目录

/usr/local/nagios/var

--localstatedir

4

nagios用户

nagios(9000)

 --with-nagios-user

5

nagios用户组

nagios(9000)

 --with-nagios-group

6

nagios命令组

nagios(9001)

--with-command-group

7

开启nagios事件代理的Perl解释器(可以在nagios运行时,使事件代理Event Broker模块提供对外调用接口)

 

--enable-embedded-perl

8

开启Perl缓存

 

--with-perlcache

 

 

mkdir /usr/local/nagios && chown -R nagios:nagios /usr/local/nagios
cd /usr/local/src/ && tar xf nagios-4.3.2.tar.gz && cd nagios-4.3.2 && ./configure --prefix=/usr/local/nagios --with-nagios-user=nagios --with-nagios-group=nagios --with-command-group=nagcmd --enable-embedded-perl --with-perlcache --enable-nanosleep --enable-broker 
make all && make install && make install-init && make install-commandmode && make install-webconf && make install-config

    

nagios教程视频 nagios安装_Linux

nagios教程视频 nagios安装_常用软件部署_02

在/usr/local/nagios下的目录清单

序号

目录

内容清单

1

./bin

Nagios可执行程序所在目录

2

./libexec

外部插件存放目录

3

./sbin

CGI脚本

4

./share

文档、HTML文件存放目录

5

./etc

配置文件目录

6

./var

运行时日志、数据文件、lock文件所在目录

7

./var/archives

Nagios日志自动归档目录

8

./var/rw

用来存放外部命令文档的目录

 

三、安装nagios插件

  1.下载安装包

cd /usr/local/src && wget https://nagios-plugins.org/download/nagios-plugins-2.2.1.tar.gz#_ga=2.75280209.2104107475.1497007184-1455607473.1497007184

  2.编译安装nagios-plugins

cd /usr/local/src/ && tar xf nagios-plugins-2.2.1.tar.gz && cd nagios-plugins-2.2.1 && ./configure --prefix=/usr/local/nagios --with-nagios-user=nagios --with-nagios-group=nagios --with-openssl=/usr/bin/openssl --enable-perl-modules && make && make install

  检查清单:

    

nagios教程视频 nagios安装_perl_03

四、配置Nagios的WEB用户界面

  1.配置/etc/httpd/conf.d/nagios.conf文件 #前提已经安装上述步骤执行了 make install-webconf

# SAMPLE CONFIG SNIPPETS FOR APACHE WEB SERVER
#
# This file contains examples of entries that need
# to be incorporated into your Apache web server
# configuration file.  Customize the paths, etc. as
# needed to fit your system.

ScriptAlias /nagios/cgi-bin "/usr/local/nagios/sbin"

<Directory "/usr/local/nagios/sbin">
#  SSLRequireSSL
   Options ExecCGI
   AllowOverride None
   <IfVersion >= 2.3>
      <RequireAll>
         Require all granted
#        Require host 127.0.0.1

         AuthName "Nagios Access"
         AuthType Basic
         AuthUserFile /usr/local/nagios/etc/htpasswd.users
         Require valid-user
      </RequireAll>
   </IfVersion>
   <IfVersion < 2.3>
#      Order allow,deny
#      Allow from all
       Order deny,allow
       Deny from all
       Allow from 127.0.0.1
       Allow from 10.124.151.0/24

      AuthName "Nagios Access"
      AuthType Basic
      AuthUserFile /usr/local/nagios/etc/htpasswd.users
      Require valid-user
   </IfVersion>
</Directory>

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

<Directory "/usr/local/nagios/share">
#  SSLRequireSSL
   Options None
   AllowOverride None
   <IfVersion >= 2.3>
      <RequireAll>
         Require all granted
#        Require host 127.0.0.1

         AuthName "Nagios Access"
         AuthType Basic
         AuthUserFile /usr/local/nagios/etc/htpasswd.users
         Require valid-user
      </RequireAll>
   </IfVersion>
   <IfVersion < 2.3>
      Order allow,deny
      Allow from all
#     Order deny,allow
#     Deny from all
#     Allow from 127.0.0.1

      AuthName "Nagios Access"
      AuthType Basic
      AuthUserFile /usr/local/nagios/etc/htpasswd.users
      Require valid-user
   </IfVersion>
</Directory>

  2.检查Selinux是否已关闭

    

nagios教程视频 nagios安装_Linux_04

  3.设置访问用户认证与授权

    首先确认文件/usr/local/nagios/etc/cgi.cfg

    

nagios教程视频 nagios安装_Linux_05

  然后执行下面的命令:

#第一次创建用户
htpasswd -c /usr/local/nagios/etc/htpasswd.users nagiosadmin
#第二次+创建用户
htpasswd  /usr/local/nagios/etc/htpasswd.users nagiosatest
#设置文件属性
chmod g+w /usr/local/nagios/etc/htpasswd.users && chown nagios:nagios /usr/local/nagios/etc/htpasswd.users

  4.启动httpd服务

service httpd start

  5.启动nagios并登录验证

service nagios start

    登录http://IP/nagios输入用户名密码查看是否正常。

    

nagios教程视频 nagios安装_apicloud_06

五、nrpe安装:

  1.下载nrpe-3.1.0.tar.gz

cd /usr/local/src && wget https://ncu.dl.sourceforge.net/project/nagios/nrpe-3.x/nrpe-3.1.1/nrpe-3.1.1.tar.gz

  2.编译安装

cd /usr/local/src/nrpe-3.1.0 &&  ./configure --prefix=/usr/local/nagios && make all && make install && make install-config && make install-plugin

  3.配置守护进程启动:/etc/xinetd.d/nrpe

# default: on
# description: NRPE (Nagios Remote Plugin Executor)
service nrpe
{
       	flags           = REUSE
        socket_type     = stream    
	port		= 5666    
       	wait            = no
        user            = nagios
	group		= nagios
       	server          = /usr/local/nagios/bin/nrpe
        server_args     = -c /usr/local/nagios/etc/nrpe.cfg --inetd
	log_type        = file /tmp/nrpe.log
       	log_on_failure  += USERID
        disable         = no
	only_from       = 10.124.151.248
}

  

六、nagios监控配置: