操作步骤:
1、分别安装httpd-v2.2.18-win32-x86和2个apache-tomcat-6.0.20(分别改名为tomcat1和tomcat2)
2、修改Apache的conf目录下httpd.conf加入一句:include conf/mod_jk.conf
3、在conf目录下新建mod_jk.conf文件,内容如下:
#加载mod_jk Module(用于Apache和tomcat通信的桥梁)
LoadModule jk_module modules/mod_jk-1.2.26-httpd-2.2.4.so
#指定 workers.properties文件路径(配置负载均衡用,下详)
JkWorkersFile conf/workers.properties
JkMount /*.htm controller (配置路径跳转,指将那些请求发给tomcat)
JkMount /*.jsp controller
4、在conf目录下新建workers.properties文件,内容如下:
worker.list = controller,tomcat1,tomcat2 #server 列表
#========tomcat1========
worker.tomcat1.port=8009 #ajp13 端口号,在tomcat下server.xml配置,默认8009
worker.tomcat1.host=127.0.0.1 #tomcat的主机地址,如不为本机,请填写ip地址
worker.tomcat1.type=ajp13
worker.tomcat1.lbfactor = 1 #server的加权比重,值越高,分得的请求越多
#========tomcat2========
worker.tomcat2.port=9009 #ajp13 端口号,在tomcat下server.xml配置,默认8009
worker.tomcat2.host=127.0.0.1 #tomcat的主机地址,如不为本机,请填写ip地址
worker.tomcat2.type=ajp13
worker.tomcat2.lbfactor = 1 #server的加权比重,值越高,分得的请求越多
#========controller,负载均衡控制器========
worker.controller.type=lb
worker.controller.balanced_workers=tomcat1,tomcat2 #指定分担请求的tomcat
worker.controller.sticky_session=1
5、修改tomcat1的server.xml中shutdown端口、http连接端口、以及ajp端口(注意:ajp端口需和workers.properties中tomcat1的端口一致)
6、修改tomcat2的server.xml中shutdown端口、http连接端口、以及ajp端口(注意:ajp端口需和workers.properties中tomcat2的端口一致)
2tomcat的server.xml的
<Cluster className="org.apache.catalina.ha.tcp.SimpleTcpCluster"/>
将注释去掉
7、此时Apache整合2tomcat集群和session复制环境配置成功
8、若需要配置在外网服务器需配置域名操作如下:
a、修改Apache的httpd.conf文件将此语句注释去掉#Include conf/extra/httpd-vhosts.conf(此文件为开启Apache域名配置)
b、修改httpd-vhosts.conf文件,添加域名配置信息,内容如下:
NameVirtualHost *:80
<VirtualHost *:80>
ServerName dachuanwang.com
ServerAlias www.dachuanwang.com
ServerAdmin dachuaneb@gmail.com
DocumentRoot "E:\service\tomcat1\webapps\e_business"
<Directory "E:\service\tomcat1\webapps\e_business">
Options Indexes FollowSymLinks
AllowOverride None
Order allow,deny
Allow from all
</Directory>
JkMount /*.* controller
</VirtualHost>
若出现少级路径等情况则将*换成IP
c、修改tomcat1和tomcat2的server.xml文件,配置域名,内容如下:
<Engine name="Catalina" defaultHost="www.dachuanwang.com">
<Cluster className="org.apache.catalina.ha.tcp.SimpleTcpCluster"/>
<Realm className="org.apache.catalina.realm.UserDatabaseRealm"
resourceName="UserDatabase"/>
<Host name="www.dachuanwang.com" appBase="webapps"
unpackWARs="true" autoDeploy="true"
xmlValidation="false" xmlNamespaceAware="false">
<Context path="" reloadable="true" docBase="e_business" crossContext="true"> </Context>
</Host>
</Engine>
至此环境相关配置到此结束,相关文件请参阅附件~~~若有不对之处望各位eyeer提出讨论。