Centos6.5裏安裝Hbase(僞分布式)

首先我们到官方网站下载Hbase,而我使用的版本是hbase-0.94.27.tar.gz

解压下来:

tar zxvf hbase-0.94.27.tar.gz

寻找java安装路径

[[email protected] conf]# which java
/usr/bin/java

我们找到java的安装路径

/usr/bin/java

所以hbase的配置,如下:

 vim hbase-env.sh 

export JAVA_HOME=/usr

启动:

[[email protected] bin]# ./start-hbase.sh 
starting master, logging to /root/hbase_soft/hbase-0.94.27/bin/../logs/hbase-root-master-localhost.localdomain.out

hbase已经启动了:

Centos6.5裏安裝Hbase(僞分布式)
Centos6.5裏安裝Hbase(僞分布式)
[[email protected] bin]# ps ax  grep hbase
 7385 pts/3    Sl     0:07 /usr/bin/java -XX:OnOutOfMemoryError=kill -9 %p -Xmx1m -XX:+UseConcMarkSweepGC -Dhbase.log.dir=/root/hbase_soft/hbase-0.94.27/bin/../logs -Dhbase.log.file=hbase-root-master-localhost.localdomain.log -Dhbase.home.dir=/root/hbase_soft/hbase-0.94.27/bin/.. -Dhbase.id.str=root -Dhbase.root.logger=INFO,DRFA -Djava.library.path=/root/hbase_soft/hbase-0.94.27/bin/../lib/native/Linux-amd64-64 -Dhbase.security.logger=INFO,DRFAS -classpath /root/hbase_soft/hbase-0.94.27/bin/../conf:/usr/lib/tools.jar:/root/hbase_soft/hbase-0.94.27/bin/..:/root/hbase_soft/hbase-0.94.27/bin/../hbase-0.94.27.jar:/root/hbase_soft/hbase-0.94.27/bin/../hbase-0.94.27-tests.jar:/root/hbase_soft/hbase-0.94.27/bin/../lib/activation-1.1.jar:/root/hbase_soft/hbase-0.94.27/bin/../lib/asm-3.1.jar:/root/hbase_soft/hbase-0.94.27/bin/../lib/avro-1.5.3.jar:/root/hbase_soft/hbase-0.94.27/bin/../lib/avro-ipc-1.5.3.jar:/root/hbase_soft/hbase-0.94.27/bin/../lib/commons-beanutils-1.7.0.jar:/root/hbase_soft/hbase-0.94.27/bin/../lib/commons-beanutils-core-1.8.0.jar:/root/hbase_soft/hbase-0.94.27/bin/../lib/commons-cli-1.2.jar:/root/hbase_soft/hbase-0.94.27/bin/../lib/commons-codec-1.4.jar:/root/hbase_soft/hbase-0.94.27/bin/../lib/commons-collections-3.2.1.jar:/root/hbase_soft/hbase-0.94.27/bin/../lib/commons-configuration-1.6.jar:/root/hbase_soft/hbase-0.94.27/bin/../lib/commons-digester-1.8.jar:/root/hbase_soft/hbase-0.94.27/bin/../lib/commons-el-1.0.jar:/root/hbase_soft/hbase-0.94.27/bin/../lib/commons-httpclient-3.1.jar:/root/hbase_soft/hbase-0.94.27/bin/../lib/commons-io-2.1.jar:/root/hbase_soft/hbase-0.94.27/bin/../lib/commons-lang-2.5.jar:/root/hbase_soft/hbase-0.94.27/bin/../lib/commons-logging-1.1.1.jar:/root/hbase_soft/hbase-0.94.27/bin/../lib/commons-math-2.1.jar:/root/hbase_soft/hbase-0.94.27/bin/../lib/commons-net-1.4.1.jar:/root/hbase_soft/hbase-0.94.27/bin/../lib/core-3.1.1.jar:/root/hbase_soft/hbase-0.94.27/bin/../lib/guava-11.0.2.jar:/root/hbase_soft/hbase-0.94.27/bin/../lib/hadoop-core-1.0.4.jar:/root/hbase_soft/hbase-0.94.27/bin/../lib/hamcrest-core-1.3.jar:/root/hbase_soft/hbase-0.94.27/bin/../lib/high-scale-lib-1.1.1.jar:/root/hbase_soft/hbase-0.94.27/bin/../lib/httpclient-4.1.2.jar:/root/hbase_soft/hbase-0.94.27/bin/../lib/httpcore-4.1.3.jar:/root/hbase_soft/hbase-0.94.27/bin/../lib/jackson-core-asl-1.8.8.jar:/root/hbase_soft/hbase-0.94.27/bin/../lib/jackson-jaxrs-1.8.8.jar:/root/hbase_soft/hbase-0.94.27/bin/../lib/jackson-mapper-asl-1.8.8.jar:/root/hbase_soft/hbase-0.94.27/bin/../lib/jackson-xc-1.8.8.jar:/root/hbase_soft/hbase-0.94.27/bin/../lib/jamon-runtime-2.3.1.jar:/root/hbase_soft/hbase-0.94.27/bin/../lib/jasper-compiler-5.5.23.jar:/root/hbase_soft/hbase-0.94.27/bin/../lib/jasper-runtime-5.5.23.jar:/root/hbase_soft/hbase-0.94.27/bin/../lib/jaxb-api-2.1.jar:/root/hbase_soft/hbase-0.94.27/bin/../lib/jaxb-impl-2.2.3-1.jar:/root/hbase_soft/hbase-0.94.27/bin/../lib/jersey-core-1.8.jar:/root/hbase_soft/hbase-0.94.27/bin/../lib/jersey-json-1.8.jar:/root/hbase_soft/hbase-0.94.27/bin/../lib/jersey-server-1.8.jar:/root/hbase_soft/hbase-0.94.27/bin/../lib/jettison-1.1.jar:/root/hbase_soft/hbase-0.94.27/bin/../lib/jetty-6.1.26.jar:/root/hbase_soft/hbase-0.94.27/bin/../lib/jetty-util-6.1.26.jar:/root/hbase_soft/hbase-0.94.27/bin/../lib/jruby-complete-1.6.5.jar:/root/hbase_soft/hbase-0.94.27/bin/../lib/jsp-2.1-6.1.14.jar:/root/hbase_soft/hbase-0.94.27/bin/../lib/jsp-api-2.1-6.1.14.jar:/root/hbase_soft/hbase-0.94.27/bin/../lib/jsr305-1.3.9.jar:/root/hbase_soft/hbase-0.94.27/bin/../lib/junit-4.11.jar:/root/hbase_soft/hbase-0.94.27/bin/../lib/libthrift-0.8.0.jar:/root/hbase_soft/hbase-0.94.27/bin/../lib/log4j-1.2.16.jar:/root/hbase_soft/hbase-0.94.27/bin/../lib/metrics-core-2.1.2.jar:/root/hbase_soft/hbase-0.94.27/bin/../lib/netty-3.2.4.Final.jar:/root/hbase_soft/hbase-0.94.27/bin/../lib/protobuf-java-2.4.0a.jar:/root/hbase_soft/hbase-0.94.27/bin/../lib/servlet-api-2.5-6.1.14.jar:/root/hbase_soft/hbase-0.94.27/bin/../lib/slf4j-api-1.4.3.jar:/root/hbase_soft/hbase-0.94.27/bin/../lib/slf4j-log4j12-1.4.3.jar:/root/hbase_soft/hbase-0.94.27/bin/../lib/snappy-java-
