首页 > 系统服务 > 详细

hbase连接linux开发过程

时间:2017-04-12 02:35:57      阅读:215      评论:0      收藏:0      [点我收藏+]

最近近公司被安排做hbase开发,太久没做今天记录下过程

import java.io.IOException;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.Path;
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;


public class getHbaseConfiguration {

private static Configuration conf = null;
public getHbaseConfiguration()
{

}

//这里必须预先处理化不然不然可能会出现未初始化conf就开始使用的问题
static
{
if(null == conf)
{
conf = HBaseConfiguration.create();
Path path = new Path("hbase-site.xml");
conf.addResource(path);
}
// return conf;
}
public void createTable(String tableName) throws IOException
{

HBaseAdmin admin = new HBaseAdmin(conf);
if(admin.tableExists(tableName))
{
System.out.println("Exists tables");
}
HTableDescriptor hTabeDescriptor = new HTableDescriptor("tableName");
hTabeDescriptor.addFamily(new HColumnDescriptor("cf1"));
admin.createTable(hTabeDescriptor);

}
public static void main(String[] args) {
//new getHbaseConfiguration().getInstance();
try {
new getHbaseConfiguration().createTable("test_1");
} catch (IOException e) {
e.printStackTrace();
}
}
}

被初始化的conf要求,可以从集群中hbase目录下conf拷贝,记得集群先hbase shell ---list测试集群可用否

<?xml version="1.0"?>
<?xml-stylesheet type="text/xsl" href="configuration.xsl"?>
<!--
/**
*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-->
<configuration>
<property>
<name>hbase.rootdir</name>
<value>hdfs://CDHProject1:9000/hbase</value>
</property>
<property>
<name>hbase.cluster.distributed</name>
<value>true</value>
</property>
<property>
<name>hbase.tmp.dir</name>
<value>/home/hadoop/bigdata/softs/hbase-1.0.0-cdh5.5.5/data/tmp</value>
</property>
<!-- zookeeper- -->
<property>
<name>hbase.zookeeper.quorum</name>
<value>CDHProject1,CDHProject2,CDHProject3</value>
</property>
<property>
<name>hbase.zookeeper.property.clientPort</name>
<value>2181</value>
</property>
</configuration>

 

hbase连接linux开发过程

原文:http://www.cnblogs.com/yaohaitao/p/6696882.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!