Apache Geode 运行定位器进程

        定位器是一个Geode进程,它告诉新连接进来的成员正在运行的成员位置并为服务器提供负载均衡。

        你可以将定位器作为对等的定位器运行,也可以作为服务器定位器运行,或是两者一起:

  • 在定位器的分布式系统中,对等定位器为已运行的成员提供加入成员的连接信息。
  • 在定位器的分布式系统中,服务定位器为服务器提供客户端连接信息。服务定位器也监控服务器加载和发送客户到最小负载的服务器中。

        默认情况下,定位器以对等和服务器模式运行。

        你可以独立运行定位器或是嵌入到另外一个Geode进程中。独立运行你的定位器为整体定位服务提供了最高的可靠性和可用性。

定位器配置和日志文件

定位器配置和日志文件有如下属性:

  • 当你使用gfsh启动一个独立的定位器,gfsh会自动加载需要的jar文件($GEMFIRE/lib/locator-dependencies.jar)到JVM进程的类路径。如果你用LocatorLauncher API 启动一个独立定位器,你必须在用于运行定位器的命令中指定$GEMFIRE/lib/locator-dependencies.jar。查看《Geode进程类路径设置》获取更多类路径设置信息。你可以通过指定--classpath参数来修改类路径。
  • 定位器和其它成员一样是分布式系统成。就组播端口和定位器定位器配置而言,定位器应该和服务器有相同的配置。因此,如果有2个其它的定位器在分布式系统中,每个定位器应引用其它定位器(就像服务器成员那样)。例如:

gfsh> start locator --name=locator1 --port=9009 --mcast-port=0 \
--locators='host1[9001],host2[9003]'
 

 你可以在gemfire.properties文件中配置定位器或是在命令行指定启动参数。如果你在一个属性文件中指定定位器配置,定位器和分布式系统中的其它成员一样要求相同的gemfire.properties设置和相同的gfsecurity.properties设置,如果你正在使用一个单独的,受限制的访问安全设置文件。

例如,在定gemfire.properties中配置位器和多播端口:

locators=host1[9001],host2[9003]
mcast-port=0
 
  • 这里没有为位定器指定缓存配置。

  • 为了输出日志,定位器在它的当前工作目录创建一个日志文件。日志输出的默认路径为定位器的工作目录中的locator_name.log。如果你使用之前用的一个定位器名称重启一个定位器,已有的locator_name.log文件会自动为你重命名(例如locator1-01-01.loglocator1-02-01.log)。你可以在启动定位器时通过在--log-level参数中指定一个级别来实现在这个文件中修改日志级别。

  • 默认情况下,定位器会在gfsh执行目录下的一个子目录(在定位器之后命名)中启动。这个子目录被认为是当前的工作目录。你也可以在用gfsh启动定位器时指定一个不同的工作目录。

  • 默认情况下,一个因为网络断开或是成员没有响应而被关闭和断开连接的定位器会自己重启并且自动尝试重新连接到分布式系统。当一个定位器在重新连接状态,它会为分布式系统提供不被发现服务。查看《使用自动重连接处理被动缓存掉线》获得更多详情。

定位器和集群配置服务

       定位器使用集群服务来保存应用到所有集群成员的配置,或是到一个指定的组成员中。配置会保存在定位器目录中并会传播到分布式系统中所有定位器中。当你用gfsh启动服务器,服务器会从定位器接收到组级别和集群级别的配置。

查看《群集配置服务概述》

启动定位器

 使用以下指南启动定位器:

  • 独立定位器. 用这些方法的一个启动一个独立定位器

    • 使用gfsh命令工具。查看 gfsh(Geode SHell)来获取gfsh使用的更多信息。例如:

    • gfsh>start locator --name=locator1
      
      gfsh> start locator --name=locator2 --bind-address=192.0.2.0 --port=13489
       
    • com.gemstone.gemfire.distributed.LocatorLauncher 类和java可执行文件中用main方法启动定位器,例如:
    • working/directory/of/Locator/process$java -server \
       -classpath "$GEMFIRE/lib/locator-dependencies.jar:/path/to/application/classes.jar" \
       com.gemstone.gemfire.distributed.LocatorLauncher start Locator1 --port=11235 \
        --redirect-output
       
    • 特别的,你在你创建的java应用进程中使用LocatorLauncher类API运行一个嵌入式定位器服务。你执行java命令的目录将成为定位器进程的工作目录。

    • 当你启动多个定位器是,不要并行启动它们(换言之,同时)。作为最佳实践,你应该在其它定位器启动之前让第一个定位器完全启动等待大约30秒。为了检查定位器是否成功启动,检查定位器日志。为了查看定位器正常运行时间,你可以使用gfsh status locator 命令。

  • 嵌入式定位器。成员启动时管理定位器或是通过API来管理定位器:

        在你的成员中使用gemfire.properties start-locator设置来自动启动定位器。查看《参考手册》。当成员退出时定位器会自动停止。这些属性有如下的语法:

