이 콘텐츠는 선택한 언어로 제공되지 않습니다.

11.2. Run Red Hat JBoss Data Grid in a Cluster


The clustered quickstarts for Red Hat JBoss Data Grid are based on the quickstarts found in https://github.com/infinispan/infinispan-quickstart/tree/master/clustered-cache.

11.2.1. Compile the Project

Use Maven to compile your project with the following command:
$ mvn clean compile dependency:copy-dependencies -DstripVersion
Copy to Clipboard Toggle word wrap

11.2.2. Run the Clustered Cache with Replication Mode

To run Red Hat JBoss Data Grid's replication mode example of a clustered cache, launch two nodes from different consoles.

Procedure 11.1. Run the Clustered Cache with Replication Mode

  1. Use the following command to launch the first node:
    $ java -cp target/classes/:target/dependency/* org.infinispan.quickstart.clusteredcache.replication.Node0
    Copy to Clipboard Toggle word wrap
  2. Use the following command to launch the second node:
    $ java -cp target/classes/:target/dependency/* org.infinispan.quickstart.clusteredcache.replication.Node1
    Copy to Clipboard Toggle word wrap
Result

JGroups and JBoss Data Grid initialized on both nodes. After approximately fifteen seconds, the cache entry log message appears on the console of the first node.

11.2.3. Run the Clustered Cache with Distribution Mode

To run Red Hat JBoss Data Grid's distribution mode example of a clustered cache, launch three nodes from different consoles.

Procedure 11.2. Run the Clustered Cache with Distribution Mode

  1. Use the following command to launch the first node:
    $ java -cp target/classes/:target/dependency/* org.infinispan.quickstart.clusteredcache.distribution.Node0
    Copy to Clipboard Toggle word wrap
  2. Use the following command to launch the second node:
    $ java -cp target/classes/:target/dependency/* org.infinispan.quickstart.clusteredcache.distribution.Node1
    Copy to Clipboard Toggle word wrap
  3. Use the following command to launch the third node:
    $ java -cp target/classes/:target/dependency/* org.infinispan.quickstart.clusteredcache.distribution.Node2
    Copy to Clipboard Toggle word wrap
Result

JGroups and JBoss Data Grid initialized on the three nodes. After approximately fifteen seconds, the ten entries added by the third node are visible as they are distributed to the first and second nodes.

11.2.4. Configure the Cluster

Use the following steps to add and configure your cluster:

Procedure 11.3. Configure the Cluster

  1. Add the default configuration for a new cluster.
  2. Customize the default cluster configuration according to the requirements of your network. This is done declaratively (using XML) or programmatically.
  3. Configure the replicated or distributed data grid.

11.2.4.1. Add the Default Cluster Configuration

Add a cluster configuration to ensure that Red Hat JBoss Data Grid is aware that a cluster exists and is defined. The following is a default configuration that serves this purpose:

Example 11.2. Default Configuration

new ConfigurationBuilder()
   .clustering().cacheMode(CacheMode.REPL_SYNC)
   .build()
Copy to Clipboard Toggle word wrap

Note

Use the new GlobalConfigurationBuilder().clusteredDefault() to quickly create a preconfigured and cluster-aware GlobalConfiguration for clusters. This configuration can also be customized.

11.2.4.2. Customize the Default Cluster Configuration

Depending on the network requirements, you may need to customize your JGroups configuration.
Programmatic Configuration:

Use the following GlobalConfiguration code to specify the name of the file to use for JGroups configuration:

new GlobalConfigurationBuilder().transport().addProperty("configurationFile", "jgroups.xml")
   .build()
Copy to Clipboard Toggle word wrap
Replace jgroups.xml with the desired file name.
The jgroups.xml file is located at Infinispan-Quickstart/clustered-cache/src/main/resources/.

Note

To bind JGroups solely to your loopback interface (to avoid any configured firewalls), use the system property -Djgroups.bind_addr="127.0.0.1". This is particularly useful to test a cluster where all nodes are on a single machine.
Declarative Configuration:

Use the following XML snippet in the infinispan.xml file to configure the JGroups properties to use Red Hat JBoss Data Grid's XML configuration:

<global>
   <transport>
      <properties>
         <property name="configurationFile" value="jgroups.xml"/>
      </properties>
   </transport>
</global>
Copy to Clipboard Toggle word wrap

11.2.4.3. Configure the Replicated Data Grid

Red Hat JBoss Data Grid's replicated mode ensures that every entry is replicated on every node in the data grid.
This mode offers security against data loss due to node failures and excellent data availability. These benefits are at the cost of limiting the storage capacity to the amount of storage available on the node with the least memory.
Programmatic Configuration:

Use the following code snippet to programmatically configure the cache for replication mode (either synchronous or asynchronous):

private static EmbeddedCacheManager createCacheManagerProgramatically() {
   return new DefaultCacheManager(
      new GlobalConfigurationBuilder()
         .transport().addProperty("configurationFile", "jgroups.xml")
         .build(),
      new ConfigurationBuilder()
         .clustering().cacheMode(CacheMode.REPL_SYNC)
         .build()
   );
}
Copy to Clipboard Toggle word wrap
Declarative Configuration:

Edit the infinispan.xml file to include the following XML code to declaratively configure the cache for replication mode (either synchronous or asynchronous):

<infinispan xsi:schemaLocation="urn:infinispan:config:8.3 http://www.infinispan.org/schemas/infinispan-config-8.3.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="urn:infinispan:config:8.3">
   <global>
      <transport>
         <properties>
            <property name="configurationFile" value="jgroups.xml"/>
         </properties>
      </transport>
   </global>
   <default>
      <clustering mode="replication">
         <sync/>
      </clustering>
   </default>
</infinispan>
Copy to Clipboard Toggle word wrap
Use the following code to initialize and return a DefaultCacheManager with the XML configuration file:
private static EmbeddedCacheManager createCacheManagerFromXml() throws IOException {
   return new DefaultCacheManager("infinispan.xml");}
Copy to Clipboard Toggle word wrap

Note

JBoss EAP includes its own underlying JMX. This can cause a collision when using the sample code with JBoss EAP and display an error such as org.infinispan.jmx.JmxDomainConflictException: Domain already registered org.infinispan.
To avoid this, configure global configuration as follows:
GlobalConfiguration glob = new GlobalConfigurationBuilder()
	.clusteredDefault()
        .globalJmxStatistics()
          .allowDuplicateDomains(true)
          .enable()
        .build();
Copy to Clipboard Toggle word wrap

11.2.4.4. Configure the Distributed Data Grid

Red Hat JBoss Data Grid's distributed mode ensures that each entry is stored on a subset of the total nodes in the data grid. The number of nodes in the subset is controlled by the numOwners parameter, which sets how many owners each entry has.
Distributed mode offers increased storage capacity but also results in increased access times and less durability (protection against node failures). Adjust the numOwners value to set the desired trade off between space, durability and availability. Durability is further improved by JBoss Data Grid's topology aware consistent hash, which locates entry owners across a variety of data centers, racks and nodes.
Programmatic Configuration:

Programmatically configure the cache for distributed mode (either synchronous or asynchronous) as follows:

new ConfigurationBuilder()
   .clustering()
      .cacheMode(CacheMode.DIST_SYNC)
      .hash().numOwners(2)
   .build()
Copy to Clipboard Toggle word wrap
Declarative Configuration:

Edit the infinispan.xml file to include the following XML code to declaratively configure the cache for distributed mode (either synchronous or asynchronous):

<default>
   <clustering mode="distribution">
      <sync/>
      <hash numOwners="2"/>
   </clustering>
</default>
Copy to Clipboard Toggle word wrap
맨 위로 이동
Red Hat logoGithubredditYoutubeTwitter

자세한 정보

평가판, 구매 및 판매

커뮤니티

Red Hat 문서 정보

Red Hat을 사용하는 고객은 신뢰할 수 있는 콘텐츠가 포함된 제품과 서비스를 통해 혁신하고 목표를 달성할 수 있습니다. 최신 업데이트를 확인하세요.

보다 포괄적 수용을 위한 오픈 소스 용어 교체

Red Hat은 코드, 문서, 웹 속성에서 문제가 있는 언어를 교체하기 위해 최선을 다하고 있습니다. 자세한 내용은 다음을 참조하세요.Red Hat 블로그.

Red Hat 소개

Red Hat은 기업이 핵심 데이터 센터에서 네트워크 에지에 이르기까지 플랫폼과 환경 전반에서 더 쉽게 작업할 수 있도록 강화된 솔루션을 제공합니다.

Theme

© 2025 Red Hat