Sunday, June 3, 2007

Apache Httpd and Tomcat integration using mod_jk, part 2

This posting splitted because somehow blogspot just cut it. I don't know why but when I previewed the posting, blogspot just cut the postings, so I splitted it into 2 parts.

Ok, now we create workers.properties file.
onty@phoenix:/opt/httpd-2.2.4$ vi conf/workers.properties
------------------------------------------------------------------------------------
worker.list=router,jkstatus
# Define a worker using ajp13
worker.worker1.port=8009
worker.worker1.host=localhost
worker.worker1.type=ajp13
worker.worker1.lbfactor=1
# Define prefered failover node for worker1
worker.worker1.redirect=worker2
# Define another worker using ajp13
worker.worker2.port=8009
worker.worker2.host=localhost
worker.worker2.type=ajp13
worker.worker2.lbfactor=1

# Define the LB worker
worker.router.type=lb
worker.router.balance_workers=worker1,worker2
# Define the status worker
worker.jkstatus.type=status

------------------------------------------------------------------------------------
This file defines all our workers. Our 'router' worker will be a load balancer worker for other workers, including worker1 and worker2.

Now, we install (unzip, exactly) our apache. We use apache-5.2.23. We will modify the directory structure little bit, as shown like this.


Give attention to tomcat1 and tomcat2 directory, and also directories inside it.We will use 2 instance of tomcat1 and tomcat2 as worker 'worker1' and 'worker2'. We also need to configure each server.xml in tomcat1 and tomcat2 so that they're not using the same port.
Tomcat1 :
Server port="8005" shutdown="SHUTDOWN"
..
..
Connector port="8009"
enableLookups="false" redirectPort="8443" protocol="AJP/1.3"
..
..

Connector port="8080" maxHttpHeaderSize="8192"
maxThreads="150" minSpareThreads="25" maxSpareThreads="75"
enableLookups="false" redirectPort="8443" acceptCount="100"
connectionTimeout="20000" disableUploadTimeout="true"

Tomcat2 :
Server port="9005" shutdown="SHUTDOWN"
..
..
Connector port="9009"
enableLookups="false" redirectPort="8443" protocol="AJP/1.3"
..
..

Connector port="8080" maxHttpHeaderSize="8192"
maxThreads="150" minSpareThreads="25" maxSpareThreads="75"
enableLookups="false" redirectPort="8443" acceptCount="100"
connectionTimeout="20000" disableUploadTimeout="true"

One more thing, we need to create startup and shutdown file for each tomcat instance. We call it start1.sh, start2.sh, stop1.sh, stop2.sh
start1.sh
#!/bin/bash
export CATALINA_BASE=/opt/apache-tomcat-5.5.23-cluster/tomcat1
export JAVA_HOME=/opt/jdk1.6.0
./startup.sh
start2.sh
#!/bin/bash
export CATALINA_BASE=/opt/apache-tomcat-5.5.23-cluster/tomcat2
export JAVA_HOME=/opt/jdk1.6.0
./startup.sh
stop1.sh
#!/bin/bash
export CATALINA_BASE=/opt/apache-tomcat-5.5.23-cluster/tomcat1
export JAVA_HOME=/opt/jdk1.6.0
./shutdown.sh
stop2.sh
#!/bin/bash
export CATALINA_BASE=/opt/apache-tomcat-5.5.23-cluster/tomcat2
export JAVA_HOME=/opt/jdk1.6.0
./shutdown.sh

Basically, these file just aimed to setup environment variable named CATALINA_BASE to point which tomcat instance we want to start/stop.

Now, lets try our installation. Start both tomcat instance, and also start your httpd server. Point out the browser to http://localhost/tomcat-docs/ and see if the request handled correctly. Httpd will redirect the request so that can be served by tomcat. Also point the browser to http://localhost/jkmanager/. This context path shows us the Load Balancing status for our tomcat instance.

Feel free to drop any comments about this posting.
Thanks, good luck trying !

Apache Httpd and Tomcat integration using mod_jk, part 1

In my other blog, I've wrote about howto use mod_jk2 to integrate httpd and tomcat. The article can be accesed here and here.
Now, since mod_jk2 has not supported again by apache-tomcat-connector developers, so in this article I will use mod_jk. I'm using :
  • httpd-2.2.4, can be downloaded here
  • tomcat-5.2.23, can be downloaded here
  • tomcat-connector, can be downloaded here