#gemfire.properties
start-locator=[address]port[,server={true|false},peer={true|false}]

 示例

#gemfire.properties
start-locator=13489

  在你的代码中使用com.gemstone.gemfire.distributed.LocatorLauncher API来启动定位器。在你的java应用进程中使用LocatorLauncher.Builder类来构造一个LocatorLauncher实例,然后使用start()方法来启动定位器服务。LocatorLauncher类的其它方法提供了定位器的状态信息并且允许你停止定位器。

  

import com.gemstone.gemfire.distributed.LocatorLauncher;

 public class MyEmbeddedLocator {

    public static void main(String[] args){
        LocatorLauncher locatorLauncher  = new LocatorLauncher.Builder()
          .setMemberName("locator1")
          .setPort(13489)
          .build();

          locatorLauncher.start();

          System.out.println("Locator successfully started");
        }
    }

 这里是另外一个在应用中嵌入定位器的例子,启动它然后在其它成员访问它之前检查定位器的状态:

package example;

import ...

class MyApplication implements Runnable {

  private final LocatorLauncher locatorLauncher;

  public MyApplication(final String... args) {
    validateArgs(args);

    locatorLauncher = new LocatorLauncher.Builder()
      .setMemberName(args[0])
      .setPort(Integer.parseInt(args[1])
      .setRedirectOutput(true)
      .build();
  }

  protected void args(final String[] args) {
    ...
  }

  public void run() {
    ...

    // start the Locator in-process
    locatorLauncher.start();

    // wait for Locator to start and be ready to accept member (client) connections
    locatorLauncher.waitOnStatusResponse(30, 5, TimeUnit.SECONDS);

    ...
  }

  public static void main(final String... args) {
    new MyApplication(args).run();
  }

}

  然后执行应用,你可运行:

/working/directory/of/MyApplication$ java \
 -server -classpath "$GEMFIRE/lib/locator-dependencies.jar:/path/to/application/classes.jar" \
 example.MyApplication Locator1 11235

 你执行java命令的目录将成为定位器进程的工作目录。

检查定位器的状态

如果你用gfsh连接到分布式系统,你可以通过提供一个定位器名称来检查一个运行着的定位器状态。例如:

gfsh>status locator --name=locator1

如果你没有连接到一个分布式系统,你可以通过进程ID来检查一个本定的定位器状态,定位器的主机名和端口,或是定位器当前工作目录。例如:

gfsh>status locator --pid=2986

 或

gfsh>status locator --host=host1 --port=1035

 或

$ gfsh status locator --dir=<locator_working_directory>

<locator_working_directory> 对应的是哪里,哪里就是定位器运行的工作目录。如果成功,命令会返回如下的信息(带着启动时提供的jvm参数):

stymon@ubuntu:~$ gfsh status locator --dir=locator1
Locator in /home/stymon/locator1 on ubuntu.local[10334] as locator1 is currently online.
Process ID: 2359
Uptime: 17 minutes 3 seconds
GemFire Version: 8.0.0
Java Version: 1.7.0_65
Log File: /home/stymon/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/stymon/Pivotal_GemFire_800_b48319_Linux/lib/locator-dependencies.jar:/usr/local/java/lib/tools.jar

Cluster configuration service is up and running.

停止定位器

如果你用gfsh连接到了分布式系统,你可以通过提供定位器名来停止一个正在运行的定位器。例如:

gfsh>stop locator --name=locator1

如果你没有连接到一个分布式系统,你可以通过进程ID或是定位器当前工作目录来停止一个本地的定位器。例如:

gfsh>stop locator --pid=2986

 或

gfsh>stop locator --dir=<locator_working_directory>

 <locator_working_directory> 对应的是哪里,哪里就是定位器运行的工作目录。

多站点定位器部署

如果你使用多站点配置,你可以在启动的时候连接到一个定位器到一个远程站点。为了在下个多站点配置中连接一个新的定位器到一个远程定位器,启动时指定如下:
gfsh> start locator --name=locator1 --port=9009 --mcast-port=0 \
--J='-Dgemfire.remote-locators=192.0.2.0[9009],198.51.100.0[9009]'

猜你喜欢

转载自bewithme.iteye.com/blog/2325733