51cto赵强HADOOP学习(九)

2017-12-16  本文已影响0人  lehuai

Hbase

一个基于HDFS的NoSQL数据库

起源于Big Table的思想

面向列

HBase的体系结构和数据模型

image.png
image.png

HBase数据存储的逻辑结构

image.png

开启全分布模式的虚拟机。

hadoop31:

Hbase本地模式

# tar -zxvf hbase-0.96.2-hadoop2-bin.tar.gz -C ~/training/
# cd ~/training/
# cd hbase-0.96.2-hadoop2/
# cd conf
# vi hbase-env.sh 
export JAVA_HOME=/root/training/jdk1.8.0_144
#cd ..
#mkdir data
#cd conf
vi hbase-site.xml
<property>
        <name>hbase.rootdir</name>
        <value>file:///root/training/hbase-0.96.2-hadoop2/data</value>
</property>
#cd ..
#bin/start-hbase.sh
#jps
#bin/hbase shell
quie
#bin/stop-hbase.sh

hbase伪分布模式

#vi .bash_profile
export HBASE_HOME=/root/training/hbase-0.96.2-hadoop2

export PATH=$HBASE_HOME/bin:$PATH
#source .bash_profile
# cd training/hbase-0.96.2-hadoop2/conf/
#vi hbase-env.sh
export HBASE_MANAGES_ZK=true   //去掉前面的注释就可以
#vi hbase-site.xml
<property>
    <name>hbase.rootdir</name>
    <value>hdfs://192.168.56.31:9000/hbase</value>
</property>
<property>
    <name>hbase.cluster.distributed</name>
    <value>true</value>
</property>
<property>
    <name>hbase.zookeeper.quorum</name>
    <value>192.168.56.21</value>
</property>
<property>
    <name>dfs.replication</name>
    <value>1</value>
</property>

#vi regionservers
localhost
#cd ~/training
#start-dfs.sh
#start-hbase.sh
#stop-hbase.sh

HBase的集群模式

#pwd
/root/training
# cd hbase-0.96.2-hadoop2/conf/
#vi hbase-site.xml
<property>
    <name>dfs.replication</name>
    <value>2</value>            //伪分布是1,这里要改成2
</property>
<property>
    <name>hbase.master.maxclockskew</name>
    <value>180000</value>
</property>

#vi regionservers 
192.168.56.22
192.168.56.23
192.168.56.24
#cd ../..
# scp -r hbase-0.96.2-hadoop2/ root@hadoop22:~/training/
# scp -r hbase-0.96.2-hadoop2/ root@hadoop23:~/training/
# scp -r hbase-0.96.2-hadoop2/ root@hadoop24:~/training/

hadoop22,23,24

#vi ~/.bash_profile
export HBASE_HOME=/root/training/hbase-0.96.2-hadoop2

export PATH=$HBASE_HOME/bin:$PATH
#source ~/.bash_profile

hadoop21:

#start-hbase.sh
#jps
#hbase shell
quit

在浏览器浏览

192.168.56.21:60010

使用HBase Shell

hbase shell
>create 'students','info','grade'
>list
>describe 'students'
>put 'students','stu01','info:name','Tom'
>put 'students','stu01','info:age','20'
>put 'students','stu01','info:grade:chinese','80'
>scan 'students'

HBase的Java编程接口

HBaseDemo.java

import java.io.IOException;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hbase.HColumnDescriptor;
import org.apache.hadoop.hbase.HTableDescriptor;
import org.apache.hadoop.hbase.MasterNotRunningException;
import org.apache.hadoop.hbase.TableName;
import org.apache.hadoop.hbase.ZooKeeperConnectionException;
import org.apache.hadoop.hbase.client.HBaseAdmin;
import org.junit.Test;

public class HBaseDemo {
    
    @Test
    public void testCreateTable() throws Exception {
        //指明ZK的地址
        Configuration conf = new Configuration();
        conf.set("hbase.zookeeper.quorum", "192.168.56.21");
        
        //创建一个HBaseAdmin
        HBaseAdmin admin = new HBaseAdmin(conf);
        
        //指明表的信息
        HTableDescriptor td = new HTableDescriptor(TableName.valueOf("students01"));
        
        //指明列族
        HColumnDescriptor cdInfo = new HColumnDescriptor("info");
        HColumnDescriptor cdGrade = new HColumnDescriptor("grade");
        
        //将列族加入表
        td.addFamily(cdInfo);
        td.addFamily(cdGrade);
        
        //创建表
        admin.createTable(td);
        
        admin.close();
        
    }
    
    @Test
    public void testPut() {
        
    }
    
    @Test
    public void testGet() {
        
    }

}

Oracle的回收站

上一篇下一篇

猜你喜欢

热点阅读