在zookeeper中“java.net.ConnectException:Connection refused”

时间:2011-10-13 14:16:54

标签: apache-zookeeper

我按如下方式安装了zookeeper:

wget http://archive.cloudera.com/cdh/3/zookeeper-3.3.3-cdh3u1.tar.gz

这是我的zoo.cf

# The number of milliseconds of each tick
tickTime=2000
# The number of ticks that the initial
# synchronization phase can take
initLimit=10
# The number of ticks that can pass between
# sending a request and getting an acknowledgement
syncLimit=5
# the directory where the snapshot is stored.
dataDir=/home/reach121/basf/data/zookeeper/data1
# maximum client connection
maxClientCnxns=500
# the port at which the clients will connect
clientPort=2183
server.1=localhost:2878:3878
server.2=localhost:2879:3879
server.3=localhost:2880:3880

并以

开头
/bin/zkServer.sh start zoo.cfg

当我这样做的时候?

bin/zkCli.sh -server 127.0.0.1:2183

它给了我这个错误:

Connecting to 127.0.0.1:2183
2011-10-13 14:11:28,433 - INFO  [main:Environment@97] - Client environment:zookeeper.version=3.3.3-cdh3u1--1, built on 07/18/2011 15:17 GMT
2011-10-13 14:11:28,437 - INFO  [main:Environment@97] - Client environment:host.name=cignexnew
2011-10-13 14:11:28,437 - INFO  [main:Environment@97] - Client environment:java.version=1.6.0_22
2011-10-13 14:11:28,438 - INFO  [main:Environment@97] - Client environment:java.vendor=Sun Microsystems Inc.
2011-10-13 14:11:28,438 - INFO  [main:Environment@97] - Client environment:java.home=/usr/lib/jvm/java-6-openjdk/jre
2011-10-13 14:11:28,439 - INFO  [main:Environment@97] - Client environment:java.class.path=/home/reach121/basf/zookeeper-3.3.3-cdh3u1/bin/../build/classes:/home/reach121/basf/zookeeper-3.3.3-cdh3u1/bin/../build/lib/*.jar:/home/reach121/basf/zookeeper-3.3.3-cdh3u1/bin/../zookeeper-3.3.3-cdh3u1.jar:/home/reach121/basf/zookeeper-3.3.3-cdh3u1/bin/../lib/log4j-1.2.15.jar:/home/reach121/basf/zookeeper-3.3.3-cdh3u1/bin/../lib/jline-0.9.94.jar:/home/reach121/basf/zookeeper-3.3.3-cdh3u1/bin/../src/java/lib/*.jar:/home/reach121/basf/zookeeper-3.3.3-cdh3u1/bin/../conf:
2011-10-13 14:11:28,439 - INFO  [main:Environment@97] - Client environment:java.library.path=/usr/lib/jvm/java-6-openjdk/jre/lib/amd64/server:/usr/lib/jvm/java-6-openjdk/jre/lib/amd64:/usr/lib/jvm/java-6-openjdk/jre/../lib/amd64:/usr/java/packages/lib/amd64:/usr/lib/x86_64-linux-gnu/jni:/lib/x86_64-linux-gnu:/usr/lib/x86_64-linux-gnu:/usr/lib/jni:/lib:/usr/lib
2011-10-13 14:11:28,440 - INFO  [main:Environment@97] - Client environment:java.io.tmpdir=/tmp
2011-10-13 14:11:28,440 - INFO  [main:Environment@97] - Client environment:java.compiler=<NA>
2011-10-13 14:11:28,441 - INFO  [main:Environment@97] - Client environment:os.name=Linux
2011-10-13 14:11:28,441 - INFO  [main:Environment@97] - Client environment:os.arch=amd64
2011-10-13 14:11:28,441 - INFO  [main:Environment@97] - Client environment:os.version=2.6.35.4-rscloud
2011-10-13 14:11:28,442 - INFO  [main:Environment@97] - Client environment:user.name=reach121
2011-10-13 14:11:28,443 - INFO  [main:Environment@97] - Client environment:user.home=/home/reach121
2011-10-13 14:11:28,443 - INFO  [main:Environment@97] - Client environment:user.dir=/home/reach121/basf/zookeeper-3.3.3-cdh3u1
2011-10-13 14:11:28,446 - INFO  [main:ZooKeeper@373] - Initiating client connection, connectString=127.0.0.1:2183 sessionTimeout=30000 watcher=org.apache.zookeeper.ZooKeeperMain$MyWatcher@5311a775
Welcome to ZooKeeper!
2011-10-13 14:11:28,472 - INFO  [main-SendThread():ClientCnxn$SendThread@1041] - Opening socket connection to server /127.0.0.1:2183
JLine support is enabled
2011-10-13 14:11:28,487 - WARN  [main-SendThread(localhost:2183):ClientCnxn$SendThread@1161] - Session 0x0 for server null, unexpected error, closing socket connection and attempting reconnect
java.net.ConnectException: Connection refused
        at sun.nio.ch.SocketChannelImpl.checkConnect(Native Method)
        at sun.nio.ch.SocketChannelImpl.finishConnect(SocketChannelImpl.java:592)
        at org.apache.zookeeper.ClientCnxn$SendThread.run(ClientCnxn.java:1119)
[zk: 127.0.0.1:2183(CONNECTING) 0] 2011-10-13 14:11:30,374 - INFO  [main-SendThread(localhost:2183):ClientCnxn$SendThread@1041] - Opening socket connection to server localhost/127.0.0.1:2183
2011-10-13 14:11:30,376 - WARN  [main-SendThread(localhost:2183):ClientCnxn$SendThread@1161] - Session 0x0 for server null, unexpected error, closing socket connection and attempting reconnect
java.net.ConnectException: Connection refused
        at sun.nio.ch.SocketChannelImpl.checkConnect(Native Method)
        at sun.nio.ch.SocketChannelImpl.finishConnect(SocketChannelImpl.java:592)
        at org.apache.zookeeper.ClientCnxn$SendThread.run(ClientCnxn.java:1119)

3 个答案:

答案 0 :(得分:6)

服务器出现了吗?可能没有给出:

server.1=localhost:2878:3878
server.2=localhost:2879:3879
server.3=localhost:2880:3880

如果您在同一主机上运行所有三台服务器,则每台服务器都需要具有不同的配置 - 特别是datadir位置必须不同,并且您需要确保每个datadir都有一个与服务器线对应的myid文件(即服务器。#in config)。

通常,当您想要在分布式模式下运行时,您需要拥有单独的主机。在这种情况下,为什么不只是在独立(默认)模式下运行?

我建议您先在管理指南中阅读更多内容:http://zookeeper.apache.org/doc/r3.3.3/zookeeperAdmin.html

答案 1 :(得分:3)

确保所有必需的服务正在运行

步骤1:检查hbase-master是否正在运行

sudo /etc/init.d/hbase-master status

如果没有,则启动它sudo /etc/init.d/hbase-master start

第2步:检查hbase-regionserver是否正在运行

sudo /etc/init.d/hbase-regionserver status

如果没有,则启动它sudo /etc/init.d/hbase-regionserver start

步骤3:检查zookeeper服务器是否正在运行

sudo /etc/init.d/zookeeper-server status

如果没有,则启动它sudo /etc/init.d/zookeeper-server start


或者只是连续运行这3个命令。

sudo /etc/init.d/hbase-master restart
sudo /etc/init.d/hbase-regionserver restart
sudo /etc/init.d/zookeeper-server restart

之后不要忘记检查状态

sudo /etc/init.d/hbase-master status
sudo /etc/init.d/hbase-regionserver status
sudo /etc/init.d/zookeeper-server status

您可能会发现zookeeper仍未运行: 然后你可以运行zookeeper

sudo /usr/lib/zookeeper/bin/zkServer.sh stop
sudo /usr/lib/zookeeper/bin/zkServer.sh start

之后再次检查状态并确保其正在运行

sudo /etc/init.d/zookeeper-server status

这应该有用。

答案 2 :(得分:2)

我有同样的问题从客户端代码连接到mapr m3开箱即用

问题是客户端试图在localhost连接到M3 zookeeper。

我的M3群集上的

/opt/mapr/conf/mapr-clusters.conf指向localhost ... 我将其更改为M3机器的IP地址,并且客户端的连接工作

/opt/mapr/conf/cldb.conf添加IP地址代替localhost

并重新启动zookeeper