I prefer apache.the.net.id since this is the nearest mirror from Indonesia. O ya, Im using Kubuntu Feisty Fawn in my laptop.
First, we install the httpd-2.2.4 first. Unzip it, place it at some directory you like. In my environment, my user has full access to /opt directory, so I'm using it.
onty@phoenix:/opt$ gunzip httpd-2.2.4.tar.gz
onty@phoenix:/opt$ tar -xvf httpd-2.2.4.tar
onty@phoenix:/opt$ mv httpd-2.2.4 httpd-2.2.4-src
onty@phoenix:/opt$ cd httpd-2.2.4-src
Configure, put the result in /opt/httpd-2.2.4, enable shared object, enable cgi support. Enabling shared object makes us able to load dynamic shared object library. We're using mod_jk's shared object, so we need to enable apache to support dynamic shared object library. This also usefull if you want to enable your apache httpd server to serve PHP also. Same like this, you would also compile PHP as shared object, and then load it dynamically to apache httpd using LoadModule syntax in your httpd.conf .
onty@phoenix:/opt/httpd-2.2.4-src$ ./configure --prefix=/opt/httpd-2.2.4 --enable-so --enable-cgi
onty@phoenix:/opt/httpd-2.2.4-src$ make onty@phoenix:/opt/httpd-2.2.4-src$ make install
Now, try to start it using root :
onty@phoenix:/opt/httpd-2.2.4-src$ cd /opt/httpd-2.2.4
onty@phoenix:/opt/httpd-2.2.4$ su -
root@phoenix:/opt/httpd-2.2.4# bin/apachectl start
If everything ok, you should be able to point your browser to http://localhost now, and see if you can read any "It works" there.
OK, now we continue to install the tomcat connector. Apache has provided us with the binary version of the connector. As mentioned in before, we should now already download it. I'm using mod_jk-1.2.21-apache-2.2.x-linux-i686.so. What we need to do is just load this shared object so that can be used by apache, that simple ? yes :D
Edit your httpd.conf, add this line :
Include conf/extra/mod_jk.conf
This is new style from apache that makes us easier to maintain our configuration file in modular basis.
Now create a new file in conf/extra/ name it mod_jk.conf.
--------------------------------------------- mod_jk.conf -----------------------------------
JkWorkersFile /opt/httpd-2.2.4/conf/workers.properties
JkShmFile /var/log/httpd/mod_jk.shm

JkLogFile /opt/httpd-2.2.4/logs/mod_jk.log
JkLogLevel info
JkLogStampFormat "[%a %b %d %H:%M:%S %Y]"
JkMount /tomcat-docs/* router

JkMount jkstatus
Order deny,allow
Deny from all
Allow from 127.0.0.1

-------------------------------------------------------
From the configuration file, we can see that :
We will place the log file in /opt/httpd-2.2.4/logs/mod_jk.log.
We will configure the connectors with a file named workers.properties located in /opt/httpd-2.2.4/conf .
We will have shared file that will be used by apache and tomcat, located in /var/log/httpd/mod_jk.shm. If the directory /var/log/httpd doesnt exist yet, we should create it first using root user.
The logger level will be INFO.
We will map /tomcat-docs/ request in httpd to be handled by tomcat, so make sure that this webapp exist in tomcat. By default if you download tomcat, this webapp is already exist. Later you can change it to your own webapp. And this request will be handled by a worker named 'router'.
Last one is for jkmanager monitoring tools. There will be new context path named /jkmanager/ that will show us status for our jk_module. This context path only allowed to be accessed from 127.0.0.1 (localhost).

Ok, now we need to create workers.properties in conf/ directory. See part 2 of this post.

Friday, June 1, 2007

Tora(Toolkit for Oracle) Installation

Yesterday I managed to install my laptop with Tora. I'm using Kubuntu Feisty Fawn.For you who doesnt have any idea what kind of animal Tora is, let me give you some hint. If you used to use Toad in M$-Windows to do your oracle database-related jobs, well, you can say that Tora has similar usage.It can runs on Linux, make your life simpler, and easier, he he. Hey, it's your laptop that should work for you, not you're the one that has to work for your laptop, right ?
Ok, here's the step I saved from my installation adventure :

1. get Oracle instant client
You can get it here :
http://download.oracle.com/otn/linux/instantclient/instantclient-basic-linux32-10.2.0.3-20061115.zip
http://download.oracle.com/otn/linux/instantclient/instantclient-sdk-linux32-10.2.0.3-20061115.zip

2. Unzip it at some directory, e.g : /opt/instantclient_10_2

3. Add the directory to /etc/ld.so.conf, dont forget run /sbin/ldconfig.
Here's the sample from my laptop :
------------------
onty@phoenix:~$ cat /etc/ld.so.conf
/lib
/usr/lib
/usr/lib/firefox/plugins
/opt/instantclient_10_2
------------------

4. Install libqscintilla.
Thank God, I'm using Kubuntu,and having great internet connection in my office. So just simply run apt-get.
root@phoenix:/opt# apt-get install libqscintilla6 libqscintilla-dev

5. Download and Unzip tora
You can get it here. I'm using version 1.3.21.

6. compile start
oracle@phoenix:/opt/tora-1.3.21$ ./configure --with-qt-dir=/usr/lib/qt3 --with-oracle-libraries=/opt/instantclient_10_2 --with-oracle-includes=/opt/instantclient_10_2/sdk/include --with-oci-version=10G --with-instant-client
oracle@phoenix:/opt/tora-1.3.21$ make
oracle@phoenix:/opt/tora-1.3.21$ make install

7. In the midde of make, I'm getting error says that toThreadStartWrapper has not been declared. I googled around to find the solution, and found out that I have to edit a file named tothread.cpp around line 157 like below.

#define THREAD_ASSERT(x) if((x)!=0) { \
throw (qApp->translate("toThread","Thread function \"%1\" failed.").arg(QString::fromLatin1( #x ))); }

/* new added start */
void *toThreadStartWrapper(void *t);
/* new added end */

void toThread::initAttr()

After that, I continued with make, and make install.

And finally, run ./tora and you can see ORACLE option in your connection. That connection refers to wherever you put our TNSNAMES.ORA in your ORACLE_HOME.


OK, that's for today's tip.