简体   繁体   English

无法使用 JAVA 创建表和列出表到远程 HBase

[英]Unable to Create table and List tables to remote HBase using JAVA

trying to connect HBase Remotely only, same code works in locally:尝试仅远程连接 HBase,相同的代码在本地工作:

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:这些是我的 Jar 文件:

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/并包含位于 hadoop 路径/usr/lib/hbase/lib/所有 jar 文件

And I have copy the hbase-site.xml file to my project and also add the remote ip address into etc/host file too.我已将 hbase-site.xml 文件复制到我的项目中,并将远程 IP 地址也添加到 etc/host 文件中。

I'm facing problems, while creating a new table in to remote hbase and trying to fetch table list from hbase using java client!我在向远程 hbase 创建新表并尝试使用 java 客户端从 hbase 获取表列表时遇到问题!

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!但是同样的jar文件,除了Creating table和Listing Table之外,我还可以做更多的操作,比如Get、Put等少数操作!

Kindly do favor me.请善待我。

Add the following dependency in your pom.xml file在 pom.xml 文件中添加以下依赖项

<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不是单独设置 hbase 配置细节,而是将hbase-site.xmlcore-site.xml作为资源添加到Configuration对象中并使用它

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拥有 Configuration 对象后,创建Connection并获取Admin对象

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.然后您可以使用以下代码片段创建 HBase 表以及列族。

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.由于您能够执行 put 和 get,因此它不应该是 jar 问题。 Can you try adding this property zookeeper.znode.parent with value "/hbase-unsecure" in hbase config.您可以尝试在 hbase 配置中添加值为“/hbase-unsecure”的此属性zookeeper.znode.parent Its the the root znode that will contain all the znodes created/used by HBase.它是包含 HBase 创建/使用的所有 znode 的根 znode。 In zookeeper client jar, this value is "/hbase".在 zookeeper 客户端 jar 中,此值为“/hbase”。 Compare it with your config xml files.将它与您的配置 xml 文件进行比较。 You can look here你可以看这里

I had similar problem.我有类似的问题。 I fixed it by opening the following ports in the HBase nodes:我通过在 HBase 节点中打开以下端口来修复它:

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

In Centos 7:在 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更多信息在这里

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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