Apache Geode in 15 Minutes or Less

–>

Apache Geode in 15 Minutes or Less

Need a quick introduction to Apache Geode? Take this brief tour to try out basic features and functionality.
需要快速介绍 Apache Geode 吗?参加这个简短的教程, 尝试基本的特性和功能。

Step 1: Install Apache Geode

步骤1:安装 Apache Geode

See How to Install for instructions.
有关说明, 请参阅如何安装。

Step 2: Use gfsh to start a locator

步骤2:使用 gfsh 启动 locator

In a terminal window, use the gfsh command line interface to start up a locator. Apache Geode gfsh (pronounced “jee-fish”) provides a single, intuitive command-line interface from which you can launch, manage, and monitor Apache Geode processes, data, and applications. See gfsh.

在终端窗口中, 使用 gfsh 命令行界面启动定位器。Apache Geode gfsh (发音为 “jee-fish”) 提供了一个单一、直观的命令行界面, 您可以从中启动、管理和监视 Apache Geode 进程、数据和应用程序。见 gfsh。

The locator is a Geode process that tells new, connecting members where running members are located and provides load balancing for server use. A locator, by default, starts up a JMX Manager, which is used for monitoring and managing a Geode cluster. The cluster configuration service uses locators to persist and distribute cluster configurations to cluster members. See Running Geode Locator Processes and Overview of the Cluster Configuration Service.

locator 是一个位置编码过程, 它通知新的连接正在运行的成员所在的成员, 并为服务器提供负载平衡。默认情况下, 定位器启动 JMX 管理器, 该管理器用于监视和管理 Geode 群集。群集配置服务使用定位器来保留群集配置并将其分发到群集成员。请参阅运行 Geode Locator 进程和群集配置服务概述。

  1. Create a scratch working directory (for example, my_geode) and change directories into it. gfsh saves locator and server working directories and log files in this location.
    创建临时工作目录 (例如, my_ geode) 并将目录更改到其中。gfsh 将locator 和服务器工作目录和日志文件保存在此位置。
  2. Start gfsh by typing gfsh at the command line (or gfsh.bat if you are using Windows).
    通过在命令行中键入 gfsh (如果您使用的是 windows, 则键入 gfsh) 来启动 gfsh。
    _________________________     __
   / _____/ ______/ ______/ /____/ /
  / /  __/ /___  /_____  / _____  /
 / /__/ / ____/  _____/ / /    / /
/______/_/      /______/_/    /_/    1.8

Monitor and Manage Geode
gfsh>
  1. At the gfsh prompt, type the start locator command and specify a name for the locator:
    在 gfsh 提示符下, 键入启动定位器命令, 并指定定位器的名称:
gfsh>start locator --name=locator1
Starting a Geode Locator in /home/username/my_geode/locator1...
.................................
Locator in /home/username/my_geode/locator1 on ubuntu.local[10334] as locator1 is currently online.
Process ID: 3529
Uptime: 18 seconds
Geode Version: 1.8
Java Version: 1.8.0_121
Log File: /home/username/my_geode/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: /home/username/Apache_Geode_Linux/lib/geode-core-1.0.0.jar:
/home/username/Apache_Geode_Linux/lib/geode-dependencies.jar

Successfully connected to: JMX Manager [host=10.118.33.169, port=1099]

Cluster configuration service is up and running.

If you run start locator from gfsh without specifying the member name, gfsh will automatically pick a random member name. This is useful for automation.
如果在不指定成员名称的情况下从 gfsh start locator, gfsh 将自动选择随机成员名称。这对于自动化很有用。

Step 3: Start Pulse

步骤 3: 启动 Pulse

Start up the browser-based Pulse monitoring tool. Pulse is a Web Application that provides a graphical dashboard for monitoring vital, real-time health and performance of Geode clusters, members, and regions. See Geode Pulse.
启动基于浏览器的脉冲监控工具。pulse 是一个 web 应用程序, 它提供了一个图形仪表板, 用于监视 geode 群集、成员和区域的重要、实时运行状况和性能。请参阅Geode Pulse。

gfsh>start pulse

This command launches Pulse and automatically connects you to the JMX Manager running in the Locator. At the Pulse login screen, type in the default username admin and password admin.
此命令启动 Pulse 并自动将您连接到在 Locator 中运行的 JMX 管理器。在 Pulse 登录屏幕上, 键入默认的用户名 admin 和密码 admin。

The Pulse application now displays the locator you just started (locator1):
Pulse 应用程序现在显示您刚刚启动的 locator (locator1):

Step 4: Start a server

步骤4:启动服务

A Geode server is a process that runs as a long-lived, configurable member of a cluster. The Geode server is used primarily for hosting long-lived data regions and for running standard Geode processes such as the server in a client/server configuration. See Running Geode Server Processes.

