zookeeper自身节点故障

发布于 2022-09-02 00:39:48 字数 132 浏览 11 评论 0

客户端连接zookeeper服务时,必须指定某一个zookeeper节点的ip连接上去,但是如果该zookeeper节点自身宕机了,客户端如何知道连接zookeeper服务时,要使用哪个新的ip?(注意:指的是zookeeper服务自身的节点宕机了)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

熟人话多 2022-09-09 00:39:48

指定一个域名,域名可以做负载的。
而且我今天也在想这个问题,觉得client还可以做一个发现server的ip功能,这样server宕机,client可以及时切换到另一个可用的server,而且还可以自己做负载,当然这个不是针对zookeeper的。
不过lz可以谷歌下,zookeeper应有成熟方案解决单点问题的方案。
这是我随手google的 http://www.cnblogs.com/yjmyzz/p/Solve-the-problem-of-single-point-of-failure-using-ZooKeeper.html

音盲 2022-09-09 00:39:48

答案来自zk文档

如果在连接时候zk服务器宕机
To create a client session the application code must provide a connection string containing a comma separated list of host:port pairs, each corresponding to a ZooKeeper server (e.g. "127.0.0.1:4545" or "127.0.0.1:3000,127.0.0.1:3001,127.0.0.1:3002"). The ZooKeeper client library will pick an arbitrary server and try to connect to it. If this connection fails, or if the client becomes disconnected from the server for any reason, the client will automatically try the next server in the list, until a connection is (re-)established.

如果已经连接之后服务器宕机
SessionMovedException. There is an internal exception that is generally not seen by clients called the SessionMovedException. This exception occurs because a request was received on a connection for a session which has been reestablished on a different server. The normal cause of this error is a client that sends a request to a server, but the network packet gets delayed, so the client times out and connects to a new server. When the delayed packet arrives at the first server, the old server detects that the session has moved, and closes the client connection. Clients normally do not see this error since they do not read from those old connections. (Old connections are usually closed.) One situation in which this condition can be seen is when two clients try to reestablish the same connection using a saved session id and password. One of the clients will reestablish the connection and the second client will be disconnected (causing the pair to attempt to re-establish its connection/session indefinitely).

清音悠歌 2022-09-09 00:39:48

连接的时候 zookeeper 集群ip 都写上就行了。
eg:
ZkClient zkClient = new ZkClient("192.168.19.130:2181,192.168.19.130:2182,192.168.19.130:2183");

这样 如果一台 zookeeper 宕机 ,client 会自动连接 其他的。

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文