Apache 2 + Tomcat 5 + mod_jk 的整合[转载]

Installing JDK (Java Development Kit)
In order to run Tomcat, you will need to install JDK and set the JAVA_HOME environment variable to identify the location of the JDK environment on your system. I have chosen to use JDK 5.0.
1. You can download JDK 5.0 at
2. Click on Download JDK 5.0 Update 6 to go to the download page.
3. Click Accept to accept the license agreement.
4. Next choose the Linux self-extracting file. This is the download for the self-extracting binary file rather than the rpm.
5. Download to your preferred download directory. Change to that
directory and make it executable by executing the following command:
chmod +x jdk-1_5_0_06-linux-i586.bin
Now execute the file:
You should now have a new directory called jdk1.5.0_06. Now move this directory to the location where it should be run. I chose /usr/lib/.
mv jdk1.5.0_06 /usr/lib
Now create a symbolic link called jdk to JAVA_HOME by the following command. This allows you to easily switch back and forth between different jvms should you ever need to.
cd /usr/lib
ln -s jdk1.5.0_06 jdk
Now we need to set the JAVA_HOME environment variable. Add the following at the end of /etc/profile just after export PATH.
export JAVA_HOME
/etc/profile is executed at startup and
when a user logs into the system. In order to update the environment
you will need to log out and log back in to the system.
Check to make sure JAVA_HOME is defined correctly by executing the command below. This should report the location of the Java SDK which should be /usr/lib/jdk.

Installing Tomcat
In this section you will download and install Apache Tomcat 5.5.16.
For this particular setup, there is no need to build the package from
source, we will download the binary version.
1. Download the binary version to your preferred download directory from here:
. Choose the tar.gz from the core section for 5.5.16.
2. Now change to that directory and extract the files using the following command:
cd /mydownloads #(be sure to change to your download directory)
tar xvzf apache-tomcat-5.5.16.tar.gz
You should now have a new directory called apache-tomcat-5.5.16. Now move this directory to the location where it should be installed. Again, I chose /usr/lib/. Note that this location will be referred to as CATALINA_HOME in the Tomcat documentation.
mv apache-tomcat-5.5.16 /usr/lib
4. Next change to the /usr/lib/ directory.
cd /usr/lib
5. Now create a symbolic link called apache-tomcat to the CATALINA_HOME by the following command.
ln -s apache-tomcat-5.5.16 apache-tomcat
This will save you from having to make changes to startup and
shutdown scripts each time you upgrade Tomcat and if you so desire, it
also allows you to keep several versions of Tomcat on your system and
easily switch amongst them.
You should now be able to start and stop Tomcat from the CATALINA_HOME/bin
directory. If you are using another shell other than the bash shell you
will nee to add sh to the beginning of the command. You should now be
able to test that Tomcat is installed by starting it and opening your
browser and entering http://localhost:8080 into your browser. Port 8080 is the default port for Tomcat and can be easily changed in the /usr/lib/apache-tomcat/conf/server.xml
file. (We will work with this file later on.) If you plan to access
this page remotely, be sure to forward the respective port to your
server’s IP address within your router. You should now see the Tomcat
welcome page that contains links to Tomcat documentation as well as
sample JSP/Servlet scripts. Verify that Tomcat is running by executing
some of the examples found on the welcome page.
cd /usr/lib/apache-tomcat/bin
To shutdown the server, you will need to execute the following
command. Feel free to try it, but for now we will leave Tomcat running.

Installing and configuring mod_jk
In order to make the connection between Tomcat and Apache, we will
need to download and install mod_jk connector. You will find that the
Apache documentation recommends that you install the packaged version
of mod_jk if it is available for your particular Linux distribution.
Many outdated resources recommend installing the mod_jk2 connector, but
I have found that it has been deprecated and although mod_jk was
developed before mod_jk2, it is still fully supported and is very
Mike Millson gave some good reasoning behind using mod_jk for connecting Tomcat to Apache for Red Hat here:
Integrating Tomcat and Apache on Red Hat Linux
1. I chose to download the current source from the Apache archives:
. Download the jakarta-tomcat-connectors-1.2.15-src.tar.gz file to your /usr/src/ directory.
2. Change to the /usr/src directory.
cd /usr/src
3. Next, extract the contents to create the /usr/src/jakarta-tomcat-connectors-1.2.15-src directory.
tar xvzf jakarta-tomcat-connectors-1.2.15-src.tar.gz
4. Change to the /usr/src/jakarta-tomcat-connectors-1.2.15-src/jk/native directory.
cd jakarta-tomcat-connectors-1.2.15-src/jk/native
5. Now you are ready to create the custom configure file for your system. Execute the following:
This will create a configure file in the /usr/src/jakarta-tomcat-connectors-1.2.15-src/jk/native directory.
6. Execute the following command in order to configure mod_jk for your system.
  Important note: You will need to have apxs2
(APache eXtension tool) installed and configured with Apache. If you do
not have it, as was my case, you can download and install the apache2-threaded-dev package (which replaced the former apache-dev package) from
. At the time of this writing, the Debian package archive at
was down and they referred me to their temporary site until they resolved their issues
. I found the apache2-threaded-dev package and was able to install it successfully.
Be sure to include the correct location apxs2 on your system in the path of the command.
./configure –with-apxs=/usr/bin/apxs2
7. Now build the mod_jk with the following:
8. Finally, if you were successful with the previous commands, copy the newly created mod_jk.so to your Apache2 modules directory. My modules were located at /usr/lib/apache2/modules.
cd apache-2.0
cp /usr/src/jakarta-tomcat-connectors-1.2.15-src/jk/native/apache-2.0/mod_jk.so /usr/lib/apache2/modules
You now are ready to move to the next stage which is to begin
configuring Apache and Tomcat. You can find more information about the
mod_jk connector at

Configuring Tomcat and Apache
Create the workers.properties file.
  Important note: Be sure to make a backup copy of your config files before modifying.
The workers.properties
file contains the details about how each process is linked to Tomcat by
defining workers that communicate through the ajpv13 protocol. Refer to
the Workers HowTo for more detail.
1. First create the workers.properties file in your Apache2 root directory.
touch /etc/apache2/workers.properties
2. Next, open the workers.properties file and add the following. You can find many other examples of the workers.properties
file on the internet, but this is the one that I created and it seems
to work fine with the other portions that have already been configured
in this tutorial.
3. Save and close the file.
4. Now we need to open the /etc/apache2/apache2.conf file and add the following lines at the bottom. (httpd.conf is just for backward compatibility):
      LoadModule jk_module /usr/lib/apache2/modules/mod_jk.so
