<1>软硬件环境
Apache Http Server 2.2.4
Tomcat 5.028
jdk1.6
请自行下载jk_module.so,但注意必须与apache http server的版本对应。
硬件我手头有一台IBM服务器,有三台刀片机可用,IP分别是
S1:192.168.70.101
S2:192.168.70.102
S3:192.168.70.103
当然这三台机器您完全可以用三个一般的台式机来代替.
我们的计划是
用S1来做应用服务器,用S2来做负载均衡,用S3来做数据库服务器.
<2>在S1,S2下安装jdk1.6
例如我安装在c:\jdk1.6下
添加环境变量:
JAVA_HOME=C:\jdk1.6
CLASSPATH=%JAVA_HOME%\lib\tools.jar;%JAVA_HOME%\lib\dt.jar
在PATH前面加:
PATH=%JAVA_HOME%\bin;
<3>在S1下安装apache,没有什么值得注意的地方,一路按next就可以了
我安装在D:\Apache2.2
<4>在S1,S2下安装tomcat 5.028
也是一路按next就可以了,我安装在d:\tomcat5.0
以上对于一个java开发人员来说应该都不是问题,接下来就是重头戏了!
<5>配置
5.1 把下载的mod_jk-1.2.26-httpd-2.2.4.so拷贝到S1机器的D:\Apache2.2\modules目录下,并改名为mod_jk.so
5.2 打开S1机器的D:\Apache2.2\conf\http.conf文件,在一堆LoadModule的最后加上这么一行
LoadModule jk_module modules/mod_jk.so
5.3 在D:\Apache2.2\conf\http.conf的最后加上对jk_module的配置
#与tomcat关联
<IfModule jk_module>
JkWorkersFile conf/workers.properties
JkMountFile conf/uriworkermap.properties
JkLogFile logs/mod_jk.log
JkLogLevel warn
</IfModule>
<IfModule dir_module>
DirectoryIndex index.html,index.jsp,index.htm
</IfModule>
#结束与tomcat关联
#添加虚拟主机,注意S1上apache网页文件目录和tomcat网页文件目录要指向同一个目录,否则静态页面会无法访问
<VirtualHost *:80>
ServerName www.map512.cn
DocumentRoot D:/Tomcat5.0/webapps
ServerAdmin support.szmap@gmail.com
JkMountFile conf/uriworkermap.properties
</VirtualHost>
#给虚拟主机目录付权限
<Directory D:/Tomcat5.0/webapps>
Options Indexes FollowSymLinks
AllowOverride None
Order allow,deny
Allow from all
</Directory>
#默认访问
<IfModule dir_module>
DirectoryIndex index.html,index.jsp
</IfModule>
5.4 在D:\Apache2.2\conf\http.conf目录下新建一个文件workers.properties,并添加以下内容
#
# workers.properties
#
# list the workers by name
worker.list=SZMAP, status
# localhost server 1
# ------------------------
worker.s1.port=8009
worker.s1.host=192.168.70.101
worker.s1.type=ajp13
# localhost server 2
# ------------------------
worker.s2.port=8009
worker.s2.host=192.168.70.102
worker.s2.type=ajp13
# worker.s2.stopped=1
worker.SZMAP.type=lb
worker.retries=3
worker.SZMAP.balance_workers=s1, s2
worker.SZMAP.sticky_session=1
worker.status.type=status
说明:这个文件配置了两个worker,一个是SZMAP即我们的应用服务,这个应用服务type是lb即负载均衡,并由s1和s2两个balanced_workers来执行,这里你可以添加无限多个服务器来实现负载(当然,前提是您有足够的RMB),一个是status是用来查看负载均衡状态的,我们后面将会用到.
5.6 在D:\Apache2.2\conf\http.conf目录下新建一个文件uriworkermap.properties,并添加以下内容
/*=SZMAP
/jkstatus=status #设置除以下类型的文件外,都由tomcat提供服务(也就是说下面列出的格式都有apache提供服务)
!/*.gif=SZMAP
!/*.jpg=SZMAP
!/*.png=SZMAP
!/*.css=SZMAP
!/*.js=SZMAP
!/*.html=SZMAP
说明:这个配置的意思是,所有的请求都转到SZMAP这个worker(即上面配置的s1,s2这两个balanced_workers下的tomcat服务)去执行,除了*.gif,*.html等静态元素和/jkstatus,/jkstatus由status这个worker执行.
5.7 Tomcat的配置
打开S1机器D:\Tomcat5.0\conf\server.xml,找到Engine部分,改成
<Engine defaultHost="localhost" name="Catalina" jvmRoute="s1">
<Host appBase="webapps" name="localhost">
<Cluster className="org.apache.catalina.cluster.tcp.SimpleTcpCluster"
managerClassName="org.apache.catalina.cluster.session.DeltaManager"
expireSessionsOnShutdown="false"
useDirtyFlag="true">
<Membership
className="org.apache.catalina.cluster.mcast.McastService"
mcastAddr="228.0.0.4"
mcastPort="45564"
mcastFrequency="500"
mcastDropTime="3000"/>
<Receiver
className="org.apache.catalina.cluster.tcp.ReplicationListener"
tcpListenAddress="auto"
tcpListenPort="4001"
tcpSelectorTimeout="100"
tcpThreadCount="6"/>
<Sender
className="org.apache.catalina.cluster.tcp.ReplicationTransmitter"
replicationMode="pooled"/>
<Valve className="org.apache.catalina.cluster.tcp.ReplicationValve"
filter=".*\.gif;.*\.js;.*\.jpg;.*\.html;.*\.txt;"/>
</Cluster>
<Logger className="org.apache.catalina.logger.FileLogger" prefix="localhost_log." suffix=".txt" timestamp="true"/>
</Host>
<Logger className="org.apache.catalina.logger.FileLogger" prefix="catalina_log." suffix=".txt" timestamp="true"/>
<Realm className="org.apache.catalina.realm.UserDatabaseRealm"/>
</Engine>
打开S2机器D:\Tomcat5.0\conf\server.xml,找到Engine部分,改成
<Engine defaultHost="localhost" name="Catalina" jvmRoute="s2">
<Host appBase="webapps" name="localhost">
<Cluster className="org.apache.catalina.cluster.tcp.SimpleTcpCluster"
managerClassName="org.apache.catalina.cluster.session.DeltaManager"
expireSessionsOnShutdown="false"
useDirtyFlag="true">
<Membership
className="org.apache.catalina.cluster.mcast.McastService"
mcastAddr="228.0.0.4"
mcastPort="45564"
mcastFrequency="500"
mcastDropTime="3000"/>
<Receiver
className="org.apache.catalina.cluster.tcp.ReplicationListener"
tcpListenAddress="auto"
tcpListenPort="4001"
tcpSelectorTimeout="100"
tcpThreadCount="6"/>
<Sender
className="org.apache.catalina.cluster.tcp.ReplicationTransmitter"
replicationMode="pooled"/>
<Valve className="org.apache.catalina.cluster.tcp.ReplicationValve"
filter=".*\.gif;.*\.js;.*\.jpg;.*\.html;.*\.txt;"/>
</Cluster>
<Logger className="org.apache.catalina.logger.FileLogger" prefix="localhost_log." suffix=".txt" timestamp="true"/>
</Host>
<Logger className="org.apache.catalina.logger.FileLogger" prefix="catalina_log." suffix=".txt" timestamp="true"/>
<Realm className="org.apache.catalina.realm.UserDatabaseRealm"/>
</Engine>
到此,我们的配置已经完成.
<6>查看结果
启动S1和S2下的tomcat服务,然后启动S1下的apache服务.
打开流览器,输入地址http://192.168.70.101/jkstatus,如果能看到以下界面,那么,恭喜您,您该感谢我了!呵呵!
JK Status Manager for 192.168.70.101:80
Server Version: |
Apache/2.2.4 (Win32) mod_jk/1.2.26 |
JK Version: |
mod_jk/1.2.26 |
[Change Format:
XML |
Property |
Text] [
Read Only] [
S=Show only this worker,
E=Edit worker,
R=Reset worker state,
T=Try worker recovery]
Listing Load Balancing Worker (1 Worker) [Hide]
[S|E|R] Worker Status for SZMAP
Type |
Sticky Sessions |
Force Sticky Sessions |
Retries |
LB Method |
Locking |
Recover Wait Time |
Max Reply Timeouts |
lb |
True |
False |
2 |
Request |
Optimistic |
60 |
0 |
Good |
Degraded |
Bad/Stopped |
Busy |
Max Busy |
Next Maintenance |
2 |
0 |
0 |
0 |
6 |
32/94 |
Balancer Members [Hide]
|
Name |
Type |
Host |
Addr |
Act |
State |
D |
F |
M |
V |
Acc |
Err |
CE |
RE |
Wr |
Rd |
Busy |
Max |
Route |
RR |
Cd |
Rs |
[E|R] |
s1 |
ajp13 |
192.168.70.101:8009 |
192.168.70.101:8009 |
ACT |
OK/IDLE |
0 |
1 |
1 |
0 |
1821 |
0 |
0 |
0 |
1.3M |
2.0M |
0 |
5 |
s1 |
|
|
0/0 |
[E|R] |
s2 |
ajp13 |
192.168.70.102:8009 |
192.168.70.102:8009 |
ACT |
OK/IDLE |
0 |
1 |
1 |
0 |
1821 |
0 |
0 |
0 |
1.3M |
2.0M |
0 |
4 |
s2 |
|
|
0/0 |
Edit one attribute for all members: [
Activation |
LB Factor |
Route |
Redirect Route |
Cluster Domain |
Distance ]
参考:
proxy方式
:http://blog.chinaunix.net/u/22176/showart_1002535.html
liunx下
的配置:http://seven.blog.51cto.com/120537/57930