View Code

终端使用:

Centos6.5裏安裝Hbase(僞分布式)
Centos6.5裏安裝Hbase(僞分布式)
[[email protected] hbase-0.94.27]# ./bin/hbase shell
HBase Shell; enter 'help<RETURN>' for list of supported commands.
Type "exit<RETURN>" to leave the HBase Shell
Version 0.94.27, rfb434617716493eac82b55180b0bbd653beb90bf, Thu Mar 19 06:17:55 UTC 2015

hbase(main):001:0> create 'test', 'cf'
0 row(s) in 1.6440 seconds

hbase(main):002:0> list 'table'
TABLE                                                                                                                                                  
0 row(s) in 0.0220 seconds

hbase(main):003:0> put 'test', 'row1', 'cf:a', 'value1'
0 row(s) in 0.1190 seconds

hbase(main):004:0> put 'test', 'row2', 'cf:b', 'value2'
0 row(s) in 0.0140 seconds

hbase(main):005:0> put 'test', 'row3', 'cf:c', 'value3'
0 row(s) in 0.0090 seconds

hbase(main):006:0> scan 'test'
ROW                                    COLUMN+CELL                                                                                                     
 row1                                  column=cf:a, timestamp=1437493507138, value=value1                                                              
 row2                                  column=cf:b, timestamp=1437493514968, value=value2                                                              
 row3                                  column=cf:c, timestamp=1437493520531, value=value3                                                              