Geode 服务是作为群集的长期、可配置成员运行的过程。Geode 服务器主要用于承载路由长期存活的数据 regions 和运行标准的 Geode 进程, 如客户端/服务器配置中的服务。请参阅运行 Geode 服务进程。

Start the cache server:
启动缓存服务器:

gfsh>start server --name=server1 --server-port=40411

This commands starts a cache server named “server1” on the specified port of 40411.
这个命令启动了命名为”service1″的缓存服务,端口指定为40411.

If you run start server from gfsh without specifying the member name, gfsh will automatically pick a random member name. This is useful for automation.
如果在不指定成员名称的情况下从 gfsh 运行 start server , gfsh 将自动选择随机成员名称。这对于自动化很有用。

Observe the changes (new member and server) in Pulse. Try expanding the distributed system icon to see the locator and cache server graphically.
观察 Pulse 中的更改 (新成员和服务)。尝试展开分布式系统图标, 以图形方式查看定位器和缓存服务器。

Step 5: Create a replicated, persistent region

步骤5:创建拷贝的持久 region

In this step you create a region with the gfsh command line utility. Regions are the core building blocks of the Geode cluster and provide the means for organizing your data. The region you create for this exercise employs replication to replicate data across members of the cluster and utilizes persistence to save the data to disk. See Data Regions.
在此步骤中, 您将使用 gfsh 命令行实用程序创建一个 region。region 是 Geode 集群的核心组成部分, 并提供了组织数据的方法。为此练习创建的区域使用复制在群集成员之间复制数据, 并利用持久性将数据保存到磁盘。请参阅Data Regions。

  1. Create a replicated, persistent region:
    创建拷贝的持久 region
gfsh>create region --name=regionA --type=REPLICATE_PERSISTENT
Member  | Status
------- | --------------------------------------
server1 | Region "/regionA" created on "server1"

Note that the region is hosted on server1.
请注意, region 位于server1上。

  1. Use the gfsh command line to view a list of the regions in the cluster.
    使用 gfsh 命令行查看群集中区域的列表。
gfsh>list regions
List of regions
---------------
regionA
  1. List the members of your cluster. The locator and cache server you started appear in the list:
    列出群集的成员,您开始的 locator 和缓存服务器将显示在列表中:
gfsh>list members
  Name       | Id
------------ | ---------------------------------------
Coordinator: | 192.0.2.0(locator1:3529:locator)<ec><v0>:59926
locator1     | 192.0.2.0(locator1:3529:locator)<ec><v0>:59926
server1      | 192.0.2.0(server1:3883)<v1>:65390
  1. To view specifics about a region, type the following:
    若要查看有关 region 的详细信息, 请键入以下内容:
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 | size | 0
  1. In Pulse, click the green cluster icon to see all the new members and new regions that you just added to your cluster.
    在 Pulse 中, 单击绿色群集图标以查看刚刚添加到群集的所有新成员和新 regions。

Note: Keep this gfsh prompt open for the next steps.
注意: 在接下来的步骤中保持此 gfsh 提示打开。

Step 6: Manipulate data in the region and demonstrate persistence

步骤6:操作 region 内的数据并演示持久性

Apache Geode manages data as key/value pairs. In most applications, a Java program adds, deletes and modifies stored data. You can also use gfsh commands to add and retrieve data. See Data Commands.

Apache Geode 将数据作为 key/value 对进行管理。在大多数应用程序中, Java 程序会添加、删除和修改存储的数据。您还可以使用 gfsh 命令来添加和检索数据。请参阅 Data Commands。

  1. Run the following put commands to add some data to the region:
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>
  1. Run the following command to retrieve data from the region:
    运行以下命令从该 region 检索数据:
gfsh>query --query="select * from /regionA"

Result     : true
startCount : 0
endCount   : 20
Rows       : 2

Result
------
two
one

Note that the result displays the values for the two data entries you created with the put commands.
请注意 结果显示使用 put 命令创建的两个数据项的值。
See Data Entries.

  1. Stop the cache server using the following command:
    关闭缓存服务的命令如下:
    gfsh>stop server --name=server1
Stopping Cache Server running in /home/username/my_geode/server1 on ubuntu.local[40411] as server1...
Process ID: 3883
Log File: /home/username/my_geode/server1/server1.log
...
  1. Restart the cache server using the following command:
    重启缓存服务器使用下面的命令:
gfsh>start server --name=server1 --server-port=40411
  1. Run the following command to retrieve data from the region again – notice that the data is still available:
    运行下面的命令从 region 再次建索数据 – 注意 数据依然存在:
gfsh>query --query="select * from /regionA"

Result     : true
startCount : 0
endCount   : 20
Rows       : 2

