user2435082
user2435082

Reputation: 295

Unable to make Java client connection to standlone HBase setup in remote machine

I am using HBase.1.1.2 version. I am able to do everything from Hbase Shell and also with Hbase REST API. I have one VMWare with Ubuntu in which Hadoop & Hbase has been configured and I am executing Java program from my windows machine.

Note:- I have not installed separate zookeeper I am using Hbase inbuilt zookeeper.

JPS output :-

3824 SecondaryNameNode
4194 NodeManager
7154 HMaster
9092 Jps
3300 NameNode
3510 DataNode
3975 ResourceManager

Below is my Hbase-site.xml :-

<configuration>
     <property>
      <name>hbase.rootdir</name>
      <value>hdfs://XX.XX.XX.XX:9000/hbase</value>
   </property>

   //Here you have to set the path where you want HBase to store its built in zookeeper  files.
   <property>
      <name>hbase.zookeeper.property.dataDir</name>
      <value>/home/prag/Desktop/hadoop_data/zookeeper</value>
   </property>  

<property>
  <name>hbase.cluster.distributed</name>
  <value>true</value>
</property> 

</configuration>

*XX.XX.XX.XX is my IP address of my ubuntu vm where my hbase has been installed which I am able to ping from windows.

Below is my Java code :-

    import org.apache.hadoop.conf.Configuration;
    import org.apache.hadoop.hbase.HBaseConfiguration;
    import org.apache.hadoop.hbase.client.HBaseAdmin;

    public class HBaseConnection {

        public HBaseConnection() {

        }

        public static void main(String[] args){
            try{
                Configuration config=HBaseConfiguration.create();

                HBaseAdmin.checkHBaseAvailable(config);
                config.set("hbase.zookeeper.quorum", "00.00.00.00");

            }catch(Exception e){
                e.printStackTrace();
            }
        }

    }

Below is the exception which I am getting from my java programme :-

 org.apache.hadoop.hbase.ZooKeeperConnectionException: Can't connect to ZooKeeper
        at org.apache.hadoop.hbase.client.HBaseAdmin.checkHBaseAvailable(HBaseAdmin.java:2813)
        at com.sag.hbase.HBaseConnection.main(HBaseConnection.java:17)
    Caused by: org.apache.zookeeper.KeeperException$ConnectionLossException: KeeperErrorCode = ConnectionLoss for /hbase
        at org.apache.zookeeper.KeeperException.create(KeeperException.java:99)
        at org.apache.zookeeper.KeeperException.create(KeeperException.java:51)
        at org.apache.zookeeper.ZooKeeper.exists(ZooKeeper.java:1045)
        at org.apache.zookeeper.ZooKeeper.exists(ZooKeeper.java:1073)
        at org.apache.hadoop.hbase.client.HBaseAdmin.checkHBaseAvailable(HBaseAdmin.java:2806)
        ... 1 more

Upvotes: 1

Views: 1091

Answers (2)

user2435082
user2435082

Reputation: 295

Just to help others I want to answer my question.Solution for this problem is that you should not have entry with localhost in your hosts file.

Upvotes: 0

Martin Serrano
Martin Serrano

Reputation: 3795

In order to connect to HBase from the client, the client also needs to know where the ZooKeeper quorum is running. This is the same as the ZooKeeper connection information. ZooKeeper defaults to using port 2181, so in your configuration, the quorum configuration should be set to XX.XX.XX.XX:2181:

config.set(HConstants.ZOOKEEPER_QUORUM, "XX.XX.XX.XX:2181");

with the XXs replaced with the real IP address of course. You can use the HBase zkclki command to validate the setting. You will also need to move this line before calling checkHBaseAvailable.

Upvotes: 1

Related Questions