# Where to find workers.properties
JkWorkersFile /etc/apache2/workers.properties
# Where to put jk logs
JkLogFile /var/log/apache2/mod_jk.log
# Set the jk log level [debug/error/info]
JkLogLevel info
# Select the log format
JkLogStampFormat “[%a %b %d %H:%M:%S %Y] “
# JkOptions indicate to send SSL KEY SIZE,
JkOptions +ForwardKeySize +ForwardURICompat -ForwardDirectories
# JkRequestLogFormat set the request format
JkRequestLogFormat “%w %V %T”
# Send servlet for context / jsp-examples to worker named worker1
JkMount /jsp-examples worker1
# Send JSPs for context /jsp-examples/* to worker named worker1
JkMount /jsp-examples/* worker1
Save and close the file.
Now a final security point.
We will create a group and user tomcat tomcat like that:
groupadd tomcat
useradd -g tomcat tomcat
Then change the user and group of the Tomcat path:
chown -R tomcat:tomcat /usr/lib/apache-tomcat-5.5.16
To change the password of tomcat user, with root type:
passwd tomcat
and follow the instructions.
Then to start and stop the Tomcat server you should use the tomcat user.
su – tomcat
Now stop and start Tomcat:
cd /usr/lib/apache-tomcat/bin
And restart Apache:
/etc/init.d/apache2 restart
You are done.

In this test, we are directing all URLs that begin with “/jsp-examples” to Tomcat.
In a real world situation, we might only direct JSPs or servlets to the JK worker.   
Make sure no other server is running on the default Tomcat ports of 8005, 8009 and 8080.
Make sure no other server is running on the Apache port, which is normally 8080 or 80.
Start Tomcat first: Always start Tomcat first and then start Apache.
If you have to bounce Tomcat, remember to take down Apache first and restart it after Tomcat restarts.
Start Apache: Point your browser to http://localhost and verify that you get the default Apache page. Substitute “localhost” for the actual machine name/IP if necessary.
Point your browser to http://localhost:8080 and verify that you get the default Tomcat page.
Point your browser to http://localhost/jsp-examples/ and verify that you get the index page for the Tomcat examples.
This will be served by Apache and will indicate that you have completed your integration of Apache and Tomcat successfully.

References and paths:
Tomcat conf:
Tomcat stop and start:
cd /usr/lib/apache-tomcat/bin
Apache modules:
Apache conf:

CentOS 5.4 下 VMWare server 2.0 崩溃[转载]

在CentOS 5.4上,按照官方的安装说明安装后,可以启动,但是启动后及分钟或几十分钟不等的事件后VMWare server就会崩溃,后来在google上搜索,发现是是CentOS的glibc库和VMWare server 2.0不兼容所致。

CentOS 5.4的gilibc版本为:2.5-42,需要降级到2.5-34,具体的方法如下:



2,下载与机器架构匹配的jlibc的rpm包(machine architecture为i686,如果为X64请下载相应的rpm包)

mkdir ~/vmwareglibc
cd ~/vmwareglibc
wget http://mirror.centos.org/centos/5.3/os/i386/CentOS/glibc-2.5-34.i686.rpm
rpm2cpio glibc-2.5-34.i686.rpm | cpio -ivd
mkdir /usr/lib/vmware/lib/libc.so.6
mv lib/libc-2.5.so /usr/lib/vmware/lib/libc.so.6/libc.so.6 (此次小心,最好用cp)
3,编辑VMware hostd 配置文件,在倒数第二行追加Lib path

vi /usr/sbin/vmware-hostd

export LD_LIBRARY_PATH=/usr/lib/vmware/lib/libc.so.6:$LD_LIBRARY_PATH


if [ ! “@@VMWARE_NO_MALLOC_CHECK@@” = 1 ]; then
export MALLOC_CHECK_=2
export LD_LIBRARY_PATH=/usr/lib/vmware/lib/libc.so.6:$LD_LIBRARY_PATH
eval exec “$DEBUG_CMD” “$binary” “$@”4,重新启动VMWare server,然后在vmware 的log文件中能看到上面的glibc的库被载入,而不是CentOS5.4系统的glibc。


00716000-00854000 r-xp 00000000 fd:00 3082802 /usr/lib/vmware/lib/libc.so.6/libc.so.6
00854000-00856000 r-xp 0013e000 fd:00 3082802 /usr/lib/vmware/lib/libc.so.6/libc.so.6
00856000-00857000 rwxp 00140000 fd:00 3082802 /usr/lib/vmware/lib/libc.so.6/libc.so.6


Step 1: Install the latest 2.0.2 VMware Server package and run the configuration. It will crash, but just ignore this for now.

Step 2: Run the following command, and make note of the response.

Step 3: Run the following commands, and replace any instance of {ARCH} with the result of Step 2:

mkdir ~/vmwareglibc
cd ~/vmwareglibc
wget http://mirror.centos.org/centos/5.3/os/{ARCH}/CentOS/glibc-2.5-34.{ARCH}.rpm
rpm2cpio glibc-2.5-34.{ARCH}.rpm | cpio -ivd
mkdir /usr/lib/vmware/lib/libc.so.6
mv lib64/libc-2.5.so /usr/lib/vmware/lib/libc.so.6/libc.so.6(此次小心,最好用cp)
Step 4: Open the VMware hostd process script for editing.

vim /usr/sbin/vmware-hostdStep 5: At line 372, before the program is called, insert two empty lines and add the following:

export LD_LIBRARY_PATH=/usr/lib/vmware/lib/libc.so.6:$LD_LIBRARY_PATHBefore Example:

if [ ! “@@VMWARE_NO_MALLOC_CHECK@@” = 1 ]; then
export MALLOC_CHECK_=2

eval exec “$DEBUG_CMD” “$binary” “$@”
After Example:

if [ ! “@@VMWARE_NO_MALLOC_CHECK@@” = 1 ]; then
export MALLOC_CHECK_=2

export LD_LIBRARY_PATH=/usr/lib/vmware/lib/libc.so.6:$LD_LIBRARY_PATH

eval exec “$DEBUG_CMD” “$binary” “$@”
NOTE: In Step 3, the wget command may in the future be this as 5.3 repositories are taken off of the main CentOS Mirrors:

wget http://vault.centos.org/5.3/os/{ARCH}/CentOS/glibc-2.5-34.{ARCH}.rpm