1

我正在使用 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-listener 和一个 network-listener

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}"

...以及根据 jvmRoute 的 sysyem 属性:

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

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

如果我查看 cookie,我可以看到:

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

(或与 i2 和 i1 交换相同)。这让我假设复制设置正确,但是当我停止 i1 时,我得到的是一个空白页并且 cookie 没有变化(我想 JSESSIONID 应该更改最后一部分,“.i2”中的“.i1”以使请求被路由到 i2,我错了吗?)。谢谢,安德里亚

4

1 回答 1

2

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

  • 使会话中管理的所有对象实现可序列化
  • 对于那些不能被序列化的人(例如EntityManager、Transactions...),在声明属性时添加“transient”修饰符

希望它有帮助,安德里亚

于 2012-10-17T06:51:57.247 回答