Apache+Tomcat负载均衡(二):mod_jk

所有博文均在个人独立博客http://blog.mozhu.org首发,欢迎访问!

环境准备

Apache版本:2.4.18
下载地址:http://httpd.apache.org/download.cgi
下载mod_jk相关包
http://apache.fayea.com/tomcat/tomcat-connectors/jk/binaries/windows/

apache tomcat connector下载

注意:mod_jk必须和apache版本一致,本文因为采用的是apache2.4,操作系统是64位的,所以下载下面的版本
http://apache.fayea.com/tomcat/tomcat-connectors/jk/binaries/windows/tomcat-connectors-1.2.40-windows-x86_64-httpd-2.4.x.zip

Tomcat版本:6.0.44
下载地址:
http://tomcat.apache.org/download-60.cgi

JDK:1.6
OS:Windows 7 x64

部署WebDemo到三台Tomcat中,并启动,可以参考
Apache+Tomcat负载均衡(一):mod_proxy

将mod_jk.so文件放于/modules中,并修改/conf/httpd.conf
添加一行

1
Include conf/jk.conf

如果配置了mod_proxy,请注释掉防止冲突或干扰

#Include conf/extra/httpd-proxy.conf

/conf目录下建立文件jk.conf,其内容如下:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
##
## Configuration for JK
##

# Load mod_jk module
# Update this path to match your modules location
LoadModule jk_module modules/mod_jk.so
# Where to find workers.properties
# Update this path to match your conf directory location (put workers.properties next to httpd.conf)
JkWorkersFile conf/workers.properties
# Where to put jk shared memory
# Update this path to match your local state directory or logs directory
JkShmFile logs/mod_jk.shm
#This directive is only allowed inside VirtualHost (with value "On") and in the global server (with value "All")
#The default is Off, so no mounts will be inherited from the global server to any VirtualHost
JkMountCopy All
#This directive can be used multiple times per virtual server.
#The default value is "ForwardURIProxy" since version 1.2.24. It was "ForwardURICompatUnparsed" in version 1.2.23 and "ForwardURICompat" until version 1.2.22
JkOptions +ForwardURIProxy
# Where to put jk logs
# Update this path to match your logs directory location (put mod_jk.log next to access_log)
JkLogFile logs/mod_jk.log
# Set the jk log level [debug/error/info]
JkLogLevel info
# Select the timestamp log format
JkLogStampFormat "[%a %b %d %H:%M:%S %Y] "

# unmount option
#JkUnMount /*.jpg lb_worker
#JkUnMount /*.gif lb_worker
#JkUnMount /*.png lb_worker
#JkUnMount /*.htm lb_worker

<Location /djkstatus/>
JkMount jkstatus
Require all granted
</Location>

JkMount /WebDemo/* lb_worker

/conf目录下建立文件workers.properties,其内容如下:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
#
# The workers that jk should create and work with
#
worker.list=lb_worker,jkstatus,worker1,worker2,worker3
worker.lb_worker.type=lb
worker.lb_worker.balance_workers=worker1,worker2,worker3
#worker1
worker.worker1.type=ajp13
worker.worker1.host=127.0.0.1
worker.worker1.port=8019
worker.worker1.lbfactor=10

#worker2
worker.worker2.type=ajp13
worker.worker2.host=127.0.0.1
worker.worker2.port=8029
worker.worker2.lbfactor=10

#worker3
worker.worker3.type=ajp13
worker.worker3.host=127.0.0.1
worker.worker3.port=8039
worker.worker3.lbfactor=10

worker.jkstatus.type=status
worker.jkstatus.mount=/djkstatus

打开浏览器访问:
http://localhost/WebDemo/index.jsp
不断刷新,可以看到
Current Server: 1
不断从1-3变化,则表明,负载均衡配置成功

打开jkstatus集群管理页面:
http://localhost/djkstatus

djkstatus

分享到