简体   繁体   中英

Unable to Create table and List tables to remote HBase using JAVA

trying to connect HBase Remotely only, same code works in locally:

THIS IS PROGRAM:

public static void main(String[] args) throws IOException {
    HBaseConfiguration hconfig = new HBaseConfiguration(new Configuration());
    hconfig.set("hbase.zookeeper.quorum", "192.168.*.***");
    hconfig.set("hbase.master", "192.168.*.***:60000");
    hconfig.set("hbase.zookeeper.property.clientPort","2181");
    HTableDescriptor htable = new HTableDescriptor("User"); 
    htable.addFamily( new HColumnDescriptor("Id"));
    htable.addFamily( new HColumnDescriptor("Name"));
    System.out.println( "Connecting..." );
    HBaseAdmin hbase_admin = new HBaseAdmin( hconfig );
    System.out.println( "Creating Table..." );
    hbase_admin.createTable( htable );
    System.out.println("Done!");
}

After this line is throwing an error:

HBaseAdmin hbase_admin = new HBaseAdmin( hconfig );

Error:

15/10/06 11:22:05 INFO zookeeper.ClientCnxn: Session establishment complete on server quickstart.cloudera/192.168.*.***:2181, sessionid = 0x1503670c5dc00b5, negotiated timeout = 60000
Creating Table...

15/10/06 11:23:02 INFO client.RpcRetryingCaller: Call exception, tries=10, retries=35, started=57048 ms ago, cancelled=false, msg=

15/10/06 11:23:23 INFO client.RpcRetryingCaller: Call exception, tries=11, retries=35, started=78252 ms ago, cancelled=false, msg=

These are my Jar files:

commons-configuration-1.6.jar
commons-lang-2.5.jar
commons-logging-1.1.1.jar
hadoop-core-1.0.0.jar
hadoop-common-1.0.0.jar
hbase-server-1.0.0-cdh5.4.2.jar
hbase-client-1.0.0-cdh5.4.2.jar
hbase-0.92.0.jar log4j-1.2.16.jar
slf4j-api-1.5.8.jar
slf4j-log4j12-1.5.8.jar
zookeeper-3.4.2.jar 

and includes all the jar files which are located in hadoop path /usr/lib/hbase/lib/

And I have copy the hbase-site.xml file to my project and also add the remote ip address into etc/host file too.

I'm facing problems, while creating a new table in to remote hbase and trying to fetch table list from hbase using java client!

But with the same jar files, I can able to do other more operations like Get, Put and other few, except Creating table and Listing Table!

Kindly do favor me.

Add the following dependency in your pom.xml file

<dependency>
     <groupId>org.apache.hbase</groupId>
     <artifactId>hbase-client<artifactId>
     <version>1.1.0.1</version>
<dependency>

Instead of setting hbase configuration details individually add hbase-site.xml & core-site.xml as resources to Configuration object and use it

Configuration config = HBaseConfiguration.create();
config.addResource(new Path("/etc/hbase/conf/hbase-site.xml"));
config.addResource(new Path("/etc/hadoop/conf/core-site.xml"));

Once you have Configuration object create the Connection and get Admin object

Connection connection = ConnectionFactory.createConnection(config);
Admin admin = connection.getAdmin();

And then you can use the following code snippet to create HBase table along with the column families.

if (!admin.isTableAvailable(TableName.valueOf("user"))) {
    HTableDescriptor hbaseTable = new HTableDescriptor(TableName.valueOf("user"));
    hbaseTable.addFamily(new HColumnDescriptor("id"));
    hbaseTable.addFamily(new HColumnDescriptor("name"));
    admin.createTable(hbaseTable);
}

For more details refer this

for working code sample you can refer this

Since you were able to perform put and get, it should not be a jar issue. Can you try adding this property zookeeper.znode.parent with value "/hbase-unsecure" in hbase config. Its the the root znode that will contain all the znodes created/used by HBase. In zookeeper client jar, this value is "/hbase". Compare it with your config xml files. You can look here

I had similar problem. I fixed it by opening the following ports in the HBase nodes:

  1. 60000
  2. 60010
  3. 60020
  4. 9090

In Centos 7:

sudo firewall-cmd --zone=public --add-port=60000/tcp --permanent
sudo firewall-cmd --zone=public --add-port=60010/tcp --permanent
sudo firewall-cmd --zone=public --add-port=60020/tcp --permanent
sudo firewall-cmd --zone=public --add-port=9090/tcp --permanent
sudo firewall-cmd --reload

More information here

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