3 row(s) in 0.0790 seconds

hbase(main):007:0> get 'test', 'row1'
COLUMN                                 CELL                                                                                                            
 cf:a                                  timestamp=1437493507138, value=value1                                                                           
1 row(s) in 0.0250 seconds

hbase(main):008:0> 
View Code

若要进行分布式,可修改 hbase-site.xml文件如下:

 

Centos6.5裏安裝Hbase(僞分布式)
Centos6.5裏安裝Hbase(僞分布式)
<property>
<name>hbase.cluster.distributed</name>
<value>true</value>
</property>
<property>
<name>hbase.rootdir</name>
<value>hdfs://hadoop:9/hbase</value>
</property>
View Code

 

 

连接的客户端代码如下:(我没跑成功,求高人指导)

Centos6.5裏安裝Hbase(僞分布式)
Centos6.5裏安裝Hbase(僞分布式)
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.KeyValue;
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.client.Result;
import org.apache.hadoop.hbase.client.ResultScanner;
import org.apache.hadoop.hbase.client.Scan;
import org.eclipse.jdt.internal.core.BatchOperation;

public class HBaseDBDao {
    
    //定义配置对象HBaseConfiguration
    static Configuration conf =null;
    static {
//        Configuration configuration = new Configuration();
//        configuration.set("hbase.zookeeper.property.clientPort","2181");
//        configuration.set("hbase.zookeeper.quorum", "192.168.1.112"); 
//        configuration.set("hbase.master", "192.168.1.112:60"); 
//        cfg = new HBaseConfiguration(configuration);
        conf = HBaseConfiguration.create();
        conf.set("hbase.zookeeper.property.clientPort","2181");
        conf.set("hbase.zookeeper.quorum", "192.168.1.112");
//        conf.set("hbase.master", "192.168.1.112:60");
    }
    
    //创建一张表,指定表名,列族
    public static void createTable(String tableName,String columnFarily)throws Exception{
        HBaseAdmin admin = new HBaseAdmin(conf);
        if(admin.tableExists(tableName)){
            System.out.println(tableName+"不存在!");
            System.exit(0);
        }else{
            HTableDescriptor  tableDesc = new HTableDescriptor(tableName);
            tableDesc.addFamily(new HColumnDescriptor(columnFarily+":"));
            System.out.println("创建表成功!");
        }
    }
    
    //添加数据,通过HTable。和BatchUpdate为已经存在的表添加数据data
//    public static void addData(String tableName,String row,String columnFamily,String column,String data)throws Exception{
//        HTable table = new HTable(cfg,tableName);
//        Put update = new Put(row);
//        update.put(columnFamily+":"+column, data.getBytes());
//        table.commit(update);
//        System.out.println("添加成功!");
//    }
    
