XMen
XMen

Reputation: 30256

"java.net.ConnectException: Connection refused" in zookeeper

I installed zookeeper as follows :

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

Here is my 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

and started by

/bin/zkServer.sh start zoo.cfg

and when I do?

bin/zkCli.sh -server 127.0.0.1:2183

it gives me this error:

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)

Upvotes: 18

Views: 67830

Answers (3)

Sachin Pawar
Sachin Pawar

Reputation: 29

I had the same issue connecting from a client code to mapr m3 out of the box

the issue is the the client was trying to connect to M3 zookeeper at localhost.

/opt/mapr/conf/mapr-clusters.conf on my M3 cluster was pointing to localhost ... i changed it to the ip address of M3 machine and the connection from client worked

/opt/mapr/conf/cldb.conf add ip address in place of localhost

and restart zookeeper

Upvotes: 2

phunt
phunt

Reputation: 530

Are the servers coming up? Likely not given:

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

If you are running all three servers on the same host they will need to each have a different config - in particular the datadir location must be different, and you need to assure that each datadir has a myid file corresponding to the server line (ie server.# in config).

Typically when you want to run in distributed mode you need to have separate hosts. In this case why not just run in standalone (default) mode?

I'd suggest you read more in the admin guide first: http://zookeeper.apache.org/doc/r3.3.3/zookeeperAdmin.html

Upvotes: 6

Abhishek Goel
Abhishek Goel

Reputation: 19771

Make sure all required services are running

Step 1 : Check if hbase-master is running

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

if not, then start it sudo /etc/init.d/hbase-master start

Step 2 : Check if hbase-regionserver is running

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

if not, then start it sudo /etc/init.d/hbase-regionserver start

Step 3 : Check if zookeeper-server is running

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

if not, then start it sudo /etc/init.d/zookeeper-server start


or simply run these 3 commands in a row.

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

after that don't forget to check the status

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

You might find that zookeeper is still not running: then you can run the zookeeper

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

after that again check the status and make sure its running

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

This should work.

Upvotes: 3

Related Questions