package com.run.hbase.dataImport;
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.HConstants;
import org.apache.hadoop.hbase.HRegionInfo;
import org.apache.hadoop.hbase.HTableDescriptor;
import org.apache.hadoop.hbase.MasterNotRunningException;
import org.apache.hadoop.hbase.ZooKeeperConnectionException;
import org.apache.hadoop.hbase.client.HBaseAdmin;
import org.apache.hadoop.hbase.client.HTable;
import org.apache.hadoop.hbase.client.Put;
import org.apache.hadoop.hbase.util.Bytes;
import org.apache.hadoop.hbase.util.Writables;
public class CreateRegion {
public static HTable getMetaTable(Configuration conf) throws IOException {
return new HTable(conf, HConstants.META_TABLE_NAME);
}
public static HBaseAdmin getHBaseAdmin(Configuration conf) throws MasterNotRunningException,
ZooKeeperConnectionException {
return new HBaseAdmin(conf);
}
public static void createEmptyRegion(Configuration conf, HTableDescriptor tblDes,
byte[] startKey, byte[] endKey) throws IllegalArgumentException, IOException,
InterruptedException {
HRegionInfo hri = new HRegionInfo(tblDes, startKey, endKey);
Put put = new Put(hri.getRegionName());
put
.add(HConstants.CATALOG_FAMILY, HConstants.REGIONINFO_QUALIFIER, Writables
.getBytes(hri));
HTable metatable = getMetaTable(conf);
metatable.put(put);
HBaseAdmin admin = getHBaseAdmin(conf);
// flush .META. data to hdfs.
admin.flush(metatable.getTableName());
admin.assign(hri.getRegionName(), true);
}
public static void main(String[] args) {
System.out.println("masterip 2181 startkey endkey tablename columnfamily");
Configuration conf = HBaseConfiguration.create();
conf.set("hbase.zookeeper.quorum", args[0]);//master0,slave1,slave2
conf.set("hbase.zookeeper.property.clientPort", args[1]);
conf.set("hbase.master", args[0] + ":60000");
HTableDescriptor tblDes = new HTableDescriptor(args[4]);
HColumnDescriptor cf = new HColumnDescriptor(args[5]);
tblDes.addFamily(cf);
byte[] startKeys = Bytes.toBytes(args[2]);
byte[] endKeys = Bytes.toBytes(args[3]);
try {
createEmptyRegion(conf, tblDes, startKeys, endKeys);
} catch (IllegalArgumentException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
|
相关推荐
HBase集群搭建
关于HBase集群监控在java代码中的实现操作,供大家参考
搭建hbase集群的详细操作;搭建hbase集群的详细操作;
hbase需要搭建集群,这里详细的介绍了集群的安装方式以及配置文件的一些修改
zookeeper+hbase集群搭建+搭建过程报错解决+原理,通俗易懂,详细配置注解!!!
2. JDK安装部署 3. Zookeeper安装部署 4. Nginx安装部署 5. Hadoop安装部署 6. HBase安装部署 7. MongoDB数据库安装部署; 8. ElasticSearch集群安装部署; 9. 应用服务器的安装及部署
一步一步教你在WINDOW CYGWIN下完成HBASE集群环境搭建。
hbase集群部署文档,附带简单基本命令、!!!!!!!
HBase集群环境搭建
HBase2集群配置.pdf HBase2集群配置.pdf HBase2集群配置.pdf HBase2集群配置.pdf
新手Hadoop_hbase集群搭建,3台服务器节点Centos7,Hadoop2.7.4,HBase1.3.1,jdk8,zookpeer3.4.10 安装包也将上传,亲手搭建编写文档
HBase集群环境安装
hadoop-2.52-hbase-0.14-hadoop2 ha高可用安装,hbase动态添加删除节点,hbase集群正常状态及启动,hbase 问题汇总
文档是我自己一步步完成实验写成的,给初学大数据的朋友共享一下希望能有所帮助
hadoop+hbase集群搭建 详细手册
docker版hbase集群构建,从docker安装开始,再到docker中下载并运行hadoop镜像,之后下载并配置hbase。最后对整个流程做总结,遇到的问题,以及一些docker基础知识和hbase教程。
记录我的学习之旅,每份文档倾心倾力,带我成我大牛,回头观望满脸笑意,望大家多多给予意见,有问题或错误,请联系 我将及时改正;借鉴文章标明出处,谢谢
月光宝盒双11-HBase集群应用和优化经验
月光宝盒双11-HBase集群应用和优化经验
数据仓库hadoop+zookeeper+hbase集群安装方法记录,自己搭建纯手写的记录。相关软件请自行下载