Thursday, July 29, 2004

Configure session failover in an OC4J cluster (9i)

Summary
The test JSP shown below should be deployed as part of an EAR file (eg. mywar.ear) to a container (eg. wartest). The steps walk through how to test and ensure that sessions are failed over from one node to another in this active-active setup.

Prerequisites

  • 3 separate ORACLE_HOME's installed, one for the web server, and two for separate application servers.
  • The application servers should already be associated with an Infrastructure repository.

Details
1. Create the following test.jsp file, generate an EAR file that includes this JSP (eg. mywar.ear), and deploy it to a container (eg. wartest).
       
        <%@page session="true" %>
        <%
          if (request.getParameter("action") != null) {
            if (request.getParameter("action").equals("set")) {
              session.putValue("test",(String)session.getId());
            } else if (request.getParameter("action").equals("unset")) {
              session.putValue("test",null);
            }
          }
          if (session.getValue("test") == null) {
            out.println("Session variable 'test' is NULL.<br>");
          } else {
            out.println("Session variable 'test' has the session id ");
            out.println("value of: " + session.getValue("test") + ".<br>");
          }
        %>
        <br>
        <a href="test.jsp?action=set">Set session variable</a><br>
        <a href="test.jsp?action=unset">Remove session variable</a><br>
        <a href="test.jsp">Refresh page</a><br>
       
2. Before generating the EAR file, modify your web.xml (located in the WEB-INF directory) and add the following line immediately under.
           
            <distributable/>
           
3. Create a cluster using Enterprise Manager, and associate the application servers to this cluster.
           
a. Navigate to Oracle Enterprise Manager 10g Application Server Control (eg. http://app1.oracle.com:1810/)
            b. Click on Create Cluster
            c. Enter a cluster name, and click on Create (eg. AppServerCluster)
            d. Click on OK
e. Check the radio box on each application server, and click on Join Cluster (eg. do this for app1.oracle.com and app2.oracle.com)
           
4. Configure state replication (this step needs to be done only once on any application server within the cluster).
           
a. Navigate to Oracle Enterprise Manager 10g Application Server Control (eg. http://app1.oracle.com:1810/)
            b. Click on your application server (eg. app1.oracle.com)
            c. Click on wartest (in this document, we are using the wartest container)
            d. Click on Administration
            e. Click on Replication Properties
            f. Check Replicate session state
            g. Click on Apply
            h. Click on OK
           
5. Startup the wartest container on each application server (there are multiple ways to do this).
           
            dcmctl start -co wartest
           
6. Modify the mod_oc4j.conf file on your web server (located at $ORACLE_HOME/Apache/Apache/conf/) and add the following two lines:
           
            Oc4jMount /mywar cluster://AppServerCluster:wartest
        Oc4jMount /mywar/* cluster://AppServerCluster:wartest
           
7. Restart the web server:
           
            dcmctl stop -ct ohs
        dcmctl start -ct ohs
           
8. Test the session failover.
           
Navigate to test.jsp on your browser, click on Set session variable, and identify which application server you are hitting. Shutdown that application server container manually, and click on Refresh page, and the session variable should now be carried over to the other application server instance.
           
For comparison purposes, modify the web server's mod_oc4j.conf and use the following configuration instead:
            Oc4jMount /mywar instance://app1.oracle.com:wartest,app2.oracle.com:wartest
        Oc4jMount /mywar/* instance://app1.oracle.com:wartest,app2.oracle.com:wartest
           
            Upon repeating the same test, you will notice that the session is not carried over.
           
Applicable Versions

Oracle Application Server 10g (9.0.4)

The "LimitRequestLine" directive in OHS cannot exceed 8190 bytes

Summary
The "LimitRequestLine" directive in Oracle HTTP Server (OHS) cannot exceed 8190 bytes.

Details
1. The syntax of LimitRequestLine is:

LimitRequestLine 8190

LimitRequestLine must not exceed the precompiled maximum of 8190. This precompiled value can be found in the HTTP header file $ORACLE_HOME/Apache/Apache/include/httpd.h:
#define DEFAULT_LIMIT_REQUEST_LINE 8190

Therefore, set the LimitRequestLine directive to a value lower than or equal to 8190.

Applicable Versions
Oracle Application Server 10g (9.0.4)

References

http://httpd.apache.org/docs/mod/core.html#limitrequestline

Manually check status of Oracle HTTP Server (OHS)

Summary
The commands below use a combination of Oracle Application Server and Unix operating system commands to confirm that OHS is running.
The commands assume that the Oracle environment is set.

Details
1. Use DCMCTL to find out if OHS is up or not. Should return 'Up' if running and 'Down' if not.
    
dcmctl getstate -ct ohs | grep HTTP_Server | awk '{print $4}'

2. Use OPMNCTL to find out if OHS is up or not. Should return 'Alive' if running and 'Down' if not.
    
opmnctl status | grep HTTP_Server | awk '{print $7}'

3. Use DMSTOOL to determine whether OHS is alive or not. Should return 'Alive' if running and nothing if not.
    
dmstool -count 1 `dmstool -list | grep HTTP_Server | grep status.value` | tail -1 | cut -f2 -d' ' | awk '{print $2}'

4. Check for the PID and count the number of processes. Should return number of processes if running and 0 if not.

ps -e -o pid,ppid,comm | grep `cat $ORACLE_HOME/Apache/Apache/logs/httpd.pid 2 > /dev/null` 2 > /dev/null | grep httpd | grep -v grep | wc -l

5. Check if the port is listening. Should return 'LISTEN' if listening and nothing if not.
       
netstat -an | grep "`cat $ORACLE_HOME/Apache/Apache/conf/httpd.conf | grep Listen | grep -v "#" | head -1 | awk '{print $2}'` " | grep LISTEN | awk '{print $6}'

Applicable Versions
Oracle Application Server 10g (9.0.4)

Change the default EM (Enterprise Manager) port number

Summary
Changing the EMD_URL in $ORACLE_HOME/sysman/config/emd.properties does not change the EM web page port number. Changing the EM port number may break some standard EM links if the instance(s) have already been associated to an Infrastructure. These instructions change the port from 1813 to 1815.

Details
* On OAS 10.1.2, this can be simply done by running the following command:
        emctl config iasconsole port 1820

            However, if you are running OAS 9.0.4, this is done manually via the steps below...

1. Edit the $ORACLE_HOME/sysman/j2ee/config/emd-web-site.xml configuration file and update the following:
            OLD VALUE -->  port="1813"
        NEW VALUE -->  port="1815"

2. Edit the $ORACLE_HOME/sysman/config/emiasconsole.properties configuration file and update the following (optional):
            OLD VALUE -->  #oracle.sysman.emSDK.svlt.ConsoleServerPort=1813
        NEW VALUE -->  #oracle.sysman.emSDK.svlt.ConsoleServerPort=1815

3. Edit the $ORACLE_HOME/install/portlist.ini file (optional, only for documentation purposes):
            OLD VALUE -->  Application Server Control port = 1813
        NEW VALUE -->  Application Server Control port = 1815
           
4. Restart the EM console:
        emctl stop iasconsole
        emctl start iasconsole

Applicable Versions
Oracle Application Server 10g (9.0.4)