    //显示所有数据,通过HTable Scan类获取已有表的信息
    public static void getAllData(String tableName)throws Exception{
        HTable table = new HTable(conf,tableName);
        Scan scan = new Scan();
        ResultScanner rs = table.getScanner(scan);
        for(Result r:rs){
            for(KeyValue kv:r.raw()){
                System.out.println(new String(kv.getKey())+new String(kv.getValue()));
            }
        }
    }
    
    //测试函数
    public static void main(String[] args){
        try{
            String tableName = "student";
            HBaseDBDao.createTable(tableName, "c1");
//            HBaseDBDao.addData(tableName, "row1", "c1", "1", "this is row 1 column c1:c1");
            HBaseDBDao.getAllData(tableName);
        }catch(Exception e){
            e.printStackTrace();
        }
    }
}
View Code

 

参考:

http://hbase.apache.org/book.html

http://hbase.apache.org/

http://blog.csdn.net/zwhfyy/article/details/8349788

http://niuzhenxin.iteye.com/blog/1447769

http://abloz.com/hbase/book.html

http://www.paul4llen.com/installing-apache-hbase-on-centos-6/ 

http://cn.soulmachine.me/blog/20140208/

http://blog.csdn.net/wuwenxiang91322/article/details/44684655

http://www.oschina.net/question/54100_24054

http://www.cnblogs.com/heyCoding/archive/2012/11/09/2762334.html

http://www.cnblogs.com/zhenjing/p/hbase_example.html

http://www.cnblogs.com/panfeng412/archive/2011/08/14/2137984.html

http://www.cnblogs.com/caca/p/centos_hadoop_install.html

http://www.cnblogs.com/elaron/archive/2013/01/05/2846803.html

http://www.cnblogs.com/Dreama/articles/2219190.html

更多相关文章
  • Centos6.5裏安裝Erlang 並安裝riak
    一.Erlang安装: 1 首先进入www.erlang.org 下载页面,下载otp_s
  • 换了macbook pro之后,要重新安装hadoop,但是mac上的jdk跟windows上的不同,导致折腾了挺久的,现在分享出来,希望对大家有用. 一:下载jdk 选择最新版本下载,地址:http://www.oracle.com/technetwork/java/javase/download
  • 


    		    在hadoop2.2上安裝hbase 集成zookeeper
    如果想详细了解hbase的安装:http://abloz.com/hbase/book.html 和官网http://hbase.apache.org/ 1. 快速单击安装 在单机安装Hbase的方法.会引导你通过shell创建一个表,插入一行,然后删除它,最后停止Hbase.只要10分钟就可以完成 ...
  • 一.应该先配置好zookeeper并成功启动,否则hbase无法启动 二.配置HBASE集群 1,配置hbase-env.sh,下面是最少配置项目 [[email protected] conf]$ vim hbase-env.sh export JAVA_HOME=/usr/java/jdk1.7.0_60 e
  • 通過tarball形式安裝HBASE Cluster(CDH5.0.2)——配置分布式集群中的YARN ResourceManager 的HA
    <?xml version="1.0"?> <!-- Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file exce ...
  • 集群安装总览参见这里 Zookeeper的配置 1,/etc/profile中加入zk的路径设置,见上面背景说明.     2,进入~/zk/conf目录,zoo_sample.cfg为zoo.cfg     vim
  • Centos(64位)安裝Hbase詳細步驟
    HBase是一个分布式的.面向列的开源数据库,该技术来源于 Fay Chang 所撰写的Google论文“Bigtable:一个结构化数据的分布式存储系统”.就像Bigtable利用了Google文件系统(File System)所提供的分布式数据存储一样,HBase在Hadoop之上提供了类似于B ...
  • 在hadoop2.5.2伪分布式上,安装了hbase1.0.1.1的伪分布式 利用HBase的API创建个testapi的表时,提示  Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/ha ...
一周排行