hbase开发环境搭建及运行hbase小实例

转载请注明:云帆大数据学院 » hbase开发环境搭建及运行hbase小实例

我们采用的是添加包的方式。
      首先需要下载安装包:

1.安装包下载
可以通过官网下载:
http://mirror.bit.edu.cn/apache/hbase/hbase-0.98.3/

2.添加包
(1)我们解压包
解压之后,得到如下包

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

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

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

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

搭建完毕,我们先做个简单的例子吧
就创建一个blog表。
1.首先通过list命令查看表

2.我们运行下面程序:

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”);


  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值