Hbase远程连接

时间:2017-02-13 10:19:44

标签: hadoop hbase remote-access

我在7个AWS实例中设置了Hadoop集群,并在其中安装了HBase。我试图从不在群集的机器上操作HBase表。使用HBase API,我编写了以下代码,只有在其中一个集群节点中执行时才能工作:

BasicConfigurator.configure();

//This reads hdfs-site.xml
HdfsConfiguration hdfsConf = new HdfsConfiguration();

System.setProperty("hadoop.home.dir", new Path("/usr/hdp/current/hadoop-client").toString());

//This reads core-site.xml and hbase-site.xml
Configuration conf = HBaseConfiguration.create();
conf.set(HConstants.ZOOKEEPER_QUORUM, PUBLIC_DNS);

HBaseAdmin.checkHBaseAvailable(conf);

Connection conn = ConnectionFactory.createConnection(conf);
TableName tName = TableName.valueOf("history_sample");
Table t = conn.getTable(tName);
Get get = new Get(Bytes.toBytes("100005379"));
Result res = t.get(get);
byte[] geoloc_date = res.getValue(Bytes.toBytes("general_data"), Bytes.toBytes("geoloc_date"));
System.out.println("Example value: " + Bytes.toString(geoloc_date));

t.close();
conn.close();  

我要做的是创建一个类似的代码,该代码可以在我的本地机器上运行,该机器在Hadoop集群之外,我不想在其中一个集群节点中执行jar文件。 / p>

提前致谢。

0 个答案:

没有答案
相关问题