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

查看:106
本文介绍了从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:端口条目的文件?

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等......),或者查看参展商的代码示例: 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天全站免登陆