Glassfish和mod_jk-负载平衡和会话复制



我正在使用Glassfish和mod_jk配置一个环境,以提供负载平衡和会话复制。

我的worker.properties如下:

worker.list=i1,i2,loadbalancer
# default properties for workers
worker.template.type=ajp13
worker.template.port=28080
worker.template.lbfactor=1
worker.template.socket_timeout=300
# properties for node1
worker.i1.reference=worker.template
worker.i1.host=10.0.0.93
#worker.worker1.host=node1
# properties for worker2
worker.i2.reference=worker.template
worker.i2.host=10.0.0.38
#worker.worker2.host=node2
# properties for loadbalancer
worker.loadbalancer.type=lb
worker.loadbalancer.balance_workers=i1,i2
worker.loadbalancer.sticky_session=true

我所做的步骤是:创建了两个节点,n1和n2从我的服务器集中管理(通过SSH):

create-node-ssh --sshuser ubuntu --sshkeyfile /home/ubuntu/acme-auction.pem --nodehost 10.0.0.93 --installdir /home/ubuntu/glassfish3 n1
create-node-ssh --sshuser ubuntu --sshkeyfile /home/ubuntu/acme-auction.pem --nodehost 10.0.0.38 --installdir /home/ubuntu/glassfish3 n2

创建了一个集群c1:

create-cluster --properties 'GMS_DISCOVERY_URI_LIST=generate:GMS_LISTENER_PORT=9090' c1

创建了两个实例:

create-instance --cluster  c1 --node n1 i1
create-instance --cluster  c1 --node n2 i2

启动实例i1启动实例i2

创建了一个http侦听器和一个网络侦听器

create-http-listener --listenerport 28080 --listeneraddress 0.0.0.0 --defaultvs server jk-connector
create-network-listener --protocol http-listener-1 --listenerport 28080 --jkenabled true --target c1-config jk-connector

然后我创建了路由JVM选项:

create-jvm-options --target c1 "-DjvmRoute=${AJP_INSTANCE_NAME}"

以及根据jvm路由的sysyem属性:

create-system-properties --target i1 AJP_INSTANCE_NAME=i1
create-system-properties --target i2 AJP_INSTANCE_NAME=i2

我希望能够使用我的应用程序访问server_ip/app_name。

如果我看一下饼干,我可以看到:

  • a JSESSIONIDVERSION,格式:value:number_of_operation
  • JSESSIONID,格式:value.i1
  • JREPLICA,格式:i2

(或者与交换的i2和i1相同)。这让我假设复制设置正确,但当我停止i1时,我得到的是一个空白页面,cookie中没有任何更改(我认为JSESSIONID应该更改".i2"中的最后一部分".i1",以使请求路由到i2,我错了吗?)。谢谢Andrea

实际上,这是一个序列化问题,无法序列化会话并(因此)切换到另一个实例。为了使其可串行化,只需要

  • 使会话中管理的所有对象实现Serializable
  • 对于那些无法序列化的对象(例如EntityManager、Transactions…),在声明属性时添加"transient"修饰符

希望能有所帮助,Andrea

最新更新