Apache Geode 创建和使用群集配置教程
使用单机演示如何为一个Geode集群使用gfsh命令来创建集群配置。
gfsh命令行工具允许你创建和启动Geode集群,集群配置服务使用定位器(locator)以组级别和集群级别来存储配置并且为新的成员在启动时提供服务。定位器将配置存储在一个隐藏的区域中,它可以被所有的定位器使用,并且以xml形式将配置写入碰盘。当gfsh命令执行时,配置会被更新。
本节提供了一个简短的例子,配置一个简单的Apache Geode集群,并在新的上下文中重用。
1.创建一个工作目录 (例如:/home/username/my_gemfire
) 然后切换到此目录。此目录将为你的集群存储配置。
2.启动gfsh命令行工具。例如
:
$ gfsh
gfsh命令提示显示
_________________________ __ / _____/ ______/ ______/ /____/ / / / __/ /___ /_____ / _____ / / /__/ / ____/ _____/ / / / / /______/_/ /______/_/ /_/ 1.0.0 Monitor and Manage Apache Geode gfsh>
3.使用如下命令启动一个定位器
gfsh>start locator --name=locator1 Starting a GemFire Locator in /Users/username/my_gemfire/locator1... ............................. Locator in /Users/username/my_gemfire/locator1 on 192.0.2.0[10334] as locator1 is currently online. Process ID: 5203 Uptime: 15 seconds GemFire Version: 8.1.0 Java Version: 1.7.0_71 Log File: /Users/username/my_gemfire/locator1/locator1.log JVM 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=9223372036854775806 Class-Path: /Users/username/Pivotal_GemFire_810_b50582_Linux/lib/gemfire.jar :/Users/username/Pivotal_GemFire_810_b50582_Linux/lib/locator-dependencies.jar Successfully connected to: [host=192.0.2.0, port=1099] Cluster configuration service is up and running.
注意到gfsh的响应为一条指示集群配置服务已经运行的消息。如果你看到一条消息指出存在的问题,检查定位器的日志文件查看可能的错误。日志文件的路径显示在了gfsh的输出中。
4.使用如下命令启动Apache Geode服务器
gfsh>start server --name=server1 --group=group1 Starting a GemFire Server in /Users/username/my_gemfire/server1... ..... Server in /Users/username/my_gemfire/server1 on 192.0.2.0[40404] as server1 is currently online. Process ID: 5627 Uptime: 2 seconds GemFire Version: 8.1.0 Java Version: 1.7.0_71 Log File: /Users/username/my_gemfire/server1/server1.log JVM Arguments: -Dgemfire.default.locators=192.0.2.0[10334] -Dgemfire.groups=group1 -Dgemfire.use-cluster-configuration=true -XX:OnOutOfMemoryError=kill -KILL %p -Dgemfire.launcher.registerSignalHandlers=true -Djava.awt.headless=true -Dsun.rmi.dgc.server.gcInterval=9223372036854775806 Class-Path: /Users/username/Pivotal_GemFire_810_b50582_Linux/lib/gemfire.jar :/Users/username/Pivotal_GemFire_810_b50582_Linux/lib/server-dependencies.jar gfsh>start server --name=server2 --group=group1 --server-port=40405 Starting a GemFire Server in /Users/username/my_gemfire/server2... ..... Server in /Users/username/my_gemfire/server2 on 192.0.2.0[40405] as server2 is currently online. Process ID: 5634 Uptime: 2 seconds GemFire Version: 8.1.0 Java Version: 1.7.0_71 Log File: /Users/username/my_gemfire/server2/server2.log JVM Arguments: -Dgemfire.default.locators=192.0.2.0[10334] -Dgemfire.groups=group1 -Dgemfire.use-cluster-configuration=true -XX:OnOutOfMemoryError=kill -KILL %p -Dgemfire.launcher.registerSignalHandlers=true -Djava.awt.headless=true -Dsun.rmi.dgc.server.gcInterval=9223372036854775806 Class-Path: /Users/username/Pivotal_GemFire_810_b50582_Linux/lib/gemfire.jar :/Users/username/Pivotal_GemFire_810_b50582_Linux/lib/server-dependencies.jar gfsh>start server --name=server3 --server-port=40406 Starting a GemFire Server in /Users/username/my_gemfire/server3... ..... Server in /Users/username/my_gemfire/server3 on 192.0.2.0[40406] as server3 is currently online. Process ID: 5637 Uptime: 2 seconds GemFire Version: 8.1.0 Java Version: 1.7.0_71 Log File: /Users/username/my_gemfire/server3/server3.log JVM Arguments: -Dgemfire.default.locators=192.0.2.0[10334] -Dgemfire.use-cluster-configuration=true -XX:OnOutOfMemoryError=kill -KILL %p -Dgemfire.launcher.registerSignalHandlers=true -Djava.awt.headless=true -Dsun.rmi.dgc.server.gcInterval=9223372036854775806 Class-Path: /Users/username/Pivotal_GemFire_810_b50582_Linux/lib/gemfire.jar :/Users/username/Pivotal_GemFire_810_b50582_Linux/lib/server-dependencies.jar
注意到你使用的用来启动server1和server2gfsh命令指定了一个组,名字为group1,然而你没有为server3指定组名。
5.使用以下指令创建一些区域:
gfsh>create region --name=region1 --group=group1 --type=REPLICATE Member | Status ------- | -------------------------------------- server2 | Region "/region1" created on "server2" server1 | Region "/region1" created on "server1" gfsh>create region --name=region2 --type=REPLICATE Member | Status ------- | -------------------------------------- server1 | Region "/region2" created on "server1" server2 | Region "/region2" created on "server2" server3 | Region "/region2" created on "server3"
注意到当缓存服务器(server1
和 server2,在本例中
)启动时region1指定了组名为group1
被创建
在所有的缓存服务器中。region2被创建在所有成员中,因为没有指定组名。
6.部署jar文件。使用gfsh布署命令来布署应用jar文件到所有的成员或到一个指定的组成员。如下的例子从Pivotal GemFire分布式第统中布署mail.jar和mx4j.jar文件。(注意:这只是一个例子,你没有必要使用集群配置服务布署这些文件。或者,您可以使用任何两个jar文件用于此演示)。
gfsh>deploy --group=group1 --jar=${SYS_GEMFIRE_DIR}/lib/mail.jar Post substitution: deploy --group=group1 --jar=/Users/username/Pivotal_GemFire_810_b50582_Linux/lib/mail.jar Member | Deployed JAR | Deployed JAR Location ------- | ------------ | ------------------------------------------------- server1 | mail.jar | /Users/username/my_gemfire/server1/vf.gf#mail.jar#1 server2 | mail.jar | /Users/username/my_gemfire/server2/vf.gf#mail.jar#1 gfsh>deploy --jar=${SYS_GEMFIRE_DIR}/lib/mx4j.jar Post substitution: deploy --jar=/Users/username/Pivotal_GemFire_810_b50582_Linux/lib/mx4j.jar Member | Deployed JAR | Deployed JAR Location ------- | ------------ | ------------------------------------------------- server1 | mx4j.jar | /Users/username/my_gemfire/server1/vf.gf#mx4j.jar#1 server2 | mx4j.jar | /Users/username/my_gemfire/server2/vf.gf#mx4j.jar#1 server3 | mx4j.jar | /Users/username/my_gemfire/server3/vf.gf#mx4j.jar#1
注意到mail.jar只布署到了
group1组成员中而
mx4j.jar布署到了所有成员中。
7.导出集群配置。你可以使用gfsh命令导出集群配置来创建一个包括集群配置的zip文件。这个zip文件包括了
cluster_config
目录中的内容考贝。例如:
gfsh>export cluster-configuration --zip-file-name=myClusterConfig.zip --dir=/Users/username
Apache Geode会把集群配置写到指定的zip文件中
Downloading cluster configuration : /Users/username/myClusterConfig.zip
剩余部份内容演示如何使用你创建的集群配置
8.用如下命令关闭集群
gfsh>shutdown --include-locators=true As 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): Y Shutdown is triggered gfsh> No longer connected to 192.0.2.0[1099]. gfsh>
9.退出gfsh命令
gfsh>quit Exiting...
10.创建工作目录 (例如: new_gemfire
) 并切换到新的目录。
11.启动gfsh
$ gfsh
12.启动一个新定位器,例如
gfsh>start locator --name=locator2 --port=10335 Starting a GemFire Locator in /Users/username/new_gemfire/locator2... ............................. Locator in /Users/username/new_gemfire/locator2 on 192.0.2.0[10335] as locator2 is currently online. Process ID: 5749 Uptime: 15 seconds GemFire Version: 8.1.0 Java Version: 1.7.0_71 Log File: /Users/username/new_gemfire/locator2/locator2.log JVM 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=9223372036854775806 Class-Path: /Users/username/Pivotal_GemFire_810_b50582_Linux/lib/gemfire.jar :/Users/username/Pivotal_GemFire_810_b50582_Linux/lib/locator-dependencies.jar Successfully connected to: [host=192.0.2.0, port=1099] Cluster configuration service is up and running.
13.使用import cluster-configuration命令导入集群配置,例如
gfsh>import cluster-configuration --zip-file-name=/Users/username/myClusterConfig.zip Cluster configuration successfully imported
注意到 locator2
目录现在包括了 cluster_config
子目录。
14.不引用组启动一个服务器
gfsh>start server --name=server4 --server-port=40414 Starting a GemFire Server in /Users/username/new_gemfire/server4... ........ Server in /Users/username/new_gemfire/server4 on 192.0.2.0[40414] as server4 is currently online. Process ID: 5813 Uptime: 4 seconds GemFire Version: 8.1.0 Java Version: 1.7.0_71 Log File: /Users/username/new_gemfire/server4/server4.log JVM Arguments: -Dgemfire.default.locators=192.0.2.0[10335] -Dgemfire.use-cluster-configuration=true -XX:OnOutOfMemoryError=kill -KILL %p -Dgemfire.launcher.registerSignalHandlers=true -Djava.awt.headless=true -Dsun.rmi.dgc.server.gcInterval=9223372036854775806 Class-Path: /Users/username/Pivotal_GemFire_810_b50582_Linux/lib/gemfire.jar :/Users/username/Pivotal_GemFire_810_b50582_Linux/lib/server-dependencies.jar
15.引用group1
组启动服务器
gfsh>start server --name=server5 --group=group1 --server-port=40415 Starting a GemFire Server in /Users/username/new_gemfire/server5... ..... Server in /Users/username/new_gemfire/server2 on 192.0.2.0[40415] as server5 is currently online. Process ID: 5954 Uptime: 2 seconds GemFire Version: 8.1.0 Java Version: 1.7.0_71 Log File: /Users/username/new_gemfire/server5/server5.log JVM Arguments: -Dgemfire.default.locators=192.0.2.0[10335] -Dgemfire.groups=group1 -Dgemfire.use-cluster-configuration=true -XX:OnOutOfMemoryError=kill -KILL %p -Dgemfire.launcher.registerSignalHandlers=true -Djava.awt.headless=true -Dsun.rmi.dgc.server.gcInterval=9223372036854775806 Class-Path: /Users/username/Pivotal_GemFire_810_b50582_Linux/lib/gemfire.jar :/Users/username/Pivotal_GemFire_810_b50582_Linux/lib/server-dependencies.jar
16.使用list regions命令显示已配置的区域。注意到
被配置为原始的集群级别的region1 和 region2是可用的。
gfsh>list regions List of regions --------------- region1 region2
17.使用describe region命令来查看每个区域属于哪个成员。注意到
region1仅属于server5因为server5启动时使用了group1配置。region2属于server4 和 server5,因为region2创建时没有指定组。
gfsh>describe region --name=region1 .......................................................... Name : region1 Data Policy : replicate Hosting Members : server5 Non-Default Attributes Shared By Hosting Members Type | Name | Value ------ | ---- | ----- Region | size | 0 gfsh>describe region --name=region2 .......................................................... Name : region2 Data Policy : replicate Hosting Members : server5 server4 Non-Default Attributes Shared By Hosting Members Type | Name | Value ------ | ---- | ----- Region | size | 0
这个集群使用了与最初的系统一样的配置。你可以使用这个配置启动任何一个成员。所有的服务器都会收到集群级别的配置。 被指定为group1的服务器也会收到group1的配置。
18.用以下命令停止集群。
gfsh>shutdown --include-locators=true As 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): Y Shutdown is triggered gfsh> No longer connected to 192.0.2.0[1099].
上一篇: 单据套打类报表的设计要点
下一篇: java密码复杂度正则表达式