Coherence Step by Step 第二篇 集群(二) 建立集群(翻译)
原文链接http://docs.oracle.com/cd/E24290_01/coh.371/e22837/cluster_setup.htm#CHDFCBIG
1.建立集群概述
<?xml version='1.0'?> <coherence xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://xmlns.oracle.com/coherence/coherence-operational-config" xsi:schemaLocation="http://xmlns.oracle.com/coherence/ coherence-operational-config coherence-operational-config.xsd"> <cluster-config> <member-identity> <cluster-name system-property="tangosol.coherence.cluster"> MyCluster </cluster-name> </member-identity> </cluster-config> </coherence>
- Site Name-网站的名字,用来宿主集群成员。如果没有指定名字,那么服务器的域名会被用来作为名字。在WAN 集群中,这个值标示了成员所在的数据中心和能够作为智能路由、负载均衡和灾难恢复的的基本。
- Machine Name-用来宿主集群成员的服务器名。如果没有指定名字,默认使用服务器名。名字用来作为创建一个ID的基本。集群服务使用ID来确定数据备份在另一个计算机室,以防止单点故障。
- Process Name-宿主集群成员的JVM进程名字。如果没有指定进程名,就默认使用JVM进程号。进程名使得可以简单的区分在一台计算机上的多个JVM。
- Member Name-集群成员的唯一的名字。名字使得区分集群成员非常简单,特别是有多个成员运行在一台计算机上或者同一个JVM。总是应该指定一个成员名字,即时不是必须这样做。
- Role Name-集群成员在集群中的的角色。角色名允许应用程序组织集群成员进入指定的角色,如cache server或者cache clients。默认的角色名(cache server使用CoherenceServer,cache client 使用application_class_name),如果没有指定角色名。
<?xml version='1.0'?> <coherence xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://xmlns.oracle.com/coherence/coherence-operational-config" xsi:schemaLocation="http://xmlns.oracle.com/coherence/ coherence-operational-config coherence-operational-config.xsd"> <cluster-config> <member-identity> <site-name system-property="tangosol.coherence.site">pa-1</site-name> <rack-name system-property="tangosol.coherence.rack">100A</rack-name> <machine-name system-property="tangosol.coherence.machine">prod001 </machine-name> <process-name system-property="tangosol.coherence.process">JVM1 </process-name> <member-name system-property="tangosol.coherence.member">C1</member-name> <role-name system-property="tangosol.coherence.role">Server</role-name> </member-identity> </cluster-config> </coherence>
<?xml version='1.0'?> <coherence xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://xmlns.oracle.com/coherence/coherence-operational-config" xsi:schemaLocation="http://xmlns.oracle.com/coherence/ coherence-operational-config coherence-operational-config.xsd"> <cluster-config> <multicast-listener> <address system-property="tangosol.coherence.clusteraddress">224.3.6.0 </address> <port system-property="tangosol.coherence.clusterport">3059</port> </multicast-listener> </cluster-config> </coherence>
<?xml version='1.0'?> <coherence xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://xmlns.oracle.com/coherence/coherence-operational-config" xsi:schemaLocation="http://xmlns.oracle.com/coherence/ coherence-operational-config coherence-operational-config.xsd"> <cluster-config> <multicast-listener> <interface>192.168.0.1</interface> </multicast-listener> </cluster-config> </coherence>
<?xml version='1.0'?> <coherence xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://xmlns.oracle.com/coherence/coherence-operational-config" xsi:schemaLocation="http://xmlns.oracle.com/coherence/ coherence-operational-config coherence-operational-config.xsd"> <cluster-config> <multicast-listener> <time-to-live system-property="tangosol.coherence.ttl">3</time-to-live> </multicast-listener> </cluster-config> </coherence>
<?xml version='1.0'?> <coherence xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://xmlns.oracle.com/coherence/coherence-operational-config" xsi:schemaLocation="http://xmlns.oracle.com/coherence/ coherence-operational-config coherence-operational-config.xsd"> <cluster-config> <multicast-listener> <join-timeout-milliseconds>6000</join-timeout-milliseconds> </multicast-listener> </cluster-config> </coherence>
- 数据包被发往网络上的多个节点(d>1)
- 节点的数量大于指定的threshold(d>(n-1)*(threshold/100))
<?xml version='1.0'?> <coherence xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://xmlns.oracle.com/coherence/coherence-operational-config" xsi:schemaLocation="http://xmlns.oracle.com/coherence/ coherence-operational-config coherence-operational-config.xsd"> <cluster-config> <multicast-listener> <multicast-threshold-percent>40</multicast-threshold-percent> </multicast-listener> </cluster-config> </coherence>
<?xml version='1.0'?> <coherence xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://xmlns.oracle.com/coherence/coherence-operational-config" xsi:schemaLocation="http://xmlns.oracle.com/coherence/ coherence-operational-config coherence-operational-config.xsd"> <cluster-config> <unicast-listener> <address system-property="tangosol.coherence.localhost">192.168.0.1 </address> <port system-property="tangosol.coherence.localport">8090</port> <port-auto-adjust system-property="tangosol.coherence.localport.adjust"> true </port-auto-adjust> </unicast-listener> </cluster-config> </coherence>
<?xml version='1.0'?> <coherence xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://xmlns.oracle.com/coherence/coherence-operational-config" xsi:schemaLocation="http://xmlns.oracle.com/coherence/ coherence-operational-config coherence-operational-config.xsd"> <cluster-config> <unicast-listener> <well-known-addresses> <socket-address id="1"> <address>192.168.0.100</address> <port>8088</port> </socket-address> <socket-address id="2"> <address>192.168.0.101</address> <port>8088</port> </socket-address> </well-known-addresses> </unicast-listener> </cluster-config> </coherence>
-Dtangosol.coherence.wka=192.168.0.100 -Dtangosol.coherence.wka.port=8088
为了创建一个额外的系统属性来指定多个WKA成员地址,operational override file必须被用来定义多个WKA成员地址,必须给每个WKA成员地址元素定义一个system-property属性。这个属性必须包含系统属性名称用于覆盖元素。下面的例子定义了包括系统属性的两个地址:
notice:在测试时候或者在管理生产环境时候可以定义额外的系统属性来指定WKA成员地址的列表。然而,最佳的实践是,在生产环境中仅使用operational override file来指定WKA成员。这确保了每个cluster成员是同一个WKA列表。
<?xml version='1.0'?> <coherence xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://xmlns.oracle.com/coherence/coherence-operational-config" xsi:schemaLocation="http://xmlns.oracle.com/coherence/ coherence-operational-config coherence-operational-config.xsd"> <cluster-config> <unicast-listener> <well-known-addresses> <socket-address id="1"> <address system-property="tangosol.coherence.wka"></address> <port system-property="tangosol.coherence.wka.port"></port> </socket-address> <socket-address id="2"> <address system-property="tangosol.coherence.wka2"></address> <port system-property="tangosol.coherence.wka2.port"></port> </socket-address> </well-known-addresses> </unicast-listener> </cluster-config> </coherence>
上面的例子中,WKA成员地址是使用系统属性来指定的:如下面所示:
-Dtangosol.coherence.wka=192.168.0.102 -Dtangosol.coherence.wka.port=8090 -Dtangosol.coherence.wka2=192.168.0.103 -Dtangosol.coherence.wka2.port=8094
<?xml version='1.0'?> <coherence xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://xmlns.oracle.com/coherence/coherence-operational-config" xsi:schemaLocation="http://xmlns.oracle.com/coherence/ coherence-operational-config coherence-operational-config.xsd"> <cluster-config> <unicast-listener> <well-known-addresses> <address-provider> <class-name>package.MyAddressProvider</class-name> </address-provider> </well-known-addresses> </unicast-listener> </cluster-config> </coherence>
<address-provider>
元素支持使用<class-factory-name>
元素用来指定一个工厂类来创建AddressProvider的实例,<method-name>元素指定了工厂类的静态工厂方法,执行对象实例化。下面的例子是获取一个地址提供者的实例,使用MyAddressProviderFactory类中的getAddressProvider方法。<?xml version='1.0'?> <coherence xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://xmlns.oracle.com/coherence/coherence-operational-config" xsi:schemaLocation="http://xmlns.oracle.com/coherence/ coherence-operational-config coherence-operational-config.xsd"> <cluster-config> <unicast-listener> <well-known-addresses> <address-provider> <class-factory-name>package.MyAddressProviderFactory </class-factory-name> <method-name>getAddressProvider</method-name> </address-provider> </well-known-addresses> </unicast-listener> </cluster-config> </coherence>
com.tangosol.run.xml.XmlConfigurable
接口的实现或者包含一个有匹配签名的公共构造方法的实现来访问。下面的例子设置iMaxTime参数为2000.<?xml version='1.0'?> <coherence xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://xmlns.oracle.com/coherence/coherence-operational-config" xsi:schemaLocation="http://xmlns.oracle.com/coherence/ coherence-operational-config coherence-operational-config.xsd"> <cluster-config> <unicast-listener> <well-known-addresses> <address-provider> <class-name>package.MyAddressProvider</class-name> <init-params> <init-param> <param-name>iMaxTime</param-name> <param-value>2000</param-value> </init-param> </init-params> </address-provider> </well-known-addresses> </unicast-listener> </cluster-config> </coherence>
<?xml version='1.0'?> <coherence xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://xmlns.oracle.com/coherence/coherence-operational-config" xsi:schemaLocation="http://xmlns.oracle.com/coherence/ coherence-operational-config coherence-operational-config.xsd"> <cluster-config> <unicast-listener> <address system-property="tangosol.coherence.localhost">127.0.0.1 </address> </unicast-listener> <multicast-listener> <time-to-live system-property="tangosol.coherence.ttl">0</time-to-live> </multicast-listener> </cluster-config> </coherence>
tangosol.coherence.ttl和tangosol.coherence.localhost系统属性被用来启用single-server模式,而不用operational override file.例如:
-Dtangosol.coherence.ttl=0 -Dtangosol.coherence.localhost=127.0.0.1
<?xml version='1.0'?> <coherence xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://xmlns.oracle.com/coherence/coherence-operational-config" xsi:schemaLocation="http://xmlns.oracle.com/coherence/ coherence-operational-config coherence-operational-config.xsd"> <cluster-config> <tcp-ring-listener> <ip-timeout system-property="tangosol.coherence.ipmonitor.pingtimeout"> 25s </ip-timeout> <ip-attempts>5</ip-attempts> <listen-backlog>10</listen-backlog> </tcp-ring-listener> </cluster-config> </coherence>
-Dtangosol.coherence.ipmonitor.pingtimeout=20s
<?xml version='1.0'?> <coherence xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://xmlns.oracle.com/coherence/coherence-operational-config" xsi:schemaLocation="http://xmlns.oracle.com/coherence/ coherence-operational-config coherence-operational-config.xsd"> <cluster-config> <packet-publisher> <packet-delivery> <heartbeat-milliseconds>5000</heartbeat-milliseconds> </packet-delivery> </packet-publisher> </cluster-config> </coherence>
<?xml version='1.0'?> <coherence xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://xmlns.oracle.com/coherence/coherence-operational-config" xsi:schemaLocation="http://xmlns.oracle.com/coherence/ coherence-operational-config coherence-operational-config.xsd"> <cluster-config> <tcp-ring-listener> <enabled>false</enabled> </tcp-ring-listener> </cluster-config> </coherence>
<?xml version='1.0'?> <coherence xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://xmlns.oracle.com/coherence/coherence-operational-config" xsi:schemaLocation="http://xmlns.oracle.com/coherence/ coherence-operational-config coherence-operational-config.xsd"> <cluster-config> <member-identity> <priority system-property="tangosol.coherence.priority">1</priority> </member-identity> </cluster-config> </coherence>
tangosol.coherence.priority系统熟悉能够使用指定一个cluster成员的优先级,而不用operational overrride file.例如:
-Dtangosol.coherence.priority=1
9.2 指定进程优先级
多个cluster组件支持现成优先级。优先级用来作为检测java 现成执行重要性的基本。组件包含:多播监听器,单播监听器,TCP ring监听器,the packet speaker, the packet publisher,incoming message handler. 默认的优先级设置给了packet speaker最高优先级,接着是incoming message handler,接着是remaining components.
现成哟先机在每个组件的配置元素指定 (<unicast-listener>
, <multicast-listener>
, <packet-speaker>
, <packet-publisher>
, <tcp-ring-listener>
, 和 <incoming-message-handler>
元素, 单独的)。例如,指定单播监听器的现成优先级,编辑operational override file和增加一个<priority>元素,在<unicast-listener>节点力,包含了从1到10的优先级的值,1的优先级最高。
<?xml version='1.0'?> <coherence xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://xmlns.oracle.com/coherence/coherence-operational-config" xsi:schemaLocation="http://xmlns.oracle.com/coherence/ coherence-operational-config coherence-operational-config.xsd"> <cluster-config> <unicast-listener> <priority>5</priority> </unicast-listener> </cluster-config> </coherence>