从java程序启动zookeeper服务器的最佳方式 [英] Best way to start zookeeper server from java program

查看:37
本文介绍了从java程序启动zookeeper服务器的最佳方式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个问题,我找不到任何流行/广泛接受的解决方案:

I have two questions for which I couldn't find any popular/widely accepted solutions:

  1. 使用 Java 程序启动 zookeeper 服务器的最简单方法是什么?

  1. What is the easiest way to start zookeeper server using Java Program?

而且,是否可以将服务器添加到 zookeeper 集群,而无需手动转到每台机器并使用新节点的 id 和 ip:port 条目更新其配置文件?

And, is it possible to add servers to zookeeper cluster without having to manually go to each machine and update their config files with new node's id and ip:port entry?

有人可以帮忙吗?谢谢!

Can someone please help? Thanks!

推荐答案

如果你想从你的 Java 代码启动一个新的 ZooKeeper 服务器进程,你可以像从 Java 启动任何其他外部进程一样,例如使用 ProcessBuilder.对于 ZooKeeper,这里没有什么特别之处.您可以查看官方文档,了解实际命令的外观.如果你想监督生产使用的过程会变得复杂,所以在这种情况下,最好使用操作系统上提供的东西(例如 upstart、runit 等...),或者查看 Exhibitor 以获取代码示例:https://github.com/Netflix/exhibitor.

If you want to start a new ZooKeeper server process from your Java code, you would do it the same way you would start any other external process from Java, e.g. using a ProcessBuilder. There is nothing special here in case of ZooKeeper. You can check the official docs on how the actual command should look like. It gets complicated if you want to supervise the process for production use, so in that case it would be better to use something provided on your OS (e.g. upstart, runit, etc...), or take a look at Exhibitor for code examples: https://github.com/Netflix/exhibitor.

如果您要从 Java 程序启动 ZooKeeper 集群,那么事情就会变得更加复杂,因为您基本上需要监督不同主机上的多个 ZooKeeper JVM 进程.另请查看参展商.

If you are asking about starting a ZooKeeper cluster from your Java program, then you complicate things further, since you would basically need to supervise multiple ZooKeeper JVM processes on different hosts. Also take a look at Exhibitor.

如果您的问题是在与 Java 代码(嵌入式)相同的 JVM 进程中启动 ZooKeeper 服务器实例,那么这也是可能的.有几个重要的细节要记住,看看这个答案:是吗是否可以在进程中启动一个 zookeeper 服务器实例,比如单元测试?

If your question is about starting a ZooKeeper server instance inside the same JVM process as your Java code (embedded), then it is also possible. There are a few important details to keep in mind, take a look at this answer: Is it possible to start a zookeeper server instance in process, say for unit tests?

关于您的第二个问题,最近才在 3.5.0 中添加了对动态集群重新配置的真正支持:http://zookeeper.apache.org/doc/trunk/zookeeperReconfig.html.

Regarding your second question, real support for dynamic cluster reconfiguration was added just recently, in 3.5.0: http://zookeeper.apache.org/doc/trunk/zookeeperReconfig.html.

在此之前,您仍然可以将服务器添加到 zookeeper 集群,而无需手动前往每台机器并更新其配置",但您必须使用像 Chef、Puppet 或类似的配置管理工具,在这种情况下您还需要重新启动集群以采用新配置.

Prior to this, you can still "add servers to zookeeper cluster without having to manually go to each machine and update their config", but you have to use a configuration management tool like Chef, Puppet or similar, and in this case you would also need to do a restart of the cluster to uptake new config.

这篇关于从java程序启动zookeeper服务器的最佳方式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