简体   繁体   中英

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

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 .

只是为了帮助他人,我想回答我的问题。此问题的解决方案是,您的主机文件中不应包含localhost条目。

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