java开发连接不到hbase Master服务

这个问题困扰了好久,知道是hosts引起的,就是改来改去改不对,这块资料相对比较少,所以发表希望有遇到的可以参考下。

首先查看linux服务器/etc/hostname文件配置,将/etc/hosts文件127.0.0.1 localhost注释掉,改成ip hostname。服务器端就处理完了

windows客户端修改hosts为linux服务器ip linux服务器hostname(做个域名映射)

启动hbase,在浏览器访问查看master地址,之前我的master地址一直是127.0.0.1或localhost,所以访问不到,经以上所述配置,master地址就是hostname,以下测试代码能测通了。


以下是客户端测试代码:

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

                Configuration conf = new Configuration();  
conf.set("hbase.zookeeper.quorum", "hostname");//这句很重要,关系这能不能连接到hbase
HBaseConfiguration cfg = new HBaseConfiguration(conf); 

                String tablename = "test";
String[] columns = new String[] { "id", "age", "name" };
HBaseAdmin admin = new HBaseAdmin(cfg);

if (admin.tableExists(tablename)) {
System.out.println("表已存在");
} else {
HTableDescriptor tableDesc = new HTableDescriptor(tablename);
for (int i = 0; i < columns.length; i++) {
tableDesc.addFamily(new HColumnDescriptor(columns[i]));
}
admin.createTable(tableDesc);
System.out.println("创建表成功!.");
}
}


发布了7 篇原创文章 · 获赞 2 · 访问量 5167

猜你喜欢

转载自blog.csdn.net/u010715243/article/details/53484144
今日推荐