Result
------
two
one

Because regionA uses persistence, it writes a copy of the data to disk. When a server hosting regionA starts, the data is populated into the cache. Note that the result displays the values for the two data entries you created with the put commands prior to stopping the server.
因为 regionA 使用持久性, 所以它将数据的副本写入磁盘。当路由到 regionA 的服务器启动时, 数据将填充到缓存中。请注意, 结果显示在停止服务器之前使用 put 命令创建的两个数据项的值。
See Data Entries.
See Data Regions.

Step 7: Examine the effects of replication

步骤7: 检查复制的效果

In this step, you start a second cache server. Because regionA is replicated, the data will be available on any server hosting the region.
在此步骤中, 启动第二个缓存服务器。由于 regionA 被复制, 因此数据将在路由到此 region 的任何服务器上可用。

See Data Regions.

  1. Start a second cache server:
    启动第二个缓存服务器:

    gfsh>start server --name=server2 --server-port=40412
    
  2. Run the describe region command to view information about regionA:
    执行 describe region 命令显示 regionA 信息:
  gfsh>describe region --name=regionA
..........................................................
Name            : regionA
Data Policy     : persistent replicate
Hosting Members : server1
                  server2

Non-Default Attributes Shared By Hosting Members

Type   | Name | Value
------ | ---- | -----
Region | size | 2

Note that you do not need to create regionA again for server2. The output of the command shows that regionA is hosted on both server1 and server2. When gfsh starts a server, it requests the configuration from the cluster configuration service which then distributes the shared configuration to any new servers joining the cluster.
请注意, 您不需要为 server2 再次创建 regionA。该命令的输出显示 regionA 都托管在 server1 和 server2 上。当 gfsh 启动服务器时, 它会从群集配置服务请求配置, 然后将共享配置分发到加入群集的任何新服务器。

  1. Add a third data entry:
    添加第三个数据实体:
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>
  1. Open the Pulse application (in a Web browser) and observe the cluster topology. You should see a locator with two attached servers. Click the Data tab to view information about regionA.
    打开 pulse 应用程序 (在 web 浏览器中) 并观察群集拓扑。您应该会看到一个具有两个连接的服务器的定位器。单击 “Data” 选项卡以查看有关 regionA 的信息。

  2. Stop the first cache server with the following command:
    停止第一个缓存服务器,命令如下:

gfsh>stop server --name=server1
Stopping Cache Server running in /home/username/my_geode/server1 on ubuntu.local[40411] as server1...
Process ID: 4064
Log File: /home/username/my_geode/server1/server1.log
....
  1. Retrieve data from the remaining cache server.
    从剩余的缓存服务器检索数据。
gfsh>query --query="select * from /regionA"

Result     : true
startCount : 0
endCount   : 20
Rows       : 3

Result
------
two
one
three

Note that the data contains 3 entries, including the entry you just added…
请注意, 数据包含3个条目, 包括您刚刚添加的条目。

  1. Add a fourth data entry:
    添加第四条数据条目:
gfsh>put --region=regionA --key="4" --value="four"
Result      : true
Key Class   : java.lang.String
Key         : 3
Value Class : java.lang.String
Old Value   : <NULL>

Note that only server2 is running. Because the data is replicated and persisted, all of the data is still available. But the new data entry is currently only available on server 2.
请注意, 只有 server2 正在运行。由于数据是复制和保留的, 因此所有数据仍然可用。但新的数据条目目前仅在 server2 上可用。

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 | size | 4
  1. Stop the remaining cache server:
    停止剩余的缓存服务:
gfsh>stop server --name=server2
Stopping Cache Server running in /home/username/my_geode/server2 on ubuntu.local[40412] as server2...
Process ID: 4185
Log File: /home/username/my_geode/server2/server2.log
.....

Step 8: Restart the cache servers in parallel

步骤 8: 并行重新启动缓存服务器

In this step you restart the cache servers in parallel. Because the data is persisted, the data is available when the servers restart. Because the data is replicated, you must start the servers in parallel so that they can synchronize their data before starting.
在此步骤中, 您将并行重新启动缓存服务器。由于数据是持久化的, 因此当服务器重新启动时, 数据可用。由于数据是复制的, 因此必须并行启动服务器, 以便它们可以在启动前同步数据。

gfsh>start server --name=server1 --server-port=40411
Starting a Geode Server in /home/username/my_geode/server1...
............................................................................
............................................................................

Note that if you look in the server1.log file for the restarted server, you will see a log message similar to the following:
请注意, 如果您在 server1.log 文件中查找重新启动的服务器, 您将看到类似于以下内容的日志消息:

