概述
一、错误描述
安装完zookeeper后,启动服务,然后进行测试,报“Error contacting service. It is probably not running.”,使用客户端命令zkCli.sh提示“java.net.ConnectException: 拒绝连接..”异常,如下所示[root@localhost bin]# sh zkCli.sh -server 127.0.0.1:2181@b@Connecting to 127.0.0.1:2181@b@2016-09-24 16:33:21,601 [myid:] - INFO [main:Environment@100] - Client environment:zookeeper.version=3.4.6-1569965, built on 02/20/2014 09:09 GMT@b@...@b@java.net.ConnectException: 拒绝连接@b@ at sun.nio.ch.SocketChannelImpl.checkConnect(Native Method)@b@ at sun.nio.ch.SocketChannelImpl.finishConnect(SocketChannelImpl.java:701)@b@ at org.apache.zookeeper.ClientCnxnSocketNIO.doTransport(ClientCnxnSocketNIO.java:361)@b@ at org.apache.zookeeper.ClientCnxn$SendThread.run(ClientCnxn.java:1081)@b@JLine support is enabled
二、解决方法
1.查看/conf/zoo.cfg配置文件,如下所示tickTime=30000@b@initLimit=10@b@syncLimit=5@b@dataDir=/data/zookeeper@b@dataLogDir=/data/logs@b@clientPort=2181
2.如上配置内容所示,由于配置数据存在路径dataDir、日志存储路径dataLogDir,但是实际不存在该目录,造成zookeeper无发正常启动,创建这两个目录,再重启服务[root@localhost bin]# mkdir /data/zookeeper@b@[root@localhost bin]# mkdir /data/logs@b@[root@localhost bin]# sh zkServer.sh restart@b@Using config: /usr/local/zookeeper-3.4.6/bin/../conf/zoo.cfg@b@JMX enabled by default@b@Using config: /usr/local/zookeeper-3.4.6/bin/../conf/zoo.cfg@b@Stopping zookeeper ... /usr/local/zookeeper-3.4.6/bin/zkServer.sh: line 143: kill: (9075) - 没有那个进程@b@STOPPED@b@JMX enabled by default@b@Using config: /usr/local/zookeeper-3.4.6/bin/../conf/zoo.cfg@b@Starting zookeeper ... STARTED
3.测试服务已正常[root@localhost bin]# telnet localhost 2181@b@Trying 127.0.0.1...@b@Connected to localhost.localdomain (127.0.0.1).@b@Escape character is '^]'.@b@Connection closed by foreign host.[root@localhost bin]# sh zkServer.sh status@b@JMX enabled by default@b@Using config: /usr/local/zookeeper-3.4.6/bin/../conf/zoo.cfg@b@Mode: standalone[root@localhost bin]# sh zkCli.sh -server 127.0.0.1:2181@b@Connecting to 127.0.0.1:2181@b@2016-09-24 17:02:38,607 [myid:] - INFO [main:Environment@100] - Client environment:zookeeper.version=3.4.6-1569965, built on 02/20/2014 09:09 GMT@b@...@b@Welcome to ZooKeeper!@b@JLine support is enabled@b@2016-09-24 17:02:38,843 [myid:] - INFO [main-SendThread(127.0.0.1:2181):ClientCnxn$SendThread@1235] - Session establishment complete on server 127.0.0.1/127.0.0.1:2181, sessionid = 0x1575b644d900000, negotiated timeout = 60000@b@@b@WATCHER::@b@@b@WatchedEvent state:SyncConnected type:None path:null@b@[zk: 127.0.0.1:2181(CONNECTED) 0] ls /@b@[zookeeper]@b@[zk: 127.0.0.1:2181(CONNECTED) 1] create /test hello@b@Created /test@b@[zk: 127.0.0.1:2181(CONNECTED) 4] set /test hello@b@cZxid = 0x2@b@ctime = Sat Sep 24 17:03:15 CST 2016@b@mZxid = 0x3@b@mtime = Sat Sep 24 17:04:16 CST 2016@b@pZxid = 0x2@b@cversion = 0@b@dataVersion = 1@b@aclVersion = 0@b@ephemeralOwner = 0x0@b@dataLength = 5@b@numChildren = 0@b@[zk: 127.0.0.1:2181(CONNECTED) 5] get /test@b@hello@b@cZxid = 0x2@b@ctime = Sat Sep 24 17:03:15 CST 2016@b@mZxid = 0x3@b@mtime = Sat Sep 24 17:04:16 CST 2016@b@pZxid = 0x2@b@cversion = 0@b@dataVersion = 1@b@aclVersion = 0@b@ephemeralOwner = 0x0@b@dataLength = 5@b@numChildren = 0@b@[zk: 127.0.0.1:2181(CONNECTED) 6]
最后
以上就是幸福期待为你收集整理的java 测试zookeeper_测试zookeeper服务报"java.net.ConnectException: 拒绝连接..Error contacting service.."...的全部内容,希望文章能够帮你解决java 测试zookeeper_测试zookeeper服务报"java.net.ConnectException: 拒绝连接..Error contacting service.."...所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
发表评论 取消回复