• [HBase Manual] CH2 Getting Started


    Getting Started

    Getting Started. 1

    1. Introduction. 1

    2.Quick Start-Strandalone HBase. 1

    2.1 JDK版本选择... 1

    2.2 Get Started With HBase. 1

    2.3 伪分布式本地安装... 1

    2.4 高级——完全分布式... 1

     

    1. Introduction

    QuickStart会介绍如何安装和运行一个单节点,standalone Hbase实例

    2.Quick Start-Strandalone HBase

    这节介绍了single-node standalone HBase的安装。Standalone实例有所有的HBase守护运行在一个JVM。也会演示如何使用hbase shell来创建表,插入数据,执行putscan操作,enabledisable表,关闭和启动HBase

    2.1 JDK版本选择

    HBase需要JDK,可以查看需要的JDK版本: Java

    2.2 Get Started With HBase

    过程:下载,配置和以standalone mode启动HBase

    1.选择一个Mirror并且下载

    2.解压下载文件,然后cd到目录。

    3.设置JAVA_HOME环境变量。可以用传统的方式设置,也可以使用conf/hbase-env.sh集中管理。编辑这个文件,去掉JAVA_HOME的注释,并且设置正确的路径。JAVA_HOME变量要被设置到包含执行文件bin/java的目录。很多最新的Linux操作系统提供一个机制比如/usr/bin/alternatives,用来切换java版本的执行文件。在这个例子中,你可以设置JAVA_HOME到包含link的目录,比如/usr
                    JAVA_HOME=/usr

    4.编辑conf/hbase-site.xmlhbase的配置文件。这个时候需要指定一些本地路径。用来HBase的数据写入和Zookeeper数据写入。默认新的目录创建在/tmp下。很多服务器会在重启后会把/tmp的目录清空。所以需要把数据放在其他地方。下面的配置HBase的数据目录被配置在testuserhome目录下面。

    Standalone Hbase配置例子:

    <configuration>

      <property>

        <name>hbase.rootdir</name>

        <value>file:///home/testuser/hbase</value>

      </property>

      <property>

        <name>hbase.zookeeper.property.dataDir</name>

        <value>/home/testuser/zookeeper</value>

      </property>

      <property>

        <name>hbase.unsafe.stream.capability.enforce</name>

        <value>false</value>

        <description>

          Controls whether HBase will check for stream capabilities (hflush/hsync).

     

          Disable this if you intend to run on LocalFileSystem, denoted by a rootdir

          with the 'file://' scheme, but be mindful of the NOTE below.

     

          WARNING: Setting this to false blinds you to potential data loss and

          inconsistent system state in the event of process and/or node failures. If

          HBase is complaining of an inability to use hsync or hflush it's most

          likely not a false positive.

        </description>

      </property>

    </configuration>

     

    不需要创建HBase的目录,HBase会自己创建。如果创建了目录HBase会进行合并。

    如果已经存在的HDFS已经有了HBasehome,设置hbase.rootdir指向hdfs实例,比如:hdfs://namenode.example.org:8020/hbase

    1.bin/start-hbase.sh脚本是快速启动hbase的方法。如果启动正常成功启动的信息就会被输出。可以使用jps查看HMaster是否启动。在standalone Hbase守护进程都运行在一个jvm上。即 HMaster,一个HregionServerZookeeper守护进程。可以到http://localhost:16010查看HBase Web UI

    过程:第一次使用HBase

    1.连接到Hbase

    使用bhase shell连接到hbase实例。

    $ ./bin/hbase shell
    hbase(main):001:0>

     

    2.输出hbase shell帮助

    在命令行上输入help回车,会显示hbase shell的帮助。

    3.创建表

    使用 create命令创建新表

    hbase(main):001:0> create 'test', 'cf'
    0 row(s) in 0.4170 seconds
     
    => Hbase::Table - test

     

    4.输出表的信息

    使用list命令确认已经存在的表

    hbase(main):002:0> list 'test'
    TABLE
    test
    1 row(s) in 0.0180 seconds
     
    => ["test"]

     

    使用describe查看表的详细信息

    hbase(main):003:0> describe 'test'
    Table test is ENABLED
    test
    COLUMN FAMILIES DESCRIPTION
    {NAME => 'cf', VERSIONS => '1', EVICT_BLOCKS_ON_CLOSE => 'false', NEW_VERSION_BEHAVIOR => 'false', KEEP_DELETED_CELLS => 'FALSE', CACHE_DATA_ON_WRITE =>
    'false', DATA_BLOCK_ENCODING => 'NONE', TTL => 'FOREVER', MIN_VERSIONS => '0', REPLICATION_SCOPE => '0', BLOOMFILTER => 'ROW', CACHE_INDEX_ON_WRITE => 'f
    alse', IN_MEMORY => 'false', CACHE_BLOOMS_ON_WRITE => 'false', PREFETCH_BLOCKS_ON_OPEN => 'false', COMPRESSION => 'NONE', BLOCKCACHE => 'true', BLOCKSIZE
     => '65536'}
    1 row(s)
    Took 0.9998 seconds

     

    5.put数据到表

    使用put命令插入数据。

    hbase(main):003:0> put 'test', 'row1', 'cf:a', 'value1'
    0 row(s) in 0.0850 seconds
     
    hbase(main):004:0> put 'test', 'row2', 'cf:b', 'value2'
    0 row(s) in 0.0110 seconds
     
    hbase(main):005:0> put 'test', 'row3', 'cf:c', 'value3'
    0 row(s) in 0.0100 seconds

     

    这里插入了3个值,在row1中插入,列cf:a,值value1Hbase中的列由列簇比如 cf,冒号,后缀组成。

    6.扫描表的所有数据

    获取hbase表的数据的方法就是scan。使用scan命令扫描表中的数据。可以过滤。

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

     

    7.获取一个行的数据

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

     

    8.disable

    如果想要删除表或者修改表的设置,在其他情况下需要先disable表,使用disable命令。如果要重新enable使用enable命令。

    hbase(main):008:0> disable 'test'
    0 row(s) in 1.1820 seconds
     
    hbase(main):009:0> enable 'test'
    0 row(s) in 0.1770 seconds

     

    9.删除表

    使用drop来删除表

    hbase(main):011:0> drop 'test'
    0 row(s) in 0.1370 seconds

     

    10.退出hbase shell

    使用quit命令退出hbase shellhbase的服务任然是运行的。

    过程:关闭Hbase

    1.bin/start-hbase.sh一样,使用bin/start-hbase.sh来关闭

    $ ./bin/stop-hbase.sh
    stopping hbase....................
    $

     

    2.执行命令后,过几分钟就会被关闭,可以使用jps查看,保证HMasterHregionServer进程被关闭。

    2.3 伪分布式本地安装

    已经安装了standalone版本之后,可以重现配置成伪分布式,伪分布式还是在一个host下运行,但是hbase的守护进程是独立的进程而不是在一个jvm下。默认的rootdir还是在/tmp下。也可以跳过直接存在本地文件系统下。

    1.关闭已经在运行的hbase

    2.配置hbase
    编辑hbase-site.xml配置,首选设置hbase.cluster.distributed=true

    <property>
      <name>hbase.cluster.distributed</name>
      <value>true</value>
    </property>

    然后修改hbase.rootdir从本地文件系统指向HDFS,使用hdfs:////比如hdfs的端口是8020.

    <property>
      <name>hbase.rootdir</name>
      <value>hdfs://localhost:8020/hbase</value>
    </property>

    不需要在hdfs创建好目录,hbase会创建。如果已经创建了目录,那么就会合并。

    3.启动hbase
    使用bin/start-hbase.sh命令启动hbase。如果系统配置的正确那么jos命令会输出HMasterHRegionServer的进程。

    4.检查hbasehdfs上的目录
    如果运行没有问题,hbase会在hdfs创建目录。按上面的配置会保存在/hbase下。可以使用hadoop fs命令查看。

    $ ./bin/hadoop fs -ls /hbase
    Found 7 items
    drwxr-xr-x   - hbase users          0 2014-06-25 18:58 /hbase/.tmp
    drwxr-xr-x   - hbase users          0 2014-06-25 21:49 /hbase/WALs
    drwxr-xr-x   - hbase users          0 2014-06-25 18:48 /hbase/corrupt
    drwxr-xr-x   - hbase users          0 2014-06-25 18:58 /hbase/data
    -rw-r--r--   3 hbase users         42 2014-06-25 18:41 /hbase/hbase.id
    -rw-r--r--   3 hbase users          7 2014-06-25 18:41 /hbase/hbase.version
    drwxr-xr-x   - hbase users          0 2014-06-25 21:49 /hbase/oldWALs

     

    5.创建一个表并且导入数据
    可以使用hbase shell创建一个表,并且导入数据,然后从表里面读取数据, shell exercises

    6.启动和关闭HBase的备份。
    HMaster服务控制了hbase的集群。可以启动9HMaster备份服务,会有一个10HMaster,包括primary。使用local-master-backup.sh来备份HMaster。对于每个备份的master,想要启动,需要分配端口。每个HMaster2个端口(默认是1600016010)Offset2,所以备份要使用1600216012.如果启动3个服务那么会使用16002/16012,16003/1601316005/16015

    $ ./bin/local-master-backup.sh start 2 3 5

    为了kill backup master然不kill整个集群,就需要找到它的PID,然后用kill -9命令去killPID保存在/tmp/hbase-USER-X-master.pid。以下命令是kill offset1的。

    $ cat /tmp/hbase-testuser-1-master.pid |xargs kill -9

     

    7.启动和关闭额外的RegionServers
    HRegionServer管理存储文件中的数据。存储文件由HMaster管理。通常每个node运行一个HRegionServer。一个系统上运行多个HRegionServer用来测试伪分布式模式。Local-regionservers.sh命令用来运行多个Regionservers。和local-master-backup.sh运行方式类似。每个参数提供了一个端口偏移值。每个RegionServer需要2个端口默认是16020,16030。因为HBase 1.1.0 之前HMaster不使用region server使用端口,保留了10个端口1602016029,1603016039用来给RegionServers使用。在运行local-regionservers.sh之前需要设置环境变量HBASE_RS_BASE_PORT HBASE_RS_INFO_BASE_PORT,比如1620016300,那么就可以支持99个额外的RegionServers。以下命令是启动4个额外的RegionServer,从16022/16032开始启动(base port上增加2)

    $ .bin/local-regionservers.sh start 2 3 4 5

    位了手动关闭RegionServer,使用local-regionserver.sh来关闭。

    $ .bin/local-regionservers.sh stop 3

     

    8.关闭HBase
    使用bin/stop-hbase.sh来关闭hbase

    2.4 高级——完全分布式

    实际情况下,需要一个完全的分布式配置在实际的场景下,来测试hbase。在分布式配置中,cluster包含很多个节点,每个节点可能运行hbase的一个或多个守护。包括主的和备份的Master实例,多个Zookeeper节点和多个RegionServer节点。

    Node Name

    Master

    ZooKeeper

    RegionServer

    node-a.example.com

    yes

    yes

    no

    node-b.example.com

    backup

    yes

    yes

    node-c.example.com

    no

    yes

    yes

     

    过程:配置无密码SSH访问

    过程:准备node-a

    node-a上会运行primary masterZookeeper进程,没有RegionServer。根据之前的关闭node-a上的RegionServer

    1.编辑conf/regionserver,删除localhost。增加node-bnode-cip地址或者主机名

    如果还是想要在node-a上运行RegionServer,也使用node-a的主机名。

    2.配置hbase使用node-b作为backup master

    创建一个文件在conf下叫backup-masters,并且增加node-bhostname

    3.配置Zookeeper

    在真是环境下Zookeeper配置很多。Zookeeper配置可以看 zookeeper 这个配置可以让hbase在每个集群的node上,启动和管理Zookeeper实例。

    node-a编辑conf/hbase-site.xml增加以下配置:

    <property>
      <name>hbase.zookeeper.quorum</name>
      <value>node-a.example.com,node-b.example.com,node-c.example.com</value>
    </property>
    <property>
      <name>hbase.zookeeper.property.dataDir</name>
      <value>/usr/local/zookeeper</value>
    </property>

     

    4.在所有的配置中,使用node-a的主机名来替换localhost

    过程:准备node-b,node-c

    Node-b会运行一个backup masterZookeeper实例

    1.下载并解压hbase

    2.node-a的配置文件复制到node-b,node-c

    每个集群中的node都有一样的配置信息。

    过程:启动和测试集群

    1.保证hbase没有在任何节点上运行。

    如果忘记停止hbase,那么就会报错。使用jps检查是否还在运行主要看HMasterHregionServerHQuorumPeer进程。如果存在就先kill

    2.启动集群

    node-a上,运行start-hbase.sh命令。Zookeeper会先启动然后是master,然后是RegionServer最后是backup master

    3.验证

    在每个node 上运行jps,查看进程是否运行。

    Node-a上输出

    $ jps
    20355 Jps
    20071 HQuorumPeer
    20137 HMaster

     

    Node-b

    $ jps
    15930 HRegionServer
    16194 Jps
    15838 HQuorumPeer
    16010 HMaster

     

    Node-c

    $ jps
    13901 Jps
    13639 HQuorumPeer
    13737 HRegionServer

     

    Zookeeper进程名

    HQourumPeerZookeeper的实例有HBase控制。如果使用这种方式的Zookeeper每个集群node都会有一个节点。如果Zookeeperhbase之外的。可以使用QuorumPeer。更多的Zookeeper可以看zookeeper 

    4.使用Web UI访问

    hbase 0.98之后,http端口从master端口60010RegionServer 60030修改到了1601016030

    如果启动正常,就可以通过Web访问Master

    5.测试服务消失会发生什么

    当上面3节点的集群配置完毕,还要看如果primary master或者RegionServerkill之后会发生什么。

  • 相关阅读:
    (第十二周)Bug修正报告
    (第十二周)团队项目19
    (第十二周)新功能WBS
    (第十二周)团队项目18
    (第十二周)团队项目17
    (第十二周)Debug阶段成员贡献分
    (第十一周)工作总结
    学习进度
    第九周
    第八周
  • 原文地址:https://www.cnblogs.com/Amaranthus/p/8882979.html
Copyright © 2020-2023  润新知