分布式成员配置
分布式系统成员(Members): 是连接到Geode分布式系统的程序。可以配置成员属于单一的分布系统,也可以配置为分布系统的clients 或 servers 并与其它分布系统进行通信。
数据成员在创建高速缓存时连接到Geode系统。通过配置属性配置分布式系统。参考gemfire_properties Geode属性定义了相关成员的初使属性,包括启动,初使化,通信的初使值。 *当成员已经连接到分布式系统后成员的这些属性不能再被修改了。
通过属性可以定义:
1.如何查找并和其它系统成员通信
2.如何做日志和统计活动
3.配置使用哪个持久化配置和cache.xml文件初使化cache和region
4.其它事件如网络丢失处理,安全设置等。
分布式系统拓扑
每一个Goede进程为一个分布式系统成员。
参考:Topology and Communication General Concepts.
Peer-to-Peer 分布式系统:成员属性同一个分布系统。
Client/Server拓扑:指配置多个分布式系统之间成员关系。配置一个分布式系统中全部或部分成员作为从外部连接的客户端的缓存服务器。每一个服务器可以管理许多客户端,以高效,垂直的分层缓存配置来管理所有的缓存访问。可以使用客户端缓存配置来配置客户端应用程序连接。客户端作为独立Geode分布式系统的成员运行,没有对等体,所以所有数据更新和请求都转到服务器。
多站点安装
多站点拓扑使用您在多个分布式系统的成员之间配置的关系。通过此配置,您可以松散耦合两个或更多分布式系统进行自动数据分发。这通常是针对地理位置上的网站进行的。您可以使用网关发送者和/或网关接收器配置每个分布式系统站点中的对等体的子集,以管理在站点之间分布的事件。
在单个分布式系统的上下文中,除非另有说明,否则远程成员引用相同分布式系统的其他成员。在客户端/服务器和多站点安装中,远程通常是指其他分布式系统中的成员。例如,所有服务器都远程连接到它们的客户端。每个客户端独立运行,仅连接到服务器层,所以所有服务器及其他客户端都远离个人客户端。所有网关接收器都远离与其他分布式系统连接的网关发送者以及那些网关发送者的对等体。
属性配置
Geode提供一个默认的开箱即用的系统配置。我们也自定义这些分布式系统配置。
Geode properties用于定义连接分布式及系统成员的行为。通过修改gemfire.properties文件,或Java API,或命令行的方式可以修改配置。通常所有的配置会保存在gemfire.properties文件中。
*通过API修改gemfire.properties和gfsecurity.properties,所做的任何更改都会覆盖在命令行或配置文件中设置的properties。 defaultConfigs目录具有gemfire.properties所有默认设置的示例文件。
可以通过以下任何方式设置属性,系统按照下列顺序查找设置
1. Java.lang.System property settion 通常设置在命令行,对于应用程序设置这些在代码或命令行 a) 以API方式,在创建cache之前执行。 System.setProperty(“gemfireProperty”,”gfTest”); System.setProperty(“gemfire.mcast-port”,”10999”); Cache cache = new CacheFactory().create(); b) Java命令行方式,使--D Java --DgemfirePropertyFile=gfTest --Dgemfire.mcast-port=10999 test.Program 2. 写入Properties配置文件 a) API方式,创建一个Properties对象并传入创建cache的方法 Properties properties = new Properties(); properties.setProperty(“log-level”,”warninig”); properties.setProperty(“name”,”testMember”); ClientCache cache = new ClientCacheFactory(properties).create(); b) gfsh命令行方 gfsh> start server --name=server_name --mcast-port=10338 --porperties-file=serverConfig/gemfire.properties --security-properties-file=gfsecurity.properties 3. gemfire.properties配置文件 4. 默认值。默认值在API中定义 org.apache.geode.distributed.ConfigurationProperties。
配置缓存和数据分区选项
通过定义缓存数据分区并为之提供自定义的配置去管理和调整缓存的存储和分发行为。
缓存配置属性定义:
1. Cache-wide 设置,如disk stores、连接超时和将该成员指定为服务器的设置
2. 缓存数据区域
配置cache缓存和数据分区方式:
1. 通过命令行方式定义配置,gfsh 支持Geode进程和应用程序的管理,调试和部署。如配置regions,locators,servers,disk stores,queues等其它内容。
2. 通过gemfire.properties配置中cache-xm-file指定的xml文件中定义。该文件可以自定为任何名称。但通常称为cache.xml。
3. 通过org.apache.geode.cache.CacheFactory,org.apache.geode.geode.cache.Cache和org.apache.geode.cache.Region APIs定义
缓存管理
Cache提供了基于内存的数据存储和管理
每一个data regions都可以独立配置。数据是以键/值对(key/value)的形式存于regions中的。Cache还提供了事物,数据查询,磁盘存储管理和日志记录等功能。参考Javadoc中org.apache.geode.cache.Cache.
可以通过命令行或XML文件或API的形式配置cache。当第一次创建cache的时候 会加载XML中的配置 。
Geode具有一种用于管理服务器和对等缓存的缓存类型,一个用于管理客户端缓存。缓存服务器进程在启动时自动创建其服务器缓存。在应用程序进程中,缓存创建返回server/peer或客户端缓存的实例。可以通过应用程序中的API调用来管理缓存。
Caching APIs
Geode caching API 提供不同成员类型的安全和行为设置
1. org.apache.geode.cache.RegionService
2.org.apache.geode.cache.GemFireCache
3.org.apache.goede.cache.Cache
4.Org.apache.geode.setting_cache_initializer.cache.ClientCache
缓存XMl
cache.xml必须符合cache-1.0.xsd的定义。
cache.xml for Peer/Server:
<?xml version="1.0" encoding="UTF-8"?> <cache xmlns="http://geode.apache.org/schema/cache" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://geode.apache.org/schema/cache http://geode.apache.org/schema/cache/cache-1.0.xsd" version="1.0”> ... </cache>
cache.xml for Client:
<?xml version="1.0" encoding="UTF-8"?> <client-cache xmlns="http://geode.apache.org/schema/cache" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://geode.apache.org/schema/cache http://geode.apache.org/schema/cache/cache-1.0.xsd" version="1.0”> ... </client-cache>
创建和关闭Cache
当启动成员进程和创建成员缓存时会初使化系统配置及cache配置 。如果使用集群配置服务,成员进程会应用当前locator或group的配置。
管理Peer or Server Cache
1. 创建cache a. 创建集群和集群配置服务 a) 启动一个使用集群配置服务的locator (--enable-cluster-configuration默认为true) Gfsh> start locator --name=locator1 b) 启动server成员 Gfsh > start server –name=server1 –server-port=40404 c) 创建regions Gfsh > create region –name=customerRegoin –type=REPLICATE Gfsh> create region –name=ordersRegion –type=PARTITION b. 使用cache.xml 配置 <?xml version="1.0" encoding="UTF-8"?> <cache xmlns="http://geode.apache.org/schema/cache" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://geode.apache.org/schema/cache http://geode.apache.org/schema/cache/cache-1.0.xsd" version="1.0”> // NOTE: Use this <cache-server> element only for server processes <cache-server port="40404"/> <region name="customerRegion" refid="REPLICATE" /> <region name="ordersRegion" refid="PARTITION" /> </cache> c. 以编程方式创建Cache 实例: a) 在Java程序中使用CacheFactory Cache cache = new CacheFacotry().create(); b) 如果使用Geode cacheServer运行系统,会在起动时依照gemfire.properties和cache.xml的定义创建分布式系统连接和初使化cache。并在退出时半闭。 2. 关闭cache cache.close()
管理客户端缓存(ClientCache)
Geode自动将ClientCache设置为独立的。Client cache 没有peers,不需要设置gemfire.properties、mcast-port 或locators.
1. 创建client cache a. 在cache.xml中使用client-cache DOCTYPET,并在<client-cache>中配置连接池和regions等。 <?xml version="1.0" encoding="UTF-8"?> <client-cache xmlns="http://geode.apache.org/schema/cache" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://geode.apache.org/schema/cache http://geode.apache.org/schema/cache/cache-1.0.xsd" version="1.0"> <pool name="serverPool"> <locator host="host1" port="44444"/> </pool> <region name="exampleRegion" refid="PROXY"/> </client-cache> *可以通过设置region的 concurrency-checks-enabled为false,查看该region的所有事件。Server members可以继续使用并发检 查,但会传入所有事件到该client cache. 该配置确保clients看到所有region事件,但不能避免客户端缓存区域和服务器缓存失去同步。 ??? b. 如果使用多个服务器连接池,请为每个客户端区域显示配置连接池名称: <pool name="svrPool1"> <locator host="host1" port="40404"/> </pool> <pool name="svrPool2"> <locator host="host2" port="40404"/> </pool> <region name="clientR1" refid="PROXY" pool-name="svrPool1"/> <region name="clientR2" refid="PROXY" pool-name="svrPool2"/> <region name="clientsPrivateR" refid="LOCAL"/> c. 在Java客户端应用程序中,使用ClientCacheFactory create方法创建cache,依照gemfire.properties和cache.xml的定义创建分布式系统连接和初使化cache。 ClientCache cliencCache = new ClientCacheFactory().create(); 2. 关闭client cache cache.close() * 如果您的客户端是持久的,并且您希望在客户端缓存关闭时维护持久队列,请使用:??? cache.close(true);
管理带身份验证的缓存
带密码的缓存在建立连接时进行身份验证,授权操作配置。
1. 创建缓存 a) 添加需要的安全属性到gemfire.properties 或 gfsecurity.properties文件, security-client-auth-init=mySecurity.UserPasswordAuthInit.create security-peer-auth-init=myAuthPkg.myAuthInitImpl.create b) 创建缓存时,请使用以下方法之一将安全实现所需的属性传递到缓存工厂创建调用 i. ClientCacheFactory or CacheFacotyr set 方法 ClientCache clientCache = new ClientCacheFactory() .set("security-username", username) .set("security-password", password) .create(); ii. Properties对象中传入ClientCacheFactory or CacheFacotory create 方法。 Properties传入的值会覆盖gemfire.properties和gfsecurity.properties的配置。 Properties properties = new Properties(); properties.setProperty("security-username", username); properties.setProperty("security-password", password); Cache cache = new CacheFactory(properties).create(); 2. 关闭缓存 cache.close()