linux下安装配置apache+nagios

1、安装依赖包

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

2、创建nagios用户和用户组

# useradd -s /sbin/nologin nagios
# mkdir /usr/local/nagios
# chown -R nagios.nagios /usr/local/nagios

3、编译安装Nagios

wget http://prdownloads.sourceforge.net/sourceforge/nagios/nagios-3.4.3.tar.gz
tar zxvf nagios-3.4.3.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

4、安装Nagios 插件

wget http://nagios-plugins.org/download/nagios-plugins-2.1.1.tar.gz#_ga=1.133786765.2089205511.1463105544
tar zxvf nagios-plugins-1.4.16.tar.gz
cd nagios-plugins-1.4.16
./configure --prefix=/usr/local/nagios
make && make install

5、安装与配置Apache

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

6、安装Php

wget http://cn2.php.net/distributions/php-5.4.10.tar.gz
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

7、配置apache

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

找到

User daemon 
Group daemon 

修改为

User nagios 
Group nagios 

  在LoadModule中添加:

LoadModule php5_module     modules/libphp5.so

  在DirectoryIndex增加 index.php,以便Apache识别PHP格式的index

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

  添加以下行

<FilesMatch "\.php$">
    SetHandler application/x-httpd-php
</FilesMatch>
<FilesMatch "\.phps$">
    SetHandler application/x-httpd-php-source
</FilesMatch>
AddType application/x-httpd-php .php

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

 

#setting for 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 david

 

启动apahce服务

/usr/local/apache2/bin/apachectl start

 

 

 

参考文章:http://www.cnblogs.com/mchina/archive/2013/02/20/2883404.html

posted @ 2016-05-13 14:24  巫谢  阅读(413)  评论(0编辑  收藏  举报