环境说明:
Windows、jdk1.7、Glassfish4.1、apache2.2.25
创建集群
- 运行:asadmin
- 启动默认域:start-doamin
- 创建你的cluster:multimode -f commands.txt
create-cluster cluster1
create-local-instance --cluster cluster1 ins1
create-local-instance --cluster cluster1 ins2
create-local-instance --cluster cluster1 ins3
create-network-listener --protocol http-listener-1 --listenerport \${AJP_PORT} --target cluster1 --jkenabled true jk-connector
create-jvm-options --target cluster1 "-DjvmRoute=\${AJP_INSTANCE_NAME}"
create-system-properties --target ins1 AJP_PORT=28009
create-system-properties --target ins2 AJP_PORT=28019
create-system-properties --target ins3 AJP_PORT=28029
create-system-properties --target ins1 AJP_INSTANCE_NAME=ins1
create-system-properties --target ins2 AJP_INSTANCE_NAME=ins2
create-system-properties --target ins3 AJP_INSTANCE_NAME=ins3
list-clusters
start-cluster cluster1
配置apache(2.2.*)
- 将如下片段添加到httpd.conf的尾部
- 重启apache
使用apache httpd 2.2.*作为前端进行带来配置,样例如下:
LoadModule proxy_module modules/mod_proxy.so
LoadModule proxy_ajp_module modules/mod_proxy_ajp.so
LoadModule proxy_balancer_module modules/mod_proxy_balancer.so
#你可以在浏览器查看你的均衡器状态
<Location /balancer-manager>
SetHandler balancer-manager
Order Deny,Allow
Deny from none
Allow from localhost
</Location>
<Proxy balancer://cluster>
BalancerMember ajp://localhost:28009 loadfactor=1 route=ins1 retry=5 max=50
BalancerMember ajp://localhost:28019 loadfactor=1 route=ins2 retry=5 max=50
BalancerMember ajp://localhost:28029 loadfactor=1 route=ins3 retry=5 max=50
ProxySet lbmethod=bytraffic
#ProxySet lbmethod=byrequests
ProxySet stickysession=JSESSIONID|jsessionid
</Proxy>
<Location />
ProxyPass balancer://cluster/ timeout=5
ProxyPassReverse balancer://cluster/
</Location>
到此,单机集群搭建完成,下面测试下,测试方法很简单,启动集群后轮流关闭实例,看看应用是否可访问。session复制问题,自己写个简单的jsp应用试试就好,懒得写可以把tomcat的那个关于session的改改就行。
注意web.xml中需要加入此条:
<distributable/>