环境:

1CentOS 6.6 x64 mini安装

2、系统软件有ApachePhpNagiosnagios-plugins

 

PS

1mini安装以后的环境缺少很多组件,需逐一完善后才能安装

2CentOS环境下需关闭防火墙 #service iptables stop

3CentOS环境下关闭Selinux

/etc/selinux/config文件中设置SELINUX=disabled

4CentOS配置环境时需能访问公网,便于后续做yum安装

 

初始化环境:

#yum install -y wget

 

#yum install -y gcc glibc glibc-common gd gd-devel xinetd openssl-devel

#yum install -y libxml2

#yum install  -y libxml2-devel

 

# yum install perl


#yum install -ynet-snmp*


需要下载的组件

# wget http://prdownloads.sourceforge.net/sourceforge/nagios/nagios-3.4.3.tar.gz

# wget http://nagios-plugins.org/download/nagios-plugins-1.4.16.tar.gz

# wget http://archive.apache.org/dist/httpd/httpd-2.2.23.tar.gz

# wget http://cn2.php.net/distributions/php-5.4.10.tar.gz


 

创建Nagios组与用户

# useradd -s /sbin/nologin nagios

# mkdir /usr/local/nagios

# chown -R nagios.nagios /usr/local/nagios

 

各组件的编译安装

####Nagios####

# tar zxvf nagios-3.4.3.tar.gz

# cd nagios-3.4.3

# ./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

 

####Nagios Plugins####

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

# cd nagios-plugins-1.4.16

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

# make && make install

 

####Apache####

# tar zxvf httpd-2.2.23.tar.gz

# cd httpd-2.2.23

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

# make && make install

 

####PHP####

# tar zxvf php-5.4.10.tar.gz

# cd php-5.4.10

# ./configure --prefix=/usr/local/php --with-apxs2=/usr/local/apache2/bin/apxs

# make && make install


修改apache配置

vi/usr/local/apache2/conf/httpd.conf

找到:

Userdaemon
Group daemon

修改为 

Usernagios
Group nagios

 

然后找到 

<IfModuledir_module>
DirectoryIndex index.html
</IfModule>

修改为 

<IfModuledir_module>
DirectoryIndex index.html index.php
</IfModule>

接着增加如下内容: 

AddTypeapplication/x-httpd-php .php

 

找到:

#ServerNamewww.example.com:80

在下面增加如下内容(CentOS是服务器的hostname

ServerNameCentOS:80

 

在文件最后面增加下面内容:

#settingfor nagios

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

<Directory"/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

</Directory>

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

<Directory"/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

</Directory>

 

创建apache目录访问权限

#/usr/local/apache2/bin/htpasswd -c /usr/local/nagios/etc/htpasswd NagiosLoginName

其中NagiosLoginName是访问用户,最后重复输入2次密码

 

启动apache

/usr/local/apache2/bin/apachectlstart


此时,基本可以通过http://ip/nagios/来访问Nagios,并进行下一阶段的设置。