[info 2015/01/14 09:08:13.610 PST server1 <main> tid=0x1] Region /regionA has pot
entially stale data. It is waiting for another member to recover the latest data.
  My persistent id:

    DiskStore ID: 8e2d99a9-4725-47e6-800d-28a26e1d59b1
    Name: server1
    Location: /192.0.2.0:/home/username/my_geode/server1/.

  Members with potentially new data:
  [
    DiskStore ID: 2e91b003-8954-43f9-8ba9-3c5b0cdd4dfa
    Name: server2
    Location: /192.0.2.0:/home/username/my_geode/server2/.
  ]
  Use the "gfsh show missing-disk-stores" command to see all disk stores that
are being waited on by other members.
  1. In a second terminal window, change directories to the scratch working directory (for example, my_geode) and start gfsh:
    在第二个终端,将目录更改为临时工作目录(如: my_geode),然后start gfsh:
[[email protected] ~/my_geode]$ gfsh
    _________________________     __
   / _____/ ______/ ______/ /____/ /
  / /  __/ /___  /_____  / _____  /
 / /__/ / ____/  _____/ / /    / /
/______/_/      /______/_/    /_/    1.8

Monitor and Manage Geode
  1. Run the following command to connect to the cluster:
    执行下面的命令连接集群:
gfsh>connect --locator=localhost[10334]
Connecting to Locator at [host=localhost, port=10334] ..
Connecting to Manager at [host=ubuntu.local, port=1099] ..
Successfully connected to: [host=ubuntu.local, port=1099]
  1. Start server2:
gfsh>start server --name=server2 --server-port=40412

hen server2 starts, note that server1 completes its start up in the first gfsh window:
当 server2 启动时, 请注意 server1 在第一个 gfsh 窗口中完成其启动:

Server in /home/username/my_geode/server1 on ubuntu.local[40411] as server1 is currently online.
Process ID: 3402
Uptime: 1 minute 46 seconds
Geode Version: 1.8
Java Version: 1.8.0_121
Log File: /home/username/my_geode/server1/server1.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: /home/username/Apache_Geode_Linux/lib/geode-core-1.0.0.jar:
/home/username/Apache_Geode_Linux/lib/geode-dependencies.jar
  1. Verify that the locator and two servers are running:
    检查 locator 和 两个服务在运行:
gfsh>list members
  Name       | Id
------------ | ---------------------------------------
Coordinator: | ubuntu(locator1:2813:locator)<ec><v0>:46644
locator1     | ubuntu(locator1:2813:locator)<ec><v0>:46644
server2      | ubuntu(server2:3992)<v8>:21507
server1      | ubuntu(server1:3402)<v7>:36532
  1. Run a query to verify that all the data you entered with the put commands is available:
    运行查询以验证使用 put 命令输入的所有数据是否可用:
gfsh>query --query="select * from /regionA"

Result     : true
startCount : 0
endCount   : 20
Rows       : 5

Result
------
one
two
four
Three

NEXT_STEP_NAME : END
  1. Stop server2 with the following command:
    关闭 server2:
gfsh>stop server --dir=server2
Stopping Cache Server running in /home/username/my_geode/server2 on 192.0.2.0[40412] as server2...
Process ID: 3992
Log File: /home/username/my_geode/server2/server2.log
....
  1. Run a query to verify that all the data you entered with the put commands is still available:
    运行查询以验证使用 put 命令输入的所有数据是否仍然可用:
gfsh>query --query="select * from /regionA"

Result     : true
startCount : 0
endCount   : 20
Rows       : 5

Result
------
one
two
four
Three

NEXT_STEP_NAME : END

Step 9: Shut down the system including your locators

步骤9 关闭系统 (包括定位器)

To shut down your cluster, do the following:
要关闭群集, 请执行以下操作:

  1. In the current gfsh session, stop the cluster:
    在当前会话,关闭集群:
gfsh>shutdown --include-locators=true
  1. When prompted, type ‘Y’ to confirm the shutdown of the cluster.
    出现提示时, 键入 “Y” 以确认群集的关闭。
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 ubuntu.local[1099].
gfsh>
  1. Type exit to quit the gfsh shell.
    输入 exit 离开 gfsh。

Step 10: What to do next…

步骤10:下一步做什么…

以下是有关 Apache Geode 下一步要探讨的内容的一些建议:
继续阅读下一节, 了解有关刚刚介绍的组件和概念的更多信息。
若要使用 gfsh 进行更多练习, 请参阅教程-使用 gfsh 执行常见任务。
若要了解群集配置服务, 请参阅教程-创建和使用群集配置。

本文来源 互联网收集,文章内容系作者个人观点,不代表 本站 对观点赞同或支持。如需转载,请注明文章来源,如您发现有涉嫌抄袭侵权的内容,请联系本站核实处理。

© 版权声明

相关文章