Balance is a flexible and very simple reverse proxy solution that gets the job done. Certainly there are other viable commercial and open source projects available to facilitate apache load balancing with fail-over. However, for the sake of brevity and simplicity, this example uses balance.
Here is all that you need to do to setup a load balanced set of zoned apache instances.
1. Add the following three entries into the /etc/hosts of the global zone so that the Zone Manager can resolve the automatically generated zone names to IP addresses.
192.168.0.96 zone0001
192.168.0.97 zone0002
192.168.0.98 zone0003
2. Add three zones to one or more servers.
# zonemgr -F -a add -o 'dCount|3' -I "ns|e1000g1|24|all" \
-s jail -G balance -G apache2
This invocation of the Zone Manager creates three zones that have been hardened such that all un-necessary services have been disabled. Each zone also has been configured with a unique IP address according to name resolution from /etc/hosts. Lastly, balance and apache2 were installed from Blastwave.org.
Note that if I wanted all four of the these apache instances to point to a single set of content, I could have used -r /data/www to read-only mount a custom apache document root /data/www into each of the four zones. Of course, you would need to re-configure each of the apache instances to point their document root directories to /data/www. There are two key benefits to this option. First, the web server content cannot be altered from within the non-global zones. So, if someone compromises any of the four apache instances, they cannot change the content unless of course point the apache server document root to an a different document root that they can change. The second benefit of this option is that the contents of the document root only needs to be cached into the ZFS filesystem once as opposed to once per apache instance. This can result in much better caching efficiency for many apache instances.
3. Run balance in each zone on port 81
# zlogin zone0001 \
"/opt/csw/sbin/balance 81 192.168.0.96:80 192.168.0.97:80 192.168.0.98:80"
# zlogin zone0002 \
"/opt/csw/sbin/balance 81 192.168.0.96:80 192.168.0.97:80 192.168.0.98:80"
"/opt/csw/sbin/balance 81 192.168.0.96:80 192.168.0.97:80 192.168.0.98:80"
# zlogin zone0003 \
"/opt/csw/sbin/balance 81 192.168.0.96:80 192.168.0.97:80 192.168.0.98:80"
"/opt/csw/sbin/balance 81 192.168.0.96:80 192.168.0.97:80 192.168.0.98:80"
There are many options with balance such as fail-over groups, sticky sessions, etc that you can take advantage of in the balance configuration. See balance man page for full set of configuration options.
4. Make each apache instance distinct to see the load balancing by editing the index.html of each apache instance.
vi /zones/zone000*/root/opt/csw/apache2/share/htdocs/index.html
Within each index.html, find and replace "Apache HTTP Server Test Page" with the respective non-global zone name. e.g. zone0001, zone0002, and zone0003.
5. The last step is simply to bring up a browser and point it to any of the four web pages and hit refresh every second or so to see the back end web server change. Be sure to hold down the shift key or which ever key is necessary to force reading the content from web server instead of reading the content from the browser's cache.
As an optional last step, you can also configure DNS to do round robin load balancing across the three IP addresses so that you can point the browser to a single domain name instead of going to IP addresses. Further, could also configure the apache instances to use a non-standard and non-privileged port like 8000 so that you could configure balance to use port 80 rather than port 81. Port 81 was just easier to use as in my example.
That is it. Have a great day!
Brad