安装方法可以参照《Ubuntu 16.04上从源码构建安装Apache Geode 1.8》。
1.创建工作目录
root@ubuntu:/opt# mkdir my_geode
root@ubuntu:/opt# cd my_geode
2.在命令行输入gfsh启动gfsh
rain@ubuntu:/opt/my_geode$ gfsh
_________________________ __
/ _____/ ______/ ______/ /____/ /
/ / __/ /___ /_____ / _____ /
/ /__/ / ____/ _____/ / / / /
/______/_/ /______/_/ /_/ 1.8.0
Monitor and Manage Apache Geode
3.在gfsh提示符下,键入start locator命令并指定locator的名称:
---------------
gfsh>start locator --name=locator1
Starting a Geode Locator in /opt/my_geode/locator1...
...........
Locator in /opt/my_geode/locator1 on orderer.example.com[10334] as locator1 is currently online.Process ID: 7776Uptime: 12 secondsGeode Version: 1.8.0Java Version: 1.8.0_144Log File: /opt/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: /opt/apache-geode-1.8.0/lib/geode-core-1.8.0.jar:/opt/apache-geode-1.8.0/lib/geode-dependencies.jar
Successfully connected to: JMX Manager [host=orderer.example.com, port=1099]
Cluster configuration service is up and running.
启动基于浏览器的Pulse监测工具。Pulse是一个Web应用程序,它提供了一个图形化仪表板,用于监视重要的、实时的Geode集群、成员和区域的健康状况和性能。
gfsh>start pulse
Launched Geode Pulse
访问地址:http://localhost:7070/pulse/login.html
用户名和密码默认都是:admin
启动缓存server:
gfsh>start server --name=server1 --server-port=40411
Starting a Geode Server in /opt/my_geode/server1...
.......
Server in /opt/my_geode/server1 on orderer.example.com[40411] as server1 is currently online.Process ID: 8077Uptime: 7 secondsGeode Version: 1.8.0Java Version: 1.8.0_144Log File: /opt/my_geode/server1/server1.logJVM Arguments: -Dgemfire.default.locators=192.168.108.132[10334] -Dgemfire.start-dev-rest-api=false -Dgemfire.use-cluster-configuration=true -XX:OnOutOfMemoryError=kill -KILL %p -Dgemfire.launcher.registerSignalHandlers=true -Djava.awt.headless=true -Dsun.rmi.dgc.server.gcInterval=9223372036854775806Class-Path: /opt/apache-geode-1.8.0/lib/geode-core-1.8.0.jar:/opt/apache-geode-1.8.0/lib/geode-dependencies.jar
gfsh>
1.创建一个复制的、持久的区域
gfsh>create region --name=regionA --type=REPLICATE_PERSISTENT
Member | Status
------- | --------------------------------------
server1 | Region "/regionA" created on "server1"
2.使用gfsh命令行查看集群中的region列表
gfsh>list regions
List of regions
---------------
regionA
3.列出集群的成员。您启动的locator和缓存server将出现在列表中:
gfsh>list members
Name | Id
-------- | ------------------------------------------------------------------
locator1 | 192.168.100.132(locator1:7776:locator):41000 [Coordinator]
server1 | 192.168.100.132(server1:8077):41001
4.要查看有关区域的详细信息,请键入以下命令:
gfsh>describe region --name=regionA
..........................................................
Name : regionA
Data Policy : persistent replicate
Hosting Members : server1
Non-Default Attributes Shared By Hosting Members
Type | Name | Value
------ | ----------- | --------------------
Region | data-policy | PERSISTENT_REPLICATE
| size | 0
| scope | distributed-ack
5.刷新Pulse仪表盘,可以看到新添加的内容。
1.运行以下put命令向区域添加一些数据:
gfsh>put --region=regionA --key="1" --value="one"
Result : true
Key Class : java.lang.String
Key : 1
Value Class : java.lang.String
Old Value : null
gfsh>put --region=regionA --key="2" --value="two"
Result : true
Key Class : java.lang.String
Key : 2
Value Class : java.lang.String
Old Value : null
2.运行以下命令从区域检索数据:
gfsh>query --query="select * from /regionA"
Result : true
Limit : 100
Rows : 2
Result
------
two
one
3.使用以下命令停止缓存服务器:
gfsh>stop server --name=server1
Stopping Cache Server running in /opt/my_geode/server1 on orderer.example.com[40411] as server1...
Process ID: 8077
Log File: /opt/my_geode/server1/server1.log
...
gfsh>
4.使用以下命令重启缓存服务器:
gfsh>start server --name=server1 --server-port=40411
Starting a Geode Server in /opt/my_geode/server1...
........
Server in /opt/my_geode/server1 on orderer.example.com[40411] as server1 is currently online.Process ID: 8707Uptime: 8 secondsGeode Version: 1.8.0Java Version: 1.8.0_144Log File: /opt/my_geode/server1/server1.logJVM Arguments: -Dgemfire.default.locators=192.168.108.132[10334] -Dgemfire.start-dev-rest-api=false -Dgemfire.use-cluster-configuration=true -XX:OnOutOfMemoryError=kill -KILL %p -Dgemfire.launcher.registerSignalHandlers=true -Djava.awt.headless=true -Dsun.rmi.dgc.server.gcInterval=9223372036854775806Class-Path: /opt/apache-geode-1.8.0/lib/geode-core-1.8.0.jar:/opt/apache-geode-1.8.0/lib/geode-dependencies.jar
gfsh>
5.再次运行以下命令从区域检索数据-请注意数据仍然可用:
gfsh>query --query="select * from /regionA"
Result : true
Limit : 100
Rows : 2
Result
------
two
one
启动第二个缓存服务器。因为regionA是复制的,所以数据可以在任何承载该区域的服务器上使用。
1.启动第二个缓存服务器:
gfsh>start server --name=server2 --server-port=40412
Starting a Geode Server in /opt/my_geode/server2...
........
Server in /opt/my_geode/server2 on orderer.example.com[40412] as server2 is currently online.Process ID: 8857Uptime: 8 secondsGeode Version: 1.8.0Java Version: 1.8.0_144Log File: /opt/my_geode/server2/server2.logJVM Arguments: -Dgemfire.default.locators=192.168.108.132[10334] -Dgemfire.start-dev-rest-api=false -Dgemfire.use-cluster-configuration=true -XX:OnOutOfMemoryError=kill -KILL %p -Dgemfire.launcher.registerSignalHandlers=true -Djava.awt.headless=true -Dsun.rmi.dgc.server.gcInterval=9223372036854775806Class-Path: /opt/apache-geode-1.8.0/lib/geode-core-1.8.0.jar:/opt/apache-geode-1.8.0/lib/geode-dependencies.jar
gfsh>
2.运行description region命令查看关于regionA的信息:
gfsh>describe region --name=regionA
..........................................................
Name : regionA
Data Policy : persistent replicate
Hosting Members : server2
server1
Non-Default Attributes Shared By Hosting Members
Type | Name | Value
------ | ----------- | --------------------
Region | data-policy | PERSISTENT_REPLICATE
| size | 2
| scope | distributed-ack
gfsh>
3.添加第三个数据项:
gfsh>put --region=regionA --key="3" --value="three"
Result : true
Key Class : java.lang.String
Key : 3
Value Class : java.lang.String
Old Value : null
gfsh>
4.打开Pulse仪表盘观察内容变化
5.用以下命令停止第一个缓存服务器:
gfsh>stop server --name=server1
Stopping Cache Server running in /opt/my_geode/server1 on orderer.example.com[40411] as server1...
Process ID: 11425
Log File: /opt/my_geode/server1/server1.log
...
gfsh>
6.从剩余的缓存服务器检索数据:
gfsh>query --query="select * from /regionA"
Result : true
Limit : 100
Rows : 3
Result
------
two
one
three
7.添加第四个数据项:
gfsh>put --region=regionA --key="4" --value="four"
Result : true
Key Class : java.lang.String
Key : 4
Value Class : java.lang.String
Old Value : null
gfsh>
注意,只有server2在运行。因为数据是复制和持久的,所以所有数据仍然可用。但是新的数据条目目前仅在服务器2上可用。
gfsh>describe region --name=regionA
..........................................................
Name : regionA
Data Policy : persistent replicate
Hosting Members : server2
Non-Default Attributes Shared By Hosting Members
Type | Name | Value
------ | ----------- | --------------------
Region | data-policy | PERSISTENT_REPLICATE
| size | 4
| scope | distributed-ack
gfsh>
8.停止剩余的缓存服务器:
gfsh>stop server --name=server2
Stopping Cache Server running in /opt/my_geode/server2 on orderer.example.com[40412] as server2...
Process ID: 11558
Log File: /opt/my_geode/server2/server2.log
...
gfsh>
并行重启缓存服务器。因为数据是持久的,所以当服务器重启时数据是可用的。由于数据是复制的,所以必须并行启动服务器,以便服务器在启动前同步它们的数据。
1.启动server1。由于regionA是复制和持久化的,需要另一台服务器的启动数据,并等待服务器启动:
gfsh>start server --name=server1 --server-port=40411
Starting a Geode Server in /opt/my_geode/server1...
.................................................................................................................................................................................
2.重新打开一个终端窗口,将目录更改为scratch工作目录(例如my_geode),并启动gfsh:
rain@ubuntu:/opt/my_geode$ gfsh
_________________________ __
/ _____/ ______/ ______/ /____/ /
/ / __/ /___ /_____ / _____ /
/ /__/ / ____/ _____/ / / / /
/______/_/ /______/_/ /_/ 1.8.0
Monitor and Manage Apache Geode
gfsh>
3.运行以下命令连接到集群:
gfsh>connect --locator=localhost[10334]
Connecting to Locator at [host=localhost, port=10334] ..
Connecting to Manager at [host=orderer.example.com, port=1099] ..
Successfully connected to: [host=orderer.example.com, port=1099]
gfsh>
4.启动server2:
gfsh>start server --name=server2 --server-port=40412
Starting a Geode Server in /opt/my_geode/server2...
........
Server in /opt/my_geode/server2 on orderer.example.com[40412] as server2 is currently online.Process ID: 12310Uptime: 10 secondsGeode Version: 1.8.0Java Version: 1.8.0_144Log File: /opt/my_geode/server2/server2.logJVM Arguments: -Dgemfire.default.locators=192.168.108.132[10334] -Dgemfire.start-dev-rest-api=false -Dgemfire.use-cluster-configuration=true -XX:OnOutOfMemoryError=kill -KILL %p -Dgemfire.launcher.registerSignalHandlers=true -Djava.awt.headless=true -Dsun.rmi.dgc.server.gcInterval=9223372036854775806Class-Path: /opt/apache-geode-1.8.0/lib/geode-core-1.8.0.jar:/opt/apache-geode-1.8.0/lib/geode-dependencies.jar
gfsh>
当server2启动时,注意server1在第一个gfsh窗口中完成启动:
gfsh>start server --name=server1 --server-port=40411
Starting a Geode Server in /opt/my_geode/server1...
...................................................................................................................................................................................................................................................................
Server in /opt/my_geode/server1 on orderer.example.com[40411] as server1 is currently online.Process ID: 11875Uptime: 6 minutes 28 secondsGeode Version: 1.8.0Java Version: 1.8.0_144Log File: /opt/my_geode/server1/server1.logJVM Arguments: -Dgemfire.default.locators=192.168.108.132[10334] -Dgemfire.start-dev-rest-api=false -Dgemfire.use-cluster-configuration=true -XX:OnOutOfMemoryError=kill -KILL %p -Dgemfire.launcher.registerSignalHandlers=true -Djava.awt.headless=true -Dsun.rmi.dgc.server.gcInterval=9223372036854775806Class-Path: /opt/apache-geode-1.8.0/lib/geode-core-1.8.0.jar:/opt/apache-geode-1.8.0/lib/geode-dependencies.jar
gfsh>
5.确认locator和两台server正在运行:
gfsh>list members
Name | Id
-------- | -------------------------------------------------------------------
locator1 | 192.168.108.132(locator1:11301:locator):41000 [Coordinator]
server1 | 192.168.108.132(server1:11875):41001
server2 | 192.168.108.132(server2:12310):41002
gfsh>
6.运行查询以验证你使用put命令输入的所有数据是否可用:
gfsh>query --query="select * from /regionA"
Result : true
Limit : 100
Rows : 4
Result
------
two
one
three
four
gfsh>
7.用以下命令停止server2:
gfsh>stop server --dir=server2
Stopping Cache Server running in /opt/my_geode/server2 on orderer.example.com[40412] as server2...
Process ID: 12310
Log File: /opt/my_geode/server2/server2.log
.....
gfsh>
8.运行查询以验证你使用put命令输入的所有数据仍然可用:
gfsh>query --query="select * from /regionA"
Result : true
Limit : 100
Rows : 4
Result
------
two
one
three
four
gfsh>
要关闭集群,请执行以下操作:
1.在当前gfsh会话中,停止集群:
gfsh>shutdown --include-locators=true
2.当提示时,键入“Y”确认集群已关闭。
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 orderer.example.com[1099].
gfsh>
3.键入exit退出gfsh shell。
start locator --name=locator1
start pulse
start server --name=server1 --server-port=40411
start server --name=server2 --server-port=40412
create region --name=regionA --type=REPLICATE_PERSISTENT
put --region=regionA --key="1" --value="one"
put --region=regionA --key="2" --value="two"
query --query="select * from /regionA"
describe region --name=regionA
shutdown --include-locators=true
参照官网:
http://geode.apache.org/docs/guide/18/getting_started/15_minute_quickstart_gfsh.html