我的運(yùn)行環(huán)境:Windows2003?Server?SP4?+?J2SDK1.5.0?+?Apache2.0.54?+?Tomcat5.5.9
??**準(zhǔn)備軟件:
??1、Apache?2.0.54???
??2、Tomcat?5.5.14?
??3、Jk2連接器(mod_jk2.so)
一:軟件的部署和配置計(jì)劃:(修改server.xml)
Configuration?Parameter????Instance?1????Instance?2????Instance?3
Instance?Type??????????????Load?Balancer????Cluster?Node?1????Cluster?Node?2
Node?name??????????????????????AP-LB?????????????TC01??????????????TC02
Node?IP???????????????????????192.168.0.12????192.168.0.12????192.168.0.12
Home?Directory?????????????D:/apache2????D:/tomcat51????D:/tomcat52
Server?Ports??????????????????????????8005??????????????9005
AJP?Connector?Ports?????????????????8009??????????????8011
Coyote/JK2?AJP?Connector?????????????????8080??????????????9080
Cluster?mcastAddr??????????????????????????228.0.0.4??????????????228.0.0.4
Cluster?mcastPort??????????????????????????45564??????????????45564
tcpListenAddress??????????????????????????192.168.0.12????192.168.0.12
Cluster?tcpListenPort?????????????????4000?????????????4001
Route???????????????????????????????????Tomcat51?????????????Tomcat52
軟件的安裝步驟如下:
1、????首先按照J(rèn)DK1.5.0
2、????安裝Apache?,按照完成后啟動(dòng)Apache,使用IE訪問
http://localhost?測(cè)試Apache運(yùn)行是否正常。
3、????在192.168.0.12上安裝tomcat,安裝完成后,啟動(dòng)tomcat,使用IE訪問
http://localhost:8080?,測(cè)試tomcat運(yùn)行是否正常。
4、????編寫一個(gè)jsp文件(sessiontest.jsp)把testsession.jsp放到webapps/jsp-examplse;,將tomcat51拷貝到的d:/下,修改名字tomcat52;
在tomcat51中的testsession.jsp有提示信息Index?Page?Served?By?tocmat51,在tomcat52的testsession.jsp有提示信息Index?Page?Served?By?tomcat52
4、在tc01和tc02bin下編輯startup.bat,分別添加
set?CATALINA_HOME=D:\tomcat51和set?CATALINA_HOME=D:\tomcat52
5、????注釋掉tc01和tc02中server.xml的
???<!--?Define?the?top?level?container?in?our?container?hierarchy
<Engine?name=”Catalina”?defaultHost=”localhost”?debug=”0”>
-->
和把下面的注釋去掉
<Engine?name="Standalone"?defaultHost="localhost"?jvmRoute="tomcat51">
TC02的jvmRoute="tomcat52"
6、????在TC01的jk2.properties添加:
#?Sample?jk2.properties?file?for?Tomcat5A
channelSocket.address=192.168.0.12
channelSocket.port=8009
shm.file=D:/Apache2/conf/jk2.shm
TC02的channelSocket.port=8011
7、將mod_jk2.so復(fù)制到d:\Apache2\modules目錄下:
??1.編輯d:\Apache2\conf\httpd.conf文件,在LoadModule那一段代碼中添加:
??LoadModule?jk2_module?modules/mod_jk2.so
8、將AddDefaultCharset?ISO-8859-1?改為?AddDefaultCharset?GB2312?使Apache自動(dòng)支持中文顯示;
9、在“虛擬主機(jī)配置代碼段”中添加:(此段配置可以根據(jù)你的實(shí)際情況進(jìn)行修改)
??<VirtualHost?*:80>
????ServerAdmin?linvsfen◎163.com
????DocumentRoot?"d:/?Tomcat51/webapps/jsp-examples
????ServerName?localhost
????ErrorLog?logs/error_log
????CustomLog?logs/access_log?common
??</VirtualHost>
10、建立并配置Apache2/conf/?workers2.properties,如下:
??????#?Usually?commented?out?on?production?environments
[logger.apache2]
file=”D:/Apache2/logs/error.log”
level=ERROR
#?Provide?the?basic?config?needed
[config]
file=D:/Apache2/conf/workers2.properties
debug=1
#?Provide?the?location?of?shm?file?on?the?Apache?web?server
[shm]
file=D:/Apache2/conf/jk2.shm
size=1000000
#?Tomcat51
[channel.socket:192.168.0.12:8009]
host=192.168.0.12
port=8009
tomcatId=tomcat51
group=balanced
lb_factor=1
route=tomcat51
#?Tomcat5A?worker
[ajp13:192.168.0.12:8009]
channel=channel.socket:tomcat51
#?Tomcat52
[channel.socket:192.168.0.12:8011]
host=192.168.0.12
port=8011
tomcatId=tomcat52
group=balanced
lb_factor=1
route=tomcat52
#?Tomcat52?worker
[ajp13:192.168.0.12:8011]
channel=channel.socket:tomcat52
#?Load?balanced?worker
[lb:balanced]
worker=ajp13:192.168.0.12:8009
worker=ajp13:192.168.0.12:8011
timeout=30
attempts=2
recovery=90
stickySession=1
noWorkersMsg=Server?Busy?please?retry?after?some?time.
noWorkerCodeMsg=503
#?URI?mapping
[uri:/jsp-examples/*]
info=Mappings?for?the?Tomcat?context?jsp-examples
context=/jsp-examples
group=balanced
#?Define?a?status?worker?to?test?the?run-time?request?behavior?to?the?all?workers
[status:]
#?Status?URI?mapping
[uri:/jkstatus/*]
group=status
11、啟動(dòng)Apache和同時(shí)啟動(dòng)tomcat服務(wù)。
二.測(cè)試集群功能
1、訪問
http://localhost/jsp-examples/sessiontest.jsp,?Apache將請(qǐng)求發(fā)給TC01,返回結(jié)果,頁面顯示信息tomcat51。URL不變
2、再打開一個(gè)IE窗口,訪問
http://192.168.0.12/jsp-examples/sessiontest.jspApache將請(qǐng)求發(fā)給TC02,返回結(jié)果。頁面有信息:tomcat52,URL不變