Load balancing refers to obtaining high availability and better performance by dispatching incoming user requests to different servers on a clustered setup. A load balancer can be anything from a simple servlet or plug-in, to expensive hardware. In this FAQ we will take a look at the Apache HTTP Server Plug-In and how it can be configured to proxy requests to the WebLogic cluster that we setup in FAQ #27 and FAQ #28.
Main Theme
"The Apache HTTP Server Plug-In allows requests to be proxied from an Apache HTTP Server to WebLogic Server. The plug-in enhances an Apache installation by allowing WebLogic Server to handle requests that require the dynamic functionality of WebLogic Server.
The plug-in is intended for use in an environment where an Apache Server serves static pages, and another part of the document tree (dynamic pages best generated by HTTP Servlets or JavaServer Pages) is delegated to WebLogic Server, which may be operating in a different process, possibly on a different host. To the end user—the browser—the HTTP requests delegated to WebLogic Server still appear to be coming from the same source.
The Apache HTTP Server Plug-In operates as an Apache module within an Apache HTTP Server. An Apache module is loaded by Apache Server at startup, and then certain HTTP requests are delegated to it. Apache modules are similar to HTTP servlets, except that an Apache module is written in code native to the platform."
In this example we will be installing the Apache HTTP Server on a separate Linux box. If you have followed the two previous FAQs (FAQ #27 and FAQ #28), we have setup a WebLogic cluster comprised of two Managed Servers running on two separate Linux machines.
1. Install the Apache HTTP Server
2. Install and configure the Apache HTTP Server Plug-In
3. Verify the load balancer
So, let's get started.
1. Install the Apache HTTP Server
We will be installing Apache on an openSUSE Linux distribution. Start by opening a terminal window and as root install Apache by typing: yast2 --install apache2. This will initiate YaST2 to download and install Apache.
Verify that the installation is successful by typing rcapache2 status in the terminal window. It should respond with status unused.
To test the installation we will need to create an index.html file in /srv/www/htdocs and start Apache by typing rcapache2 start.
Finally open a browser window and verify that the server is accessible.
For administration purposes it is recommended that you create an Apache administrator user account and give it ownership of the /srv/www, /srv/ftp and /etc/apache2 directories, the apache startup script /etc/init.d/apache2 and the log directory /var/log/apache2. Also add /usr/sbin to the account's path to get access to the rcapache2 start-up link.
The process of installing Apache is similar for other Linux distributions. For Windows you will have to download the Apache binary installation package from the Apache HTTP Server Project web site - http://httpd.apache.org/ at the time of this writing - and run the installation yourself.
2. Install and configure the Apache HTTP Server Plug-In
To download the Apache HTTP Server Plug-In go to the Oracle WebLogic downloads site - currently http://www.oracle.com/technetwork/middleware/ias/downloads/wls-main-097127.html - and click Oracle WebLogic Server Web Server Plugins 1.1 All versions under the Additional Fusion Middleware Downloads section. You will have to first click See All under the Oracle WebLogic Server 11g Rel 1 (10.3.3) Installers section to see the Additional Fusion Middleware Downloads.
This will download a cumulative archive - called WLSPlugin1.1-11gR1PS2.zip - which contains all WebLogic plug-ins. Open the archive and extract the archive appropriate for your Operating System, for this example - a 64-bit Linux distribution - it is called WLSPlugin1.1-64bitApache2.2-linux64-x86_64.zip.
To install the WebLogic Plug-In first extract the contents of the appropriate zip file - for this example we logged-in using the apache administrator account and extracted the WebLogic Plug-in into the /home/apache/WLSPlugin1.1-64bitApache2.2-linux64-x86_64 directory. Then edit the httpd.conf file in /etc/apache2 and add the following section:
# WebLogic load balancer add-in configuration
LoadModule weblogic_module /home/apache/WLSPlugin1.1-64bitApache2.2-linux64-x86_64/lib/mod_wl.so
<ifModule mod_weblogic.c>
WebLogicCluster 192.168.1.106:7003,192.168.1.107:7003
Debug ON
WLLogFile /home/apache/WLSPlugin1.1-64bitApache2.2-linux64-x86_64/log/mod_wl.log
WLTempDir /home/apache/WLSPlugin1.1-64bitApache2.2-linux64-x86_64/tmp
DebugConfigInfo ON
KeepAliveEnabled ON
KeepAliveSecs 15
DynamicServerList ON
</IfModule>
<Location /cluster>
SetHandler weblogic-handler
</Location>
Change the cluster IP addresses and ports appropriately for your setup. Also ensure that the log and temporary directories that you specify exist - for this example we have created a log and a tmp directory inside the directory where we originally extracted the plug-in. Lastly, make sure that the plug-in library directory is listed in the LD_LIBRARY_PATH environment variable.
Now restart Apache and observe that there are no errors. For complete installation instructions refer to the file README.txt included in the compressed archive.
3. Verify the load balancer
To verify the load balancer installation you need to send a request to a http://apache-host:apache-port/cluster/ URL, where apache-host is the host running Apache, apache-port is the Apache HTTP port, cluster is the configurable context path we specified above with the <Location> tag when configuring the plug-in. Because of the /cluster context in the URL path, Apache will forward the request via the WebLogic Plug-In to the WebLogic cluster. Any requests that do not contain the /cluster context in the URL will be served normally by Apache.
So, let's start JDeveloper and create a simple ADF application. On the Edit WAR Deployment Profile Properties dialog make sure that cluster is specified as the Java EE Web Context Root.
Ensure that the cluster is up and running, create an Application Server connection to the WebLogic cluster, an application deployment profile and deploy the application on the cluster.
Observe at the log window that the deployment is successful for all managed server nodes that make up the cluster.
You can test the load balancer by sending the following request http://apache-host:apache-port/cluster/faces/TestLoadBalancer.jspx, for this example the IP address of the Apache server is 192.168.1.101, so the complete URL is http://192.168.1.101/cluster/faces/TestLoadBalancer.jspx. Apache recognizes the /cluster context path in the URL and forwards the request to WebLogic via the WebLogic Plug-In!
Any requests that do not contain the /cluster context in the URL are served normally by Apache.
For the Apache WebLog Plug-In logs refer to the log file defined during the configuration earlier.
Conclusion
In this post we 've seen how a software Load Balancer based on Apache and the Apache WebLogic Plug-In could be setup to work along with a cluster setup.
Until the next time, keep on JDeveloping!
No comments:
Post a Comment