private static Admin admin = null;
private static final String user = "admin/admin@DEMO.COM";
private static final String keyPath = "/etc/security/keytabs/admin.keytab";
static {
System.setProperty("java.security.krb5.conf", "/etc/krb5.conf");
System.setProperty("sun.security.krb5.debug", "false");
Configuration conf = new Configuration();
conf.addResource("hbase-site.xml");
conf.set("hbase.zookeeper.quorum", "storm4.demo.com,storm2.demo.com,storm3.demo.com");
conf.set(HConstants.ZOOKEEPER_CLIENT_PORT, "2181");
conf.set(HConstants.ZOOKEEPER_ZNODE_PARENT, "/hbase-secure");
conf.set("hbase.security.authentication", "kerberos");
conf.set("hadoop.security.authentication", "kerberos");
UserGroupInformation.setConfiguration(conf);
try {
UserGroupInformation.loginUserFromKeytab(user, keyPath);
} catch (IOException e) {
e.printStackTrace();
}
Connection connection= null;
try {
connection = ConnectionFactory.createConnection(conf);
} catch (IOException e) {
e.printStackTrace();
}
try {
admin = connection.getAdmin();
} catch (IOException e) {
e.printStackTrace();
}
}
public synchronized static Table getTable(String tableName) {
try {
return TABLE_MAP.get(tableName);
} catch (ExecutionException e) {
e.printStackTrace();
}
return null;
}
public synchronized static void createTable(String tableName) throws HBaseException {
TableName table = TableName.valueOf(tableName);
TableDescriptorBuilder tableDesc = TableDescriptorBuilder.newBuilder(table)
tableDesc.setValue(TableDescriptorBuilder.SPLIT_POLICY, classOf[DelimitedKeyPrefixRegionSplitPolicy].getName)
tableDesc.setValue(DelimitedKeyPrefixRegionSplitPolicy.DELIMITER_KEY, "|") //以|作为分区前缀
ColumnFamilyDescriptor extCF = ColumnFamilyDescriptorBuilder.newBuilder("ext".getBytes()).setTimeToLive("90 DAYS").build();
ColumnFamilyDescriptor deviceCF = ColumnFamilyDescriptorBuilder.newBuilder("device".getBytes()).setTimeToLive("90 DAYS").build();
ColumnFamilyDescriptor locationCF = ColumnFamilyDescriptorBuilder.newBuilder("location".getBytes()).setTimeToLive("90 DAYS").build();
tableDesc.setColumnFamilies(Arrays.asList(extCF, locationCF, deviceCF));
try {
val regionServers = 8
val splitKeys = (0 until 256 by regionServers).map(Integer.toHexString).map(i => s"0$i".takeRight(2)).map(Bytes.toBytes).toArray
admin.createTable(tableDesc.build(), splitKeys); //预分区
} catch (IOException e) {
e.printStackTrace();
}
}
public static void main(String[] args) {
try {
createTable("DSP_LOG_TABLE");
} catch (HBaseException e) {
e.printStackTrace();
}
}
hbase - 预分区创建表
©著作权归作者所有,转载或内容合作请联系作者
- 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
- 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
- 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
推荐阅读更多精彩内容
- Hbase RowKey 设计 使用Spark或通过REST/API 方式存取Hbase,性能影响最大的因素在于H...