![]()
Apache web farm configuration:
By Shannon Eric Peevey, UNT Central Web SupportIntroductionI 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:
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":
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:
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. ConclusionSome 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.
Have you registered your website yet?
|