Benchmarks Online

Skip Navigation Links


Page One

Campus Computing News

Summer Hours

Today's Cartoon

RSS Matters

The Network Connection

Link of the Month

WWW@UNT.EDU

Short Courses

IRC News

Staff Activities

Subscribe to Benchmarks Online
    

WWW@UNT.EDU

Apache web farm configuration:
Simpler than mod_macro?

By Shannon Eric Peevey, UNT Central Web Support

I have come up with a way to configure apache servers across a web farm, (using a single configuration), and without using mod_macro. All you need to do is to patch the /usr/sbin/apache2ctl shell script (on Debian) with the following diff:


--- apache2ctl.orig 2006-05-15 00:37:05.793938736 -0500

+++ apache2ctl 2006-05-03 11:53:01.000000000 -0500

@@ -77,11 +77,18 @@

 

case $ARGV in

start|stop|restart|graceful)

- $HTTPD -k $ARGV

+ $HTTPD -f /etc/apache2.conf -k $ARGV

ERROR=$?

;;

startssl|sslstart|start-SSL)

- $HTTPD -k start -DSSL

+

+ ### let's create our temp httpd.conf file (we'll call it apache2.conf for fun ;) )

+ LOCALIP=$(/sbin/ifconfig eth0 | awk '/inet/ { print $2 }' | awk -F ":" '{ print $2 }')

+ cat /etc/apache2/apache2.conf > /etc/apache2.conf

+ cat /etc/apache2/sites-enabled/* >> /etc/apache2.conf

+ sed -i "s/IPADDRESS/${LOCALIP}/g" /etc/apache2.conf

+

+ $HTTPD -f /etc/apache2.conf -k start -DSSL

ERROR=$?

;;

configtest)

NOTES:

These changes to the /usr/sbin/apache2ctl shell script essentially generate a new apache httpd.conf file every time the web server starts or stops. Let me explain these changes and walk you through each line:

1. LOCALIP=$(/sbin/ifconfig eth0 | awk '/inet/ { print $2 }' | awk -F ":" '{ print $2 }')

- This line grabs the ip address for the local machine and put it into the LOCALIP variable. We are running all machines off of a single set of configuration files, so we need to grab the local machines ip address, and will use sed to replace the placeholder, "IPADDRESS", with the contents of $LOCALIP.

2. cat /etc/apache2/apache2.conf > /etc/apache2.conf

- Cat the contents of the /etc/apache2/apache2.conf file into a file named /etc/apache2.conf. (This file can be named and placed anywhere. We just put it in /etc because configuration files are often found there). In the Debian Apache2 package, the /etc/apache2/apache2.conf file contains the global variables for our Apache configuration. For our purposes, we only need to change the ip addresses throughout conf file, (and vhost files), so I removed the ports.conf include directive and moved the contents of the ports.conf and the NameVirtualHost directives from the vhost conf files into /etc/apache2/apache2.conf. All instances of ip addresses have been replaced with a placeholder, "IPADDRESS":

--- oldconf/apache2.conf 2006-01-11 06:23:27.000000000 -0600

+++ apache2.conf 2006-05-05 11:01:50.000000000 -0500

@@ -119,8 +120,13 @@

# Include all the user configurations:

Include /etc/apache2/httpd.conf


+

# Include ports listing

-Include /etc/apache2/ports.conf

+# Include /etc/apache2/ports.conf

+Listen IPADDRESS:80

+Listen IPADDRESS:443

+Listen IPADDRESS:8080

+

 

# Include generic snippets of statements

Include /etc/apache2/conf.d/[^.#]*


@@ -389,13 +397,32 @@

# Allow from .your_domain.com

#</Location>


+NameVirtualHost IPADDRESS:80

+NameVirtualHost IPADDRESS:443

+NameVirtualHost IPADDRESS:8080

 

# Include the virtual host configurations:

Include /etc/apache2/sites-enabled/[^.#]*

 

3. cat /etc/apache2/sites-enabled/* >> /etc/apache2.conf

- Next, we append all enabled vhost config files to the /etc/apache2.conf. This has the advantage of creating a monolithic Apache conf file, but allows us to manage the server configuration using the great a2ensite/a2dissite tools that come with the Debian Apache2 package.

4. sed -i "s/IPADDRESS/${LOCALIP}/g" /etc/apache2.conf

- Finally, we use sed to do a global search and replace on the /etc/apache2.conf file to replace each instance of "IPADDRESS" with the ip address of the local machine on which apache is starting.

5. It is important to note that we need to add the new configuration file to the "stop" case as well:

start|stop|restart|graceful)

- $HTTPD -k $ARGV

+ $HTTPD -f /etc/apache2.conf -k $ARGV

ERROR=$?

;;

Or else apache will complain about syntax problems in the /etc/apache2/apache2.conf templates which are used to build the new /etc/apache2.conf configuration file.

Conclusion

Some of you may be surprised that I am replacing mod_macro with this new approach, but I find that this simple shell scripting allows for greater flexibility in managing the Apache configuration within the confines of the default Debian Apache2 package, and is much less complex to maintain than mod_macro. As our configuration file was approaching 2,000-3,000 lines, we were getting lost within the file and began to make mistakes while making configuration changes to Apache. This new approach allows us to move from the monolithic conf file, which is needed by mod_macro, and to take advantage of the simplicity of a split apache conf file, helping us to ensure maximum uptime by limiting the possible confusion caused by an overly-large configuration file.

 


Please note that information published in Benchmarks Online is likely to degrade over time, especially links to various Websites. To make sure you have the most current information on a specific topic, it may be best to search the UNT Website - http://www.unt.edu . You can also search Benchmarks Online - http://www.unt.edu/benchmarks/archives/back.htm as well as consult the UNT Helpdesk - http://www.unt.edu/helpdesk/ Questions and comments should be directed to
benchmarks@unt.edu

 

 

Return to top