19.4.2. 配置 JGroups 子系统使用 TCP

在默认情况下,JGroups 系统使用多点传送 UDP 通讯。使用下列过程来配置 JGroups 系统使用多点传送 TCP。
要配置 mod_cluster 子系统使用 TCP,请参考 第 19.4.3 节 “禁用 mod_cluster 子系统的广告”
  1. 根据您的环境修改下列脚本。

    复制下列脚本到文本编辑器里。如果您使用受管域里不同的配置集,请相应地修改配置集名称。如果您使用独立服务器,请删除命令行里的 /profile=full-ha 部分。像下面这样修改命令底部列出的属性。这些属性都是可选的。
    initial_hosts
    用逗号隔开的主机列表,里面的主机被认为是众所周知的,可用来查找初始成员资格。
    port_range
    如果需要,您可以分配一个端口范围。如果您分配的端口范围为 2,而初始端口为 7600,那么 TCPPING 将试图连接每台主机的 7600-7601 端口。这个属性是可选的。
    timeout
    群集成员的可选超时时间(毫秒)。
    num_initial_members
    在群集被认为完成之前的节点数。这个属性是可选的。
    batch
    ##  If  tcp  is already added then you can remove it  ##
    /profile=full-ha/subsystem=jgroups/stack=tcp:remove
    /profile=full-ha/subsystem=jgroups/stack=tcp:add(transport={"type" =>"TCP", "socket-binding" => "jgroups-tcp"})
    /profile=full-ha/subsystem=jgroups/stack=tcp/:add-protocol(type=TCPPING)
    /profile=full-ha/subsystem=jgroups/stack=tcp/:add-protocol(type=MERGE2)
    /profile=full-ha/subsystem=jgroups/stack=tcp/:add-protocol(type=FD_SOCK,socket-binding=jgroups-tcp-fd)
    /profile=full-ha/subsystem=jgroups/stack=tcp/:add-protocol(type=FD)
    /profile=full-ha/subsystem=jgroups/stack=tcp/:add-protocol(type=VERIFY_SUSPECT)
    /profile=full-ha/subsystem=jgroups/stack=tcp/:add-protocol(type=BARRIER)
    /profile=full-ha/subsystem=jgroups/stack=tcp/:add-protocol(type=pbcast.NAKACK)
    /profile=full-ha/subsystem=jgroups/stack=tcp/:add-protocol(type=UNICAST2)
    /profile=full-ha/subsystem=jgroups/stack=tcp/:add-protocol(type=pbcast.STABLE)
    /profile=full-ha/subsystem=jgroups/stack=tcp/:add-protocol(type=pbcast.GMS)
    /profile=full-ha/subsystem=jgroups/stack=tcp/:add-protocol(type=UFC)
    /profile=full-ha/subsystem=jgroups/stack=tcp/:add-protocol(type=MFC)
    /profile=full-ha/subsystem=jgroups/stack=tcp/:add-protocol(type=FRAG2)
    /profile=full-ha/subsystem=jgroups/stack=tcp/:add-protocol(type=RSVP)
    /profile=full-ha/subsystem=jgroups:write-attribute(name=default-stack,value=tcp)
    run-batch
    /profile=full-ha/subsystem=jgroups/stack=tcp/protocol=TCPPING/property=initial_hosts/:add(value="HostA[7600],HostB[7600]")
    /profile=full-ha/subsystem=jgroups/stack=tcp/protocol=TCPPING/property=port_range/:add(value=0)
    /profile=full-ha/subsystem=jgroups/stack=tcp/protocol=TCPPING/property=timeout/:add(value=3000)
    /profile=full-ha/subsystem=jgroups/stack=tcp/protocol=TCPPING/property=num_initial_members/:add(value=3)
  2. 以批处理方式运行脚本。

    警告

    运行这个配置集的服务器必须在执行批处理文件前先关闭。
    在终端窗口里,进入包含 jboss-cli.sh 脚本的目录并输入下列命令。
    ./jboss-cli.sh -c --file=SCRIPT_NAME
    这里的 SCRIPT_NAME 是名称及包含脚本的路径。
结果

TCPPING 栈对于 JGroups 子系统不可用。如果使用它,JGroups 子系统将对所有网络通讯使用 TCP。要配置 mod_cluster 子系统使用 TCP,请参考 第 19.4.3 节 “禁用 mod_cluster 子系统的广告”