无法用java访问官方的zookeeper docker 集群
如题,我从docker hub拉取了官方的zookeeper镜像,文件如下:
version: '3.1'
services:
zoo1:
image: zookeeper
restart: always
hostname: zoo1
ports:
- 2181:2181
environment:
ZOO_MY_ID: 1
ZOO_SERVERS: server.1=0.0.0.0:2888:3888;2181 server.2=zoo2:2888:3888;2181 server.3=zoo3:2888:3888;2181
zoo2:
image: zookeeper
restart: always
hostname: zoo2
ports:
- 2182:2181
environment:
ZOO_MY_ID: 2
ZOO_SERVERS: server.1=zoo1:2888:3888;2181 server.2=0.0.0.0:2888:3888;2181 server.3=zoo3:2888:3888;2181
zoo3:
image: zookeeper
restart: always
hostname: zoo3
ports:
- 2183:2181
environment:
ZOO_MY_ID: 3
ZOO_SERVERS: server.1=zoo1:2888:3888;2181 server.2=zoo2:2888:3888;2181 server.3=0.0.0.0:2888:3888;2181
在虚拟机中成功启动,但是在java中生成客户端的时候会报错
public class Zookeeperdemo {
public static void main(String[] args) throws IOException, KeeperException, InterruptedException {
// 10.181.56.101 是虚拟机的IP
String connectString = "10.181.56.101:2181,10.181.56.101:2182,10.181.56.101:2183";
int sessionTimeout = 2000;
ZooKeeper zooKeeper;
zooKeeper = new ZooKeeper(connectString, 3000, watchedEvent -> {
//TODO: 暂时是一个空事件
});
}
}
报错信息如下,比较奇怪,我在docker内部调用zkCli是没有问题的
2020-05-27 19:58:40,819 INFO [org.apache.zookeeper.ZooKeeper] - Initiating client connection, connectString=10.181.56.101:2181,10.181.56.101:2182,10.181.56.101:2183 sessionTimeout=3000 watcher=com.dennis.Zookeeperdemo$$Lambda$1/319977154@17579e0f
2020-05-27 19:58:40,822 INFO [org.apache.zookeeper.common.X509Util] - Setting -D jdk.tls.rejectClientInitiatedRenegotiation=true to disable client-initiated TLS renegotiation
2020-05-27 19:58:41,186 INFO [org.apache.zookeeper.ClientCnxnSocket] - jute.maxbuffer value is 1048575 Bytes
2020-05-27 19:58:41,193 INFO [org.apache.zookeeper.ClientCnxn] - zookeeper.request.timeout value is 0. feature enabled=false
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论