简体   繁体   中英

Java client fails to connect to Zookeeper and HBase

I wrote a simple HBase client program to perform CRUD operations in my HBase cluster (1 Master and 3 Region Server). The Zookeeper instance is only running in the master server and the quorum includes all the 4 servers. The cluster is running fine and can perform read/write using YCSB client (means there are nothing wrong in the server/zookeeper side).

Now in the eclipse classpath I have added all the HBase libs and hbase-0.94.7.jar (which contains the hbase-default.xml file). I have also added the original hbase-site.xml file from the cluster in the project.

Initially, I ran the client code using the unmodified hbase-default.xml and what I've found that the client is trying to communicate with the localhost for zookeeper instance. And thus ignoring the hbase-site.xml.

Then I've modified the 3 parameters which holds the public IP address of the Master/Zookpeer server and tried again. This time I am getting the below error where the client is continuously trying to connect with the Zookeeper and its other quorum members.

I have all the 4 servers in the Zookeeper quorum and lets say their IP addresses are:

  • WWWW // HBase master and Zookeeper Server

  • XXXX // HBase RS and Zookeeper Quorum Member

  • YYYY // HBase RS and Zookeeper Quorum Member

  • ZZZZ // HBase RS and Zookeeper Quorum Member


13/06/19 13:06:23 INFO zookeeper.ZooKeeper: Initiating client connection, connectString=W.W.W.W:2181,X.X.X.X:2181,Y.Y.Y.Y:2181,Z.Z.Z.Z:2181 sessionTimeout=180000 watcher=hconnection

13/06/19 13:06:23 INFO zookeeper.RecoverableZooKeeper: The identifier of this process is 5828@Kamal-VAIO

13/06/19 13:06:24 INFO zookeeper.ClientCnxn: Opening socket connection to server W.W.W.W:2181. Will not attempt to authenticate using SASL (unknown error)

13/06/19 13:06:25 WARN zookeeper.ClientCnxn: Session 0x0 for server null, unexpected error, closing socket connection and attempting reconnect

java.net.ConnectException: Connection refused: no further information

13/06/19 13:06:25 WARN zookeeper.RecoverableZooKeeper: Possibly transient ZooKeeper exception: org.apache.zookeeper.KeeperException$ConnectionLossException: KeeperErrorCode = ConnectionLoss for /hbase/hbaseid

13/06/19 13:06:25 INFO util.RetryCounter: Sleeping 2000ms before retry #1...

13/06/19 13:06:25 INFO zookeeper.ClientCnxn: Opening socket connection to server X.X.X.X:2181. Will not attempt to authenticate using SASL (unknown error)

13/06/19 13:06:26 WARN zookeeper.ClientCnxn: Session 0x0 for server null, unexpected error, closing socket connection and attempting reconnect

java.net.ConnectException: Connection refused: no further information

... and so on

The Problem has been solved.

Solution:

  1. Right Click on the Project in Eclipse
  2. Go to Properties
  3. Select Java Build Path
  4. Go to Libraries
  5. Click Add Class Folder
  6. Add a new folder named conf
  7. Press all OK
  8. Copy my hbase-site.xml into the conf folder
  9. Also add the ip-host lists of my HBase cluster into Win 7 hosts file and save.
  10. Run the hbase codes and the client can successfully connect to Zookeeper and HBase master.

NOTE: Step 10 is must, otherwise the client will get the hostnames from the Zookeeper instance and will not able to resolve them.

Many thanks everyone.

Actually the problem is with kafka-client. So in this case, you have to use explicitly kafka-client dependency version 1.0.2 . sometimes other kafka-client versions giving problems. In my case after setting kafka-client version & scope "provided", the error disappeared.

 <dependency>
            <groupId>org.apache.kafka</groupId>
            <artifactId>kafka-clients</artifactId>
            <version>1.0.2</version>
            <scope>provided</scope>
        </dependency>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM