此内容没有您所选择的语言版本。
29.2. Configure Cross-Datacenter Replication
Procedure 29.1. Set Up Cross-Datacenter Replication
Set Up RELAY
Add the following configuration to thestandalone.xmlfile to set upRELAY:<subsystem xmlns="urn:jboss:domain:jgroups:1.2" default-stack="udp"> <stack name="udp"> <transport type="UDP" socket-binding="jgroups-udp"/> ... <relay site="LON"> <remote-site name="NYC" stack="tcp" cluster="global"/> <remote-site name="SFO" stack="tcp" cluster="global"/> <property name="relay_multicasts">false</property> </relay> </stack> </subsystem>TheRELAYprotocol creates an additional stack (running parallel to the existingTCPstack) to communicate with the remote site. If aTCPbased stack is used for the local cluster, twoTCPbased stack configurations are required: one for local communication and one to connect to the remote site. For an illustration, see Section 29.1, “Cross-Datacenter Replication Operations”Set Up Sites
Use the following configuration in thestandalone.xmlfile to set up sites for each distributed cache in the cluster:<distributed-cache> ... <backups> <backup site="{FIRSTSITENAME}" strategy="{SYNC/ASYNC}" /> <backup site="{SECONDSITENAME}" strategy="{SYNC/ASYNC}" /> </backups> </distributed-cache>Configure Local Site Transport
Add the name of the local site in thetransportelement to configure transport:<transport executor="infinispan-transport" lock-timeout="60000" cluster="LON" stack="udp"/>
29.2.2. Configure Cross-Data Replication (Library Mode) 复制链接链接已复制到粘贴板!
relay.RELAY2 protocol creates an additional stack (running parallel to the existing TCP stack) to communicate with the remote site. If a TCP-based stack is used for the local cluster, two TCP based stack configurations are required: one for local communication and one to connect to the remote site.
Procedure 29.2. Setting Up Cross-Datacenter Replication
Configure the Local Site
Add thesiteelement to theglobalelement to add the local site (in this example, the local site is namedLON).<infinispan> <global> ... <site local="LON" /> ... </global> </infinispan>Configure JGroups for the Local Site
Cross-site replication requires a non-default JGroups configuration. Add thetransportelement and set up the path to the configuration file as theconfigurationFileproperty. In this example, the JGroups configuration file is namedjgroups-with-relay.xml.<infinispan> <global> ... <site local="LON" /> <transport clusterName="default"> <properties> <property name="configurationFile" value="jgroups-with-relay.xml" /> </properties> </transport> ... </global> </infinispan>Configure the LON Cache
Configure the cache in siteLONto back up to the sitesNYCandSFO:<infinispan> <global> <site local="LON" /> <transport clusterName="default"> <properties> <property name="configurationFile" value="jgroups-with-relay.xml" /> </properties> </transport> ... </global> ... <namedCache name="lon"> <sites> <backups> <backup site="NYC" strategy="SYNC" backupFailurePolicy="WARN" /> <backup site="SFO" strategy="ASYNC" backupFailurePolicy="IGNORE"/> </backups> </sites> </namedCache> </infinispan>Configure the Back Up Caches
- Configure the cache in site
NYCto receive back up data fromLON:<infinispan> <global> <site local="NYC" /> <transport clusterName="default"> <properties> <property name="configurationFile" value="jgroups-with-relay.xml"/> </properties> </transport> ... </global> ... <namedCache name="lonBackup"> <sites> <backupFor remoteSite="LON" remoteCache="lon" /> </sites> </namedCache> </infinispan> - Configure the cache in site
SFOto receive back up data fromLON:<infinispan> <global> <site local="SFO" /> <transport clusterName="default"> <properties> <property name="configurationFile" value="jgroups-with-relay.xml"/> </properties> </transport> ... </global> ... <namedCache name="lonBackup"> <sites> <backupFor remoteSite="LON" remoteCache="lon" /> </sites> </namedCache> </infinispan>
Add the Contents of the Configuration File
As a default, Red Hat JBoss Data Grid includes JGroups configuration files such asjgroups-tcp.xmlandjgroups-udp.xmlin theinfinispan-core-{VERSION}.jarpackage.Copy the JGroups configuration to a new file (in this example, it is namedjgroups-with-relay.xml) and add the provided configuration information to this file. Note that therelay.RELAY2protocol configuration must be the last protocol in the configuration stack.<config> ... <relay.RELAY2 site="LON" config="relay.xml" relay_multicasts="false" /> </config>Configure the relay.xml File
Set up therelay.RELAY2configuration in therelay.xmlfile. This file describes the global cluster configuration.<RelayConfiguration> <sites> <site name="LON" id="0"> <bridges> <bridge config="jgroups-global.xml" name="global"/> </bridges> </site> <site name="NYC" id="1"> <bridges> <bridge config="jgroups-global.xml" name="global"/> </bridges> </site> <site name="SFO" id="2"> <bridges> <bridge config="jgroups-global.xml" name="global"/> </bridges> </site> </sites> </RelayConfiguration>Configure the Global Cluster
The filejgroups-global.xmlreferenced inrelay.xmlcontains another JGroups configuration which is used for the global cluster: communication between sites.The global cluster configuration is usuallyTCP-based and uses theTCPPINGprotocol (instead ofPINGorMPING) to discover members. Copy the contents ofjgroups-tcp.xmlintojgroups-global.xmland add the following configuration in order to configureTCPPING:<config> <TCP bind_port="7800" ... /> <TCPPING initial_hosts="lon.hostname[7800],nyc.hostname[7800],sfo.hostname[7800]" num_initial_members="3" ergonomics="false" /> <!-- Rest of the protocols --> </config>Replace the hostnames (or IP addresses) inTCPPING.initial_hostswith those used for your site masters. The ports (7800in this example) must match theTCP.bind_port.For more information about theTCPPINGprotocol, see Section 26.2.1.3, “Using the TCPPing Protocol”
Procedure 29.3. Configure Cross-Datacenter Replication Programmatically
Identify the Node Location
Declare the site the node resides in:globalConfiguration.site().localSite("LON");Configure JGroups
Configure JGroups to use theRELAYprotocol:globalConfiguration.transport().addProperty("configurationFile", jgroups-with-relay.xml);Set Up the Remote Site
Set up JBoss Data Grid caches to replicate to the remote site:ConfigurationBuilder lon = new ConfigurationBuilder(); lon.sites().addBackup() .site("NYC") .backupFailurePolicy(BackupFailurePolicy.WARN) .strategy(BackupConfiguration.BackupStrategy.SYNC) .replicationTimeout(12000) .sites().addInUseBackupSite("NYC") .sites().addBackup() .site("SFO") .backupFailurePolicy(BackupFailurePolicy.IGNORE) .strategy(BackupConfiguration.BackupStrategy.ASYNC) .sites().addInUseBackupSite("SFO")Optional: Configure the Backup Caches
JBoss Data Grid implicitly replicates data to a cache with same name as the remote site. If a backup cache on the remote site has a different name, users must specify abackupForcache to ensure data is replicated to the correct cache.Note
This step is optional and only required if the remote site's caches are named differently from the original caches.- Configure the cache in site
NYCto receive backup data fromLON:ConfigurationBuilder NYCbackupOfLon = new ConfigurationBuilder(); lonBackup.sites().backupFor().remoteCache("lon").remoteSite("LON"); - Configure the cache in site
SFOto receive backup data fromLON:ConfigurationBuilder SFObackupOfLon = new ConfigurationBuilder(); lonBackup.sites().backupFor().remoteCache("lon").remoteSite("LON");
Add the Contents of the Configuration File
As a default, Red Hat JBoss Data Grid includes JGroups configuration files such asjgroups-tcp.xmlandjgroups-udp.xmlin theinfinispan-core-{VERSION}.jarpackage.Copy the JGroups configuration to a new file (in this example, it is namedjgroups-with-relay.xml) and add the provided configuration information to this file. Note that therelay.RELAY2protocol configuration must be the last protocol in the configuration stack.<config> ... <relay.RELAY2 site="LON" config="relay.xml" relay_multicasts="false" /> </config>Configure the relay.xml File
Set up therelay.RELAY2configuration in therelay.xmlfile. This file describes the global cluster configuration.<RelayConfiguration> <sites> <site name="LON" id="0"> <bridges> <bridge config="jgroups-global.xml" name="global"/> </bridges> </site> <site name="NYC" id="1"> <bridges> <bridge config="jgroups-global.xml" name="global"/> </bridges> </site> <site name="SFO" id="2"> <bridges> <bridge config="jgroups-global.xml" name="global"/> </bridges> </site> </sites> </RelayConfiguration>Configure the Global Cluster
The filejgroups-global.xmlreferenced inrelay.xmlcontains another JGroups configuration which is used for the global cluster: communication between sites.The global cluster configuration is usuallyTCP-based and uses theTCPPINGprotocol (instead ofPINGorMPING) to discover members. Copy the contents ofjgroups-tcp.xmlintojgroups-global.xmland add the following configuration in order to configureTCPPING:<config> <TCP bind_port="7800" ... /> <TCPPING initial_hosts="lon.hostname[7800],nyc.hostname[7800],sfo.hostname[7800]" num_initial_members="3" ergonomics="false" /> <!-- Rest of the protocols --> </config>Replace the hostnames (or IP addresses) inTCPPING.initial_hostswith those used for your site masters. The ports (7800in this example) must match theTCP.bind_port.For more information about theTCPPINGprotocol, see Section 26.2.1.3, “Using the TCPPing Protocol”