• HBase 2.x ---- HBase快速入门


    1. HBase安装部署

    1. Zookeeper正常部署

    首先保证 zookeeper 集群的正常部署,并启动之。

    [fickler@hadoop102 zookeeper-3.5.7]$ bin/zkServer.sh start
    [fickler@hadoop103 zookeeper-3.5.7]$ bin/zkServer.sh start
    [fickler@hadoop104 zookeeper-3.5.7]$ bin/zkServer.sh start
    
    • 1
    • 2
    • 3

    2. Hadoop正常部署

    Hadoop 集群的正常部署并启动

    [fickler@hadoop102 hadoop-3.1.3]$ sbin/start-dfs.sh
    [fickler@hadoop103 hadoop-3.1.3]$ sbin/start-yarn.sh
    
    • 1
    • 2

    3. HBase的解压

    1. 解压 HBase 到指定目录
    [fickler@hadoop102 software]$ tar -zxvf hbase-2.4.11-bin.tar.gz -C /opt/module/
    [fickler@hadoop102 module]$ mv /opt/module/hbase-2.4.11 /opt/module/hbase
    
    • 1
    • 2
    1. 配置环境变量
    [fickler@hadoop102 hbase]$ sudo vim /etc/profile.d/my_env.sh
    
    • 1

    添加

    #HBASE_HOME
    export HBASE_HOME=/opt/module/hbase
    export PATH=$PATH:$HBASE_HOME/bin
    
    • 1
    • 2
    • 3
    1. 使用 source 让配置环境变量生效
    [fickler@hadoop102 hbase]$ source /etc/profile.d/my_env.sh
    
    • 1

    4. HBase的配置文件

    1. hbase-env.sh 修改内容,可以添加到最后:
    export HBASE_MANAGES_ZK=false
    
    • 1
    1. hbase-site.xml 修改内容
    
    
    <configuration>
     <property>
     <name>hbase.zookeeper.quorumname>
     <value>hadoop102,hadoop103,hadoop104value>
     <description>The directory shared by RegionServers.
     description>
     property>
    
    
    
    
    
    
    
     <property>
     <name>hbase.rootdirname>
     <value>hdfs://hadoop102:8020/hbasevalue>
     <description>The directory shared by RegionServers.
     description>
     property>
     <property>
     <name>hbase.cluster.distributedname>
     <value>truevalue>
     property>
    configuration>
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    1. regionservers
    hadoop102
    hadoop103
    hadoop104
    
    • 1
    • 2
    • 3
    1. 解决 HBase 和 Hadoop 的 log4j 兼容性问题,修改 HBase 的 jar 包,使用 Hadoop 的 jar 包
    mv /opt/module/hbase/lib/client-facing-thirdparty/slf4j-reload4j-1.7.33.jar /opt/module/hbase/lib/client-facing-thirdparty/slf4j-reload4j-1.7.33.jar.bak
    
    • 1

    5. HBase远程发送到其他集群

    [fickler@hadoop102 module]$ xsync hbase/
    
    • 1

    6. HBase服务的启动

    1. 单点启动
    [fickler@hadoop102 hbase]$ bin/hbase-daemon.sh start master
    [fickler@hadoop102 hbase]$ bin/hbase-daemon.sh start regionserver
    
    • 1
    • 2
    1. 群启
    [fickler@hadoop102 hbase]$ bin/start-hbase.sh
    
    • 1
    1. 对应的停止服务
    [fickler@hadoop102 hbase]$ bin/stop-hbase.sh
    
    • 1

    7. 查看HBase页面

    启动成功后,可以通过 “host:port” 的方式来访问 HBase 管理页面:
    http://hadoop102:16010/master-status
    在这里插入图片描述

    2. HBase Shell操作

    1. 基本操作

    1. 进入 HBase 客户端命令行
    [fickler@hadoop102 hbase]$ bin/hbase shell
    HBase Shell
    Use "help" to get list of supported commands.
    Use "exit" to quit this interactive shell.
    For Reference, please visit: http://hbase.apache.org/2.0/book.html#shell
    Version 2.4.11, r7e672a0da0586e6b7449310815182695bc6ae193, Tue Mar 15 10:31:00 PDT 2022
    Took 0.0012 seconds
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    1. 查看帮助命令
      能够展示 HBase 中所有能使用的命令,主要的命令有 namespace 命令空间相关,DDL 创建修改表格,DML 写入读取数据。
    hbase:001:0> help
    
    • 1

    在这里插入图片描述

    2. namespace

    1. 创建命名空间
      使用特定的 help 语法能够查看命令如何使用。
    hbase:003:0> help 'create_namespace'
    Create namespace; pass namespace name,
    and optionally a dictionary of namespace configuration.
    Examples:
    
      hbase> create_namespace 'ns1'
      hbase> create_namespace 'ns1', {'PROPERTY_NAME'=>'PROPERTY_VALUE'}
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    1. 创建命名空间 bigdata
    hbase:004:0> create_namespace 'bigdata'
    Took 0.4769 seconds
    
    • 1
    • 2
    1. 查看所有的命名空间
    hbase:005:0> list_namespace
    NAMESPACE                                                                                                   
    bigdata                                                                                                     
    default                                                                                                     
    hbase                                                                                                       
    3 row(s)
    Took 0.0385 seconds
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7

    3. DDL

    1. 创建表
      在 bigdata 命名空间中创建表格 student,两个列族。info 列族数据维护的版本数为 5 个,如果不写默认版本数为 1。
    hbase:006:0> create 'bigdata:student',{NAME => 'info', VERSIONS => 5},{NAME => 'msg'}
    Created table bigdata:student
    Took 0.6619 seconds                                                                                         
    => Hbase::Table - bigdata:student
    
    • 1
    • 2
    • 3
    • 4

    如果创建表格只有一个列族,没有列族属性,可以简写。
    如果不写命令空间,使用默认的命名空间 default。

    hbase:009:0> create 'student1','info'
    
    • 1
    1. 查看表
      查看表有两个命令:list 和 describe
      list:查看所有的表名
    hbase:007:0> list
    TABLE                                                                                                       
    bigdata:student                                                                                             
    1 row(s)
    Took 0.0204 seconds                                                                                         
    => ["bigdata:student"]
    
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7

    describe:查看一个表的详情

    hbase:009:0> describe 'bigdata:student'
    Table bigdata:student is ENABLED                                                                            
    bigdata:student                                                                                             
    COLUMN FAMILIES DESCRIPTION                                                                                 
    {NAME => 'info', BLOOMFILTER => 'ROW', IN_MEMORY => 'false', VERSIONS => '5', KEEP_DELETED_CELLS => 'FALSE',
     DATA_BLOCK_ENCODING => 'NONE', COMPRESSION => 'NONE', TTL => 'FOREVER', MIN_VERSIONS => '0', BLOCKCACHE => 
    'true', BLOCKSIZE => '65536', REPLICATION_SCOPE => '0'}                                                     
    
    {NAME => 'msg', BLOOMFILTER => 'ROW', IN_MEMORY => 'false', VERSIONS => '1', KEEP_DELETED_CELLS => 'FALSE', 
    DATA_BLOCK_ENCODING => 'NONE', COMPRESSION => 'NONE', TTL => 'FOREVER', MIN_VERSIONS => '0', BLOCKCACHE => '
    true', BLOCKSIZE => '65536', REPLICATION_SCOPE => '0'}                                                      
    
    2 row(s)
    Quota is disabled
    Took 0.0627 seconds
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    1. 修改表
      表名创建时的所有和列族相关的信息,都可以后续通过 alter 修改,包括增加删除列族。
      (1)增加列族和修改信息都使用覆盖的方法
    hbase:011:0> alter 'bigdata:student', {NAME => 'f1', VERSIONS => 3}
    Updating all regions with the new schema...
    1/1 regions updated.
    Done.
    Took 1.6905 seconds
    
    • 1
    • 2
    • 3
    • 4
    • 5

    (2)删除信息使用特殊的语法

    hbase:012:0> alter 'bigdata:student', NAME => 'f1', METHOD => 'delete'
    Updating all regions with the new schema...
    1/1 regions updated.
    Done.
    Took 1.6771 seconds
    hbase:013:0> alter 'bigdata:student', 'delete' => 'f1'
    Updating all regions with the new schema...
    1/1 regions updated.
    Done.
    Took 1.6505 seconds
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    1. 删除表
      shell 中删除表格,需要先将表格状态设置为不可用。
    hbase:014:0> disable 'bigdata:student'
    Took 0.3361 seconds                                                                                         
    hbase:015:0> drop 'bigdata:student'
    Took 0.3525 seconds
    
    • 1
    • 2
    • 3
    • 4

    4. DML

    1. 写入数据
      在 HBase 中如果想要写入数据,只能添加结构中最底层的 cell,可以手动写入时间戳指定 cell 的版本,推荐不写默认使用当前的系统时间。
    hbase:021:0> put 'bigdata:student1','1001','info:name','zhangsan'
    Took 0.0295 seconds                                                                                         
    hbase:022:0> put 'bigdata:student1','1001','info:name','lisi'
    Took 0.0060 seconds                                                                                         
    hbase:023:0> put 'bigdata:student1','1001','info:age','18'
    Took 0.0051 seconds
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6

    如果重复写入相同 rowKey,相同列的数据,会写入多个版本进行覆盖。

    1. 读取数据
      读取数据的方法有两个:get 和 scan。
      get 最大范围是一行数据,可以进行列的过滤,读取数据的结果为多行 cell。
    hbase:025:0> get 'bigdata:student1','1001'
    COLUMN                       CELL                                                                           
     info:age                    timestamp=2022-10-24T16:35:09.847, value=18                                    
     info:name                   timestamp=2022-10-24T16:34:59.769, value=lisi                                  
    1 row(s)
    Took 0.0389 seconds
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6

    也可以修改读取 cell 的版本数,默认读取一个,最多能读取当前列族设置的维护版本数。

    hbase:026:0> get 'bigdata:student1','1001',{COLUMN => 'info:name',VERSIONS => 6}
    COLUMN                       CELL                                                                           
     info:name                   timestamp=2022-10-24T16:34:59.769, value=lisi                                  
     info:name                   timestamp=2022-10-24T16:34:49.077, value=zhangsan                              
    1 row(s)
    Took 0.0136 second
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6

    scan 是扫描数据,能读取多行数据,不建议扫描过多的数据,推荐使用 startRow 和 stopRow 来控制读取的数据,默认范围左闭右开。

    hbase:027:0> scan 'bigdata:student1',{STARTROW => '1001',STOPROW => '1002'}
    ROW                          COLUMN+CELL                                                                    
     1001                        column=info:age, timestamp=2022-10-24T16:35:09.847, value=18                   
     1001                        column=info:name, timestamp=2022-10-24T16:34:59.769, value=lisi                
    1 row(s)
    Took 0.0156 seconds
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    1. 删除数据
      删除数据的方法有两个:delete 和 deleteall。
      delete 表示删除一个版本的数据,即为 1 个 cell,不填写版本默认删除最新的一个版本。
    hbase:028:0> delete 'bigdata:student1','1001','info:name'
    Took 0.0081 seconds
    
    • 1
    • 2

    deleteall 表示删除所有版本的数据,即为当前行当前列的多个 cell。(执行命令会标记数据为要删除,不会直接将数据彻底删除,删除数据只在特定时期清理磁盘时进行)

    hbase:029:0> deleteall 'bigdata:student1','1001','info:name'
    Took 0.0052 seconds
    
    • 1
    • 2
  • 相关阅读:
    备战数学建模41-蒙特卡罗模拟(攻坚战5)
    链表、树和图专项练习
    微信小程序开发入门与实战(Behaviors使用)
    SpringBoot终幕——日志的输出以及Lombok常用注解
    基于PaddlePaddle的工业表计数环境搭建
    Node.js的入门及模块化
    数据结构与算法基础-学习-03-线性表之链式表-初始化、销毁、清理、获取长度、判断为空、获取元素等实现
    「引流工具」火炬多平台多功能引流高效推广脚本,抖音+快手+小红书多平台自动引流软件
    【开发心得】借助修改host测试回调
    基础DQL(数据查询)—— 子查询(含实例)
  • 原文地址:https://blog.csdn.net/qq_52354698/article/details/127492431