`

HBase配置以及在Windows下连接HBase设置

 
阅读更多

本文介绍了在Linux环境下以单机模式安装HBase,并在Windows下使用Eclipse进行开发时连接HBase的相关设置。

1、  安装Linux系统(ubuntu 10.04server)安装时请安装上附加的open ssh-server。机器名字:ubuntu(cat /etc/hostname,结果是ubuntu)

2、  安装java,设置环境变量。在/etc/profile末尾追加下面三行。

exportJAVA_HOME="/home/had/jdk1.6.0_20"

exportCLASSPATH=.:$CLASSPATH:$JAVA_HOME/lib

export PATH=.:$PATH:$JAVA_HOME/bin

         其中JAVA_HOME指向的目录是java安装目录

3、  ssh上传hbase-0.90.4.tar.gz至/home/had目录。tar xzf hbase-0.90.4.tar.gz解压

4、  进入hbase-0.90.4目录,编辑conf/hbase-site.xml文件,在configuration里面加入:

<property>

           <name>hbase.rootdir</name>

           <value>/home/had/hbase-0.90.4/data</value>

</property>

作用是将数据存储路径设置在value指定的目录

5、  Linux Ubuntu 10.04 server./etc/hosts

a)        注释掉127.0.1.1     ubuntu.localdomain      Ubuntu

b)        加一行192.168.128.128  ubuntu  

                        i.             192.168.128.128是本机ip

                      ii.             ubuntu是机器名

6、  测试hbase:

a)        cd hbase-0.90.4

b)        bin/start-hbase.sh

c)        bin/hbase shell

d)        create  ‘database’,’cf’

e)        list

f)         如果成功则可以看到有下面的结果:

hbase(main):001:0>list

TABLE                                                                                                                                                                             

database                                                                                                                                                                          

1 row(s)in 0.5910 seconds

 

hbase(main):002:0>

http://192.168.128.128:60010/master.jsp这个页面也可看到相应信息

7、  windows c:/windows/system32/dirvers/hosts文件加一行:

192.168.128.128 ubuntu 

使得windows将ubuntu解析为ip地址192.168.128.128

8、  打开eclipse,新建工程,将hbase-0.90.4下面的lib目录拷贝到工程,将其中的jar包加入classpath

9、  新建一类HelloHbase:

java 写道
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.util.Bytes;


public class HelloHBase {
public static void main(String[] args) throws IOException {
Configuration conf = HBaseConfiguration.create();
conf.set("hbase.zookeeper.quorum", "192.168.128.128");
HBaseAdmin admin = new HBaseAdmin(conf);
HTableDescriptor tableDescriptor = admin.getTableDescriptor(Bytes.toBytes("database"));
byte[] name = tableDescriptor.getName();
System.out.println(new String(name));
HColumnDescriptor[] columnFamilies = tableDescriptor.getColumnFamilies();
for (HColumnDescriptor d : columnFamilies) {
System.out.println(d.getNameAsString());
}
}
}

 

运行,此时应该打印出下面两行:

database

cf

若没有,说明配置失败,请检查其他设置。

 

其中,第5、7步以及代码中的conf.set("hbase.zookeeper.quorum","192.168.128.128");一行至关重要。决定着能否在windows上连上HBase。

 

 

参考资料:

HBase官方文档:http://hbase.apache.org/book/quickstart.html

HBase 中文文档:http://www.yankay.com/wp-content/hbase/book.html

解决在其它机器使用Eclipse开发连接HBase出现异常时的参考资料:http://hi.baidu.com/laozhenghit/blog/item/987608440c76d5146a63e523.html

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics