Multiple Apache httpd configurations - One Installation

Description
This is an extension to the http daemon from apache.org.

The goal was to advance apache's http daemon that we can start it with multiple configurations on one single server with many ip addresses! We use the http daemon generally for loadbalancing Tomcat/IIS/... applications + SSL offloading.

On our former installations we had to compile the http daemon for every instance we wanted to run on the server. Now we can compile/install one apache http daemon and use this single instance with multiple configurations. (ip's/ssl-certificates/...)

The other goal was that it had to be easy to change the http daemon version to a newer one which is now pretty charming! :)

Installing & configuring the httpd
Create apache2 folder in /usr/local

 Downloading the source to root/software 

eventually set proxy environment variable export http_proxy=http://IP:Port wget http://mirror.deri.at/apache/httpd/httpd-2.2.XX.tar.gz

 Patching the sources 

If your installation is not that big (# of access) you can skip the following step.

Set the compiler flag via the enironment varible:

export CFLAGS=-DDEFAULT_THREAD_LIMIT=256

 Installing the needed libraries 

apt-get install zlib1g-dev libssl-dev build-essentials

 Extracting the downloaded source 

tar -zxvf httpd-2.2.XX.tar.gz

 Building & installing the package 

After patching the sources (if necessary for you) it's time to configure / compile & install apache's http daemon.

make clean

Change to the extracted httpd-2.2.XX directory. ./configure --enable-mods-shared=all --enable-modules=all --enable-proxy --enable-proxy-connect --enable-proxy-ftp \ --enable-proxy-http --enable-proxy-balancer --enable-ssl=shared --with-mpm=worker --prefix=/usr/local/apache2/2.2.XX \ --exec-prefix=/usr/local/apache2/2.2.XX

make make install

 Creating symlink 

Creating the "core"-link (symlink) in the /usr/local/apache2/ folder to 2.2.XX ln –s 2.2.XX core

Installing & configuring mod_jk (Tomcat Connector)
 Downloading the source to root/software 

wget http://mirror.deri.at/apache/tomcat/tomcat-connectors/jk/source/jk-1.2.XX/tomcat-connectors-1.2.XX-src.tar.gz

 Extracting the downloaded source 

tar -zxvf tomcat-connectors-1.2.XX.tar.gz

 Building & installing the package 

cd tomcat-connectors-1.2.XX-src/native make clean

Change to the "native"-folder ./configure --with-apxs=/usr/local/apache2/core/bin/apxs make make install

Installing & configuring mod_perl
This module is needed for mod_macro!

 Downloading the source to root/software 

wget http://perl.apache.org/dist/mod_perl-2.0-current.tar.gz

 Installing the needed libperl library 

apt-get install libperl-dev

 Extracting the downloaded source 

tar -zxvf mod_perl-2.0-current.tar.gz

 Building & installing the package 

cd mod_perl-2.0.X

perl Makefile.PL MP_APXS=/usr/local/apache2/core/bin/apxs

make

The module was build under ./src/modules/perl/mod_perl.so in the build directory.

cp ./src/modules/perl/mod_perl.so /usr/local/apache2/core/modules/

Installing & configuring mod_macro
mod_macro is a great configuration enhancement for apache's http daemon. We use it to make our configurations easier to read & change!

 Downloading the source to root/software 

wget http://www.coelho.net/mod_macro/mod_macro-latest.tar.gz

 Extracting the downloaded source 

The source has to be extracted to the source directory of the apache! tar –zxvf mod_macro-1.1.XX cp -Rp mod_macro-1.1.XX httpd-2.2.XX

 Building & installing the package 

cd /root/software/httpd-2.2.XX

/usr/local/apache2/core/bin/apxs -c mod_macro-1.1.XX/mod_macro.c

 Installing the build module 

cp ./mod_macro-1.1.11/.libs/mod_macro.so /usr/local/apache2/core/modules/

Template extension
Includes manage_apache.pl + search_replace.pl + template. The manage_apache.pl & search_replace.pl is available as download in the specific sections. Thx to snipt.org where most of our scripts are hosted! :)

Description
 Description of "manage_apache.pl" parameters 

manage_apache.pl [ options ] 

-help|? print help -ip|ipaddress  IP address -port          Port -folder|path   Folder name -delete|remove Folder name -apache        init-script prefix -force         Force installation

manage_apache.pl -ip IPADDRESS -port PORT -folder FOLDERNAME -apache APACHEFOLDER -delete FOLDERNAME -force yes/y

 Description of "search_replace.pl" parameters 

int replace (InputFile, OutputFile, search-String, replace-String);

1.) Input file will be copied to /tmp/$file. $file will be extracted from input file (ex: inputfile: /usr/local/apache2/folderXY/conf/httpd.conf -> $file = httpd.conf)

2.) Search string will be searched and written to the output file

3.) /tmp/$file will be deleted

4.) Returned value = how often the search string was found (& replaced)

 Description of "manage_apache.pl" script with "search_replace.pl" function 

1.) The whole template folder will be copied to $prefix/$folder (ex: /usr/local/apache2/folderXY)

2.) The following values will be replaced in httpd.conf (IP, Port, SSLPort, Folder, Prefix)

3.) The httpd start/stop script will be renamed from "template" to $folder (in /bin)

4.) The value XXConfig will be replaced by $folder

5.) Init-Script for the new httpd will be linked (ln -s /usr/local/apache2/$folder/bin/$folder /etc/init.d/apache2_$folder)

6.) Create runlevel entries (update-rc.d apache2_$folder defaults)

 Modified httpd.conf in our template 

1.) The mod_jk-module was linked

LoadModule jk_module modules/mod_jk.so

2.) Some more configurations

MaxKeepAliveRequests 100 KeepAliveTimeout 5
 * 1) KEEPALIVE TIMEOUT


 * 1) MPM CONFIGURATIONS

        ServerLimit 25 StartServers 10 MaxClients 1600 ThreadLimit 64 MinSpareThreads 25 MaxSpareThreads 256 ThreadsPerChild 64 MaxRequestsPerChild 0  

        ServerLimit 25 StartServers 10 MaxClients 3200 ThreadLimit 128 MinSpareThreads 25 MaxSpareThreads 256 ThreadsPerChild 128 MaxRequestsPerChild 0  

Options -Indexes

Include conf/sites-enabled/*
 * 1) LOAD CONFIGURATIONS

3.) Folders where created/linked under /conf ("sites-enabled" & "sites-available")

4.) The mod_perl-module was linked

LoadModule perl_module modules/mod_perl.so

 Error Hey, you forgot to install mod_perl! I need it! 

5.) The mod_macro-module was linked

LoadModule macro_module modules/mod_macro.so

manage_apache.pl


search_replace.pl


Links
Many thanks to the developers of the Apache http server as well as the modules mod_jk, mod_perl & mod_macro! Here are some nice links!

Apache HTTP Server Module mod_jk Module mod_perl Module mod_macro

- last edit .. by