Eclipse操作Hbase遇到的问题:getMaster attempt 。。。

     首先,说明一下开发环境,eclipse是部署在WIN7系统上,Hbase集群是部署在CentOS上面。

     下面是网上转载的开发步骤:

       1.添加包

(1)我们解压包
解压之后,得到如下包
 


(2)添加包
添加包的操作

 

        如上图5个步骤:
        单 击hbase-》属性弹出(2所示)Properties for hbase属性对话框.

        然后我们通过下标5,单击Add External JARs。
        找到hbase_home/lib,我这里是D:\hadoop2\hbase-0.98.3-hadoop2\lib

 


添加完毕,这样开发环境就搭建完毕。

package  www.aboutyun.com.hbase;

import java.io.IOException;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hbase.HBaseConfiguration;
import org.apache.hadoop.hbase.HColumnDescriptor;
import org.apache.hadoop.hbase.HTableDescriptor;
import org.apache.hadoop.hbase.client.HBaseAdmin;
import org.apache.hadoop.hbase.TableName;
import org.apache.hadoop.hbase.util.Bytes;

public class OperateTable {
         public static void main(String[] args) throws IOException {
         
         Configuration conf = HBaseConfiguration.create();
          conf.set("hbase.zookeeper.quorum", "master");//使用eclipse时必须添加这个,否则无法定位
         conf.set("hbase.zookeeper.property.clientPort", "2181");
         HBaseAdmin admin = new HBaseAdmin(conf);// 新建一个数据库管理员//新api
         HTableDescriptor desc=new HTableDescriptor(TableName.valueOf("blog"));
         //HTableDescriptor desc = new HTableDescriptor("blog");
         desc.addFamily(new HColumnDescriptor("article"));
         desc.addFamily(new HColumnDescriptor("author"));
         admin.createTable(desc );
         admin.close();
         //admin.disableTable("blog");
         //admin.deleteTable("blog");
         //assertThat(admin.tableExists("blog"),is(false));
   }
}





注释:
   conf.set("hbase.zookeeper.quorum", " master ");//使用eclipse时必须添加这个,否则无法定位
这里因为使用的是win7,所以master需要配置hosts。如下图所示
 



hosts的路径为C:\Windows\System32\drivers\etc







得到结果:我们看到blog就创建成功了。

 

这里说一下:
HTableDescriptor的初始化发生变化:
 

新API
  HTableDescriptor desc=new HTableDescriptor(TableName.valueOf("blog"));
旧API
  HTableDescriptor desc = new HTableDescriptor("blog");

     值得注意的是,如果你是用的Hbase集群,在代码 conf.set("hbase.zookeeper.quorum", "master");

       你可以配置自己的hosts文件,也就是你搭建的Hbase集群。这样就不会报错!

conf.set("hbase.zookeeper.quorum","dam01:2181,dam02:2181,dam03:2181");


OK!

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值