从Java API客户端访问HBase

时间:2018-12-14 16:25:25

标签: java hbase

从java API客户端访问HBase时遇到一些麻烦,我无法弄清楚自己在做什么错。

我在具有RHEL6和JAVA 1.7的VM(10.166.205.41)上以独立模式使用HBase 1.1.2。 这是hbase-site.xml中我的HBase配置

<configuration>
  <property>
    <name>hbase.zookeeper.quorum</name>
    <value>10.166.205.41</value>
  </property>
  <property>
    <name>hbase.zookeeper.property.clientPort</name>
    <value>9091</value>
  </property>
  <property>
    <name>hbase.rootdir</name>
    <value>file:///usr/local/hbaserootdir/hbase</value>
  </property>
  <property>
    <name>hbase.zookeeper.property.dataDir</name>
    <value>/usr/local/hbaserootdir/zookeeper</value>
  </property>
  <property>
    <name>hbase.unsafe.stream.capability.enforce</name>
    <value>false</value>
  </property>
</configuration>

我的regionservers文件定义如下:

10.166.205.41

HBase Shell客户端运行正常,我可以从URL 10.166.205.41:16010访问HBase主UI。

这是我的Java API客户端,在Windows 7的Eclipse上运行。 Pom.xml

<dependencies>
    <dependency>
        <groupId>org.apache.hbase</groupId>
        <artifactId>hbase-client</artifactId>
        <version>1.1.2</version>
    </dependency>
    <dependency>
         <groupId>org.apache.hbase</groupId>
         <artifactId>hbase</artifactId>
         <version>1.1.2</version>
         <type>pom</type>
    </dependency>
</dependencies>

源代码:

public class InsertData {

    final static Logger logger = Logger.getLogger(InsertData.class);

    public static void main(String[] args) throws IOException {

        Configuration config = HBaseConfiguration.create();

        config.setInt("timeout", 120000);
        config.set("hbase.zookeeper.quorum","10.166.205.41");
        config.set("hbase.zookeeper.property.clientPort", "9091");

        Connection connection = ConnectionFactory.createConnection(config);

        Table table = connection.getTable(TableName.valueOf("emp"));

        try {

            Get g = new Get(Bytes.toBytes("1"));
            Result result = table.get(g);

            byte [] name = result.getValue(Bytes.toBytes("personal data"), Bytes.toBytes("name"));

            logger.info("name : " + Bytes.toString(name));

        } finally {
            table.close();
            connection.close();
        }
    }
}

在执行期间,与服务器10.166.205.41:41571的连接失败。

2018-12-14 16:35:19 DEBUG FailedServers:56 - Added failed server with address hlzudd5hdf01.yres.ytech/10.166.205.41:41571 to list caused by org.apache.hbase.thirdparty.io.netty.channel.ConnectTimeoutException: connection timed out: hlzudd5hdf01.yres.ytech/10.166.205.41:41571
2018-12-14 16:35:19 DEBUG ClientCnxn:843 - Reading reply sessionid:0x167ad4d815d000b, packet:: clientPath:/hbase/meta-region-server serverPath:/hbase/meta-region-server finished:false header:: 3,4  replyHeader:: 3,4697,0  request:: '/hbase/meta-region-server,F  response:: #ffffffff0001a726567696f6e7365727665723a3431353731ffffffa0ffffffe9ffffff80fffffffd5611ffffff8c6a50425546a24a17686c7a7564643568646630312e797265732e797465636810ffffffe3ffffffc4218ffffffceffffff93ffffffb6ffffffeafffffffa2c100183,s{4519,4519,1544800813291,1544800813291,0,0,0,0,77,0,4519} 
2018-12-14 16:35:19 DEBUG ClientCnxn:742 - Got ping response for sessionid: 0x167ad4d815d000b after 38ms
2018-12-14 16:35:19 DEBUG AbstractRpcClient:349 - Not trying to connect to hlzudd5hdf01.yres.ytech/10.166.205.41:41571 this server is in the failed servers list
2018-12-14 16:35:19 DEBUG ClientCnxn:843 - Reading reply sessionid:0x167ad4d815d000b, packet:: clientPath:/hbase/meta-region-server serverPath:/hbase/meta-region-server finished:false header:: 4,4  replyHeader:: 4,4697,0  request:: '/hbase/meta-region-server,F  response:: #ffffffff0001a726567696f6e7365727665723a3431353731ffffffa0ffffffe9ffffff80fffffffd5611ffffff8c6a50425546a24a17686c7a7564643568646630312e797265732e797465636810ffffffe3ffffffc4218ffffffceffffff93ffffffb6ffffffeafffffffa2c100183,s{4519,4519,1544800813291,1544800813291,0,0,0,0,77,0,4519} 

在HBase主UI上,这是区域服务器地址,并且通过单击链接我也无法获得该页面。 我将程序打包为jar文件,并在我的VM上运行它很好,这使我认为这可能是端口访问问题。

进入netstat -tanp |我的RHEL6 VM上的grep LISTEN命令告诉我我的区域服务器端口正在侦听

tcp        0      0 10.166.205.41:41571         0.0.0.0:*                   LISTEN      26322/java

似乎我没有任何防火墙在运行,所以不知道为什么连接失败。也许是另一回事。

我不知道要解决此问题,因此如果您能帮助我,将不胜感激^^ 非常感谢。

0 个答案:

没有答案