Win2k下Jboss、Tomcat和Apache的集成 <?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

本文介绍在Win2k环境下,用modjk1.2.x集成Jboss、Tomcat和Apache;文章最后用一jsp文件测试了该集成环境。 

1.1 主要步骤 

① 下载集成Tomcat的Jboss、Apache和modjk1.2.x。 

② 修改Apache中的配置文件httpd.conf。 

③ 在Apache中创建新文件workers.properties。 

④ 在Apache中创建新文件uriworkermap.properties。 

⑤ 重新启动Apache。 

⑥ 修改Jboss中的server.xml和jboss-service.xml文件。 

⑦ 启动Jboss Application Server。 

1.2 详细说明 

1.2.1 软件的下载和安装 

本文所用的软件版本为:j2sdk1.4、Jboss3.2.7、Apache2.0和mod_jk-1.2.14。jdk的下载,安装和配置本文不再多说,用过java语言的人肯定都知道。 

① 集成Tomcat的Jboss的下载 

从[url]http://www.jboss.com/downloads/index[/url]下载Jboss。将Jboss安装到c:\javaApp目录下。 

② Apache的下载 

从[url]http://httpd.apache.org/[/url]下载Apache2.0。将Apache安装到c:\javaApp目录下。 

③ modjk的下载 

从[url]http://www.apache.org/dist/jakarta/tomcat-connectors/jk/binaries/win32/ [/url]

下载mod_jk。把mod_jk-1.2.x.so文件拷贝到Apache2\modules目录下。 

1.2.2 httpd.conf文件的修改 

打开 Apache2$HOME\conf\httpd.conf 文件,找到其中的LoadModule,然后在LoadModule的最后一行,加上下面的代码: 

# Load mod_jk module 

# Specify the filename of the mod_jk lib 

LoadModule jk_module modules/mod_jk-1.2.14.so 

再在httpd.conf文件的最后,加上下面的代码: 

# Where to find workers.properties 

JKWorkersFile conf/workers2.properties 

# Where to put jk logs 

JKLogFile logs/mod_jk.log 

# Set the jk log level [debug/error/info] 

JKLogLevel normal 

# Select the log format 

JkLogStampFormat "[%a %b %d %H:%M:%S %Y]" 

# JkOptions indicates to send SSK KEY SIZE 

#JkOptions+ForwardKeySize+ForwardURICompat-ForwardDirectories 

# JkRequestLogFormat 

JkRequestLogFormat "%w %V %T" 

# Mount your applications 

JKMount /web_application/* node1 

JkMount /web-console/* node1 

JkMount /jmx-console/* node1 

# You can use external file for mount points. 

# It will be checked for updates each 60 seconds. 

# The format of the file is: /url=worker 

# /examples/*=loadbalancer 

JkMountFile conf/uriworkermap.properties 

# Add shared memory. 

# This directive is present with 1.2.10 and 

# later versions of mod_jk, and is needed for 

# for load balancing to work properly 

# If there’s no this file under logs directory, create it manually. 

JkShmFile logs/jk.shm 

# Add jkstatus for managing runtime data 

<Location /jkstatus/> 

JkMount status 

Order deny,allow 

Deny from all 

Allow from 127.0.0.1 

</Location> 

1.2.3 创建 workers.properties 文件 

在Apache2\conf目录下创建一新文件workers.properties,文件包含下面的内容: 

# Define list of workers that will be used 

# for mapping requests 

worker.list=loadbalancer,status 

# Define Node1 

worker.node1.port=8009 

# You can modify the Ip address to the actual Ip address 

worker.node1.host=127.0.0.1 

worker.node1.type=ajp13 

worker.node1.lbfactor=1 

#worker.node1.local_worker=1 (1) 

worker.node1.cachesize=10 

# Define Node2 

worker.node2.port=8009 

# You can modify the Ip address to the actual Ip address 

worker.node2.host= 127.0.0.1 

worker.node2.type=ajp13 

worker.node2.lbfactor=1 

#worker.node2.local_worker=1 (1) 

worker.node2.cachesize=10 

# Load-balancing behavior 

worker.loadbalancer.type=lb 

worker.loadbalancer.balance_workers=node1, node2 

worker.loadbalancer.sticky_session=1 

worker.loadbalancer.local_worker_only=1 

worker.list=loadbalancer 

# Status worker for managing load balancer 

worker.status.type=status 

1.2.4 创建 uriworkermap.properties 文件 

在Apache2\conf目录下创建一新文件uriworkermap.properties,文件包含下面的内容: 

# Simple worker configuration file 

# Mount the Servlet context to the ajp13 worker 

/jmx-console=loadbalancer 

/jmx-console/*=loadbalancer 

/web-console=loadbalancer 

/web-console/*=loadbalancer 

# You should modify the “web_application” to 

# the real name of the web application 

/ web_application =loadbalancer 

/ web_application /*=loadbalancer 

做完上面的所有步骤后,重新启动Apache。 

1.2.5 修改Jboss中的server.xml和jboss-service.xml文件 

打开 jboss-3.2.7\server\default\deploy\jbossweb-tomcat50.sar 目录下的server.xml文件。 

把<Engine name="jboss.web" defaultHost="localhost">修改为: 

<Engine name="jboss.web" defaultHost="localhost" 

jvmRoute="node1"> 

因为集成Apache后,由Apache来处理Http请求,所以可以把下面的代码注释掉: 

<Connector port="8080" address="${jboss.bind.address}" 

maxThreads="150" minSpareThreads="25" maxSpareThreads="75" 

enableLookups="false" redirectPort="8443" acceptCount="100" 

connectionTimeout="20000" disableUploadTimeout="true"/> 

打开 jboss-3.2.7\server\default\deploy\jbossweb-tomcat50.sar\ 

META-INF目录下的jboss-service.xml文件。 

把<attribute name="UseJK">false</attribute>修改为: 

<attribute name="UseJK">true</attribute> 

启动Jboss,在IE浏览器中输入[url]http://127.0.0.1/web-console[/url],如果配置成功,将显示Jboss的web管理页面。 

1.3 测试jsp文件 

在jboss-3.2.7\server\default\deploy目录下新建一个helloworld目录,然后在helloworld目录下新建一个hello.war目录。在hello.war目录下创建一个test.jsp文件,文件代码如下: 

<HEAD> 

<TITLE>test.jsp</TITLE> 

</HEAD> 

<BODY topMargin=0 marginheight="0"> 

<DIV align=center> 

<% 

String helloworld = "Hello world!"; 

out.println(helloworld); 

%> 

</DIV> 

</BODY> 

</HTML> 

修改uriworkermap.properties文件,添加下面的代码: 

/hello=loadbalancer 

/hello/*=loadbalancer 

修改httpd.conf文件,添加下面的代码: 

JKMount /hello/* node1 

打开IE,输入[url]http://127.0.0.1/hello/test.jsp[/url],页面将显示出 

Hello world!