Tutorial Creating and Using a Cluster Configuration
A short walk-through that uses a single computer to demonstrate how to use gfsh to create a cluster configuration for a Geode cluster.
The gfsh command-line tool allows you to configure and start a Geode cluster. The cluster configuration service uses Apache Geode locators to store the configuration at the group and cluster levels and serves these configurations to new members as they are started. The locators store the configurations in a hidden region that is available to all locators and also write the configuration data to disk as XML files. Configuration data is updated as gfsh commands are executed.
This section provides a walk-through example of configuring a simple Apache Geode cluster and then re-using that configuration in a new context.
-
Create a working directory (For example:
/home/username/my_geode) and switch to the new directory. This directory will contain the configurations for your cluster. -
Start the
gfshcommand-line tool. For example:$ gfshThe
gfshcommand prompt displays._________________________ __/ _____/ ______/ ______/ /____/ // / __/ /___ /_____ / _____ // /__/ / ____/ _____/ / / / //______/_/ /______/_/ /_/ 1.15Monitor and Manage Apache Geodegfsh> -
Start a locator using the command in the following example:
gfsh>start locator --name=locator1Starting a Geode Locator in /Users/username/my_geode/locator1................................Locator in /Users/username/my_geode/locator1 on 192.0.2.0[10334] as locator1is currently online.Process ID: 70919Uptime: 12 secondsGeode Version: 1.15Java Version: 8.0.121Log File: /Users/username/my_geode/locator1/locator1.logJVM Arguments: -Dgemfire.enable-cluster-configuration=true-Dgemfire.load-cluster-configuration-from-dir=false-Dgemfire.launcher.registerSignalHandlers=true -Djava.awt.headless=true-Dsun.rmi.dgc.server.gcInterval=9223372036854775806Class-Path: /Users/username/geode115/lib/geode-dependencies.jarSuccessfully connected to: JMX Manager [host=192.0.2.0, port=1099]Cluster configuration service is up and running.Note that
gfshresponds with a message indicating that the cluster configuration service is up and running. If you see a message indicating a problem, review the locator log file for possible errors. The path to the log file is displayed in the output fromgfsh. -
Start Apache Geode servers using the commands in the following example:
gfsh>start server --name=server1 --groups=group1Starting a Geode Server in /Users/username/my_geode/server1........Server in /Users/username/my_geode/server1 on 192.0.2.0[40404] as server1is currently online.Process ID: 5627Uptime: 2 secondsGeode Version: 1.15Java Version: 8.0.121Log File: /Users/username/my_geode/server1/server1.logJVM Arguments: -Dgemfire.default.locators=192.0.2.0[10334] -Dgemfire.groups=group1-Dgemfire.start-dev-rest-api=false -Dgemfire.use-cluster-configuration=true-Dgemfire.launcher.registerSignalHandlers=true -Djava.awt.headless=trueClass-Path: /Users/username/geode115/lib/geode-dependencies.jargfsh>start server --name=server2 --groups=group1 --server-port=40405Starting a Geode Server in /Users/username/my_geode/server2........Server in /Users/username/my_geode/server2 on 192.0.2.0[40405] as server2is currently online.Process ID: 5634Uptime: 2 secondsGeode Version: 1.15Java Version: 8.0.121Log File: /Users/username/my_geode/server2/server2.logJVM Arguments: -Dgemfire.default.locators=192.0.2.0[10334] -Dgemfire.groups=group1-Dgemfire.start-dev-rest-api=false -Dgemfire.use-cluster-configuration=true-Dgemfire.launcher.registerSignalHandlers=true -Djava.awt.headless=true-Dsun.rmi.dgc.server.gcInterval=9223372036854775806Class-Path: /Users/username/geode115/lib/geode-dependencies.jargfsh>start server --name=server3 --server-port=40406Starting a Geode Server in /Users/username/my_geode/server3........Server in /Users/username/my_geode/server3 on 192.0.2.0[40406] as server3is currently online.Process ID: 5637Uptime: 2 secondsGeode Version: 1.15Java Version: 8.0.121Log File: /Users/username/my_geode/server3/server3.logJVM Arguments: -Dgemfire.default.locators=192.0.2.0[10334]-Dgemfire.start-dev-rest-api=false -Dgemfire.use-cluster-configuration=true-Dgemfire.launcher.registerSignalHandlers=true -Djava.awt.headless=true-Dsun.rmi.dgc.server.gcInterval=9223372036854775806Class-Path: /Users/username/geode115/lib/geode-dependencies.jarNote that the
gfshcommands you used to startserver1andserver2specify a group namedgroup1while the command forserver3did not specify a group name. -
Create some regions using the commands in the following example:
gfsh>create region --name=region1 --groups=group1 --type=REPLICATEMember | Status | Message------- | ------ | --------------------------------------server1 | OK | Region "/region1" created on "server1"server2 | OK | Region "/region1" created on "server2"Cluster configuration for group 'group1' is updated.gfsh>create region --name=region2 --type=REPLICATEMember | Status | Message------- | ------ | --------------------------------------server1 | OK | Region "/region2" created on "server1"server2 | OK | Region "/region2" created on "server2"server3 | OK | Region "/region2" created on "server3"Cluster configuration for group 'cluster' is updated.Note that
region1is created on all cache servers that specified the group namedgroup1when starting the cache server (server1andserver2, in this example).region2is created on all members because no group was specified. -
Deploy jar files. Use the
gfsh deploycommand to deploy application jar files to all members or to a specified group of members. The following example deploys themx4j-3.0.2.jarandra.jarfiles from the distribution. (Note: This is only an example, you do not need to deploy these files to use the Cluster Configuration Service. Alternately, you can use any two jar files for this demonstration.)gfsh>deploy --groups=group1 --jars=/lib/mx4j-3.0.2.jarDeploying files: mx4j-3.0.2.jarTotal file size is: 0.39MBContinue? (Y/n): yMember | Deployed JAR | Deployed JAR Location------- | -------------- | ----------------------------------------------------------server1 | mx4j-3.0.2.jar | /Users/username/my_geode/server1/mx4j-3.0.2.v1.jarserver2 | mx4j-3.0.2.jar | /Users/username/my_geode/server2/mx4j-3.0.2.v1.jargfsh>deploy --jars=/lib/ra.jarDeploying files: ra.jarTotal file size is: 0.03MBContinue? (Y/n): yMember | Deployed JAR | Deployed JAR Location------- | ------------ | --------------------------------------------------server1 | ra.jar | /Users/username/my_geode/server1/ra.v1.jarserver2 | ra.jar | /Users/username/my_geode/server2/ra.v1.jarserver3 | ra.jar | /Users/username/my_geode/server2/ra.v1.jarNote that the
mx4j-3.0.2.jarfile was deployed only to the members ofgroup1and thera.jarwas deployed to all members. -
Export the cluster configuration. You can use the
gfsh export cluster-configurationcommand to create a zip file that contains the cluster's persisted configuration. The zip file contains a copy of the contents of thecluster_configdirectory. For example:gfsh>export cluster-configuration --zip-file-name=/Users/username/myClConfig.zipApache Geode writes the cluster configuration to the specified zip file.
File saved to /Users/username/myClConfig.zipThe remaining steps demonstrate how to use the cluster configuration you just created.
-
Shut down the cluster using the following commands:
gfsh>shutdown --include-locators=trueAs a lot of data in memory will be lost, including possibly events in queues, do youreally want to shutdown the entire distributed system? (Y/n): YShutdown is triggeredgfsh>No longer connected to 192.0.2.0[1099].gfsh> -
Exit the
gfshcommand shell:gfsh>quitExiting... -
Create a new working directory (for example:
new_geode) and switch to the new directory. -
Start the
gfshcommand shell:$ gfsh -
Start a new locator. For example:
gfsh>start locator --name=locator2 --port=10335Starting a Geode Locator in /Users/username/new_geode/locator2................................Locator in /Users/username/new_geode/locator2 on 192.0.2.0[10335] as locator2is currently online.Process ID: 5749Uptime: 15 secondsGeode Version: 1.15Java Version: 8.0.121Log File: /Users/username/new_geode/locator2/locator2.logJVM Arguments: -Dgemfire.enable-cluster-configuration=true-Dgemfire.load-cluster-configuration-from-dir=false-Dgemfire.launcher.registerSignalHandlers=true -Djava.awt.headless=true-Dsun.rmi.dgc.server.gcInterval=9223372036854775806Class-Path: /Users/username/geode115/lib/geode-dependencies.jarSuccessfully connected to: JMX Manager [host=192.0.2.0, port=1099]Cluster configuration service is up and running. -
Import the cluster configuration using the
import cluster-configurationcommand. For example:gfsh>import cluster-configuration --zip-file-name=/Users/username/myClConfig.zipThis command will replace the existing cluster configuration, if any, The old configuration will be backed up in the working directory.Continue? (Y/n): yCluster configuration successfully importedNote that the
locator2directory now contains acluster_configsubdirectory. -
Start a server that does not reference a group:
gfsh>start server --name=server4 --server-port=40414Starting a Geode Server in /Users/username/new_geode/server4...........Server in /Users/username/new_geode/server4 on 192.0.2.0[40414] as server4is currently online.Process ID: 5813Uptime: 4 secondsGeode Version: 1.15Java Version: 8.0.121Log File: /Users/username/new_geode/server4/server4.logJVM Arguments: -Dgemfire.default.locators=192.0.2.0[10335]-Dgemfire.start-dev-rest-api=false -Dgemfire.use-cluster-configuration=true-Dgemfire.launcher.registerSignalHandlers=true -Djava.awt.headless=true-Dsun.rmi.dgc.server.gcInterval=9223372036854775806Class-Path: /Users/username/geode115/lib/geode-dependencies.jar -
Start another server that references
group1:gfsh>start server --name=server5 --groups=group1 --server-port=40415Starting a Geode Server in /Users/username/new_geode/server5........Server in /Users/username/new_geode/server2 on 192.0.2.0[40415] as server5is currently online.Process ID: 5954Uptime: 2 secondsGeode Version: 1.15Java Version: 8.0.121Log File: /Users/username/new_geode/server5/server5.logJVM Arguments: -Dgemfire.default.locators=192.0.2.0[10335] -Dgemfire.groups=group1-Dgemfire.start-dev-rest-api=false -Dgemfire.use-cluster-configuration=true-Dgemfire.launcher.registerSignalHandlers=true -Djava.awt.headless=true-Dsun.rmi.dgc.server.gcInterval=9223372036854775806Class-Path: /Users/username/geode115/lib/geode-dependencies.jar -
Use the
list regionscommand to display the configured regions. Note that region1 and region2, which were configured in the original cluster level are available.gfsh>list regionsList of regions---------------region1region2 -
Use the
describe regioncommand to see which members host each region. Note that region1 is hosted only by server5 because server5 was started using the group1 configuration. region2 is hosted on both server4 and server5 because region2 was created without a group specified.gfsh>describe region --name=region1Name : region1Data Policy : replicateHosting Members : server5Non-Default Attributes Shared By Hosting MembersType | Name | Value------ | ----------- | ---------------Region | data-policy | REPLICATE| size | 0| scope | distributed-ackgfsh>describe region --name=region2..........................................................Name : region2Data Policy : replicateHosting Members : server5server4Non-Default Attributes Shared By Hosting MembersType | Name | Value------ | ----------- | ---------------Region | data-policy | REPLICATE| size | 0| scope | distributed-ackThis new cluster uses the same configuration as the original system. You can start any number of servers using this cluster configuration. All servers will receive the cluster-level configuration. Servers that specify
group1also receive thegroup1configuration. -
Shut down your cluster using the following commands:
gfsh>shutdown --include-locators=trueAs a lot of data in memory will be lost, including possibly events in queues,do you really want to shutdown the entire distributed system? (Y/n): YShutdown is triggeredgfsh>No longer connected to 192.0.2.0[1099].