本文講述如何安裝,部署,啓停HBase集羣,如何經過命令行對Hbase進行基本操做。html
並介紹Hbase的配置文件。node
在安裝前須要將全部先決條件安裝完成。shell
和Hadoop同樣,Hbase須要JDK1.6或者更高的版本,因此請安裝好JDK並配置環境變量。apache
Hbase版本與JDK版本安全
HBase Version | JDK 7 | JDK 8 | JDK 9 (Non-LTS) | JDK 10 (Non-LTS) | JDK 11 |
---|---|---|---|---|---|
2.0+ | HBASE-20264 | HBASE-20264 | HBASE-21110 | ||
1.2+ | HBASE-20264 | HBASE-20264 | HBASE-21110 |
zookeeper是Hbase集羣的協調器,負責解決HMaster的單點問題,因此必須先安裝好一個zookeeper。服務器
集羣模式下,咱們須要Hadoop環境架構
Hadoop 版本支持框架
HBase-1.2.x, HBase-1.3.x | HBase-1.4.x | HBase-2.0.x | HBase-2.1.x | |
---|---|---|---|---|
Hadoop-2.4.x | T | F | F | F |
Hadoop-2.5.x | T | F | F | F |
Hadoop-2.6.0 | F | F | F | F |
Hadoop-2.6.1+ | T | F | T | F |
Hadoop-2.7.0 | F | F | F | F |
Hadoop-2.7.1+ | T | T | T | T |
Hadoop-2.8.[0-1] | F | F | F | F |
Hadoop-2.8.2 | N | N | N | N |
Hadoop-2.8.3+ | N | N | T | T |
Hadoop-2.9.0 | F | F | F | F |
Hadoop-2.9.1+ | N | N | N | N |
Hadoop-3.0.[0-2] | F | F | F | F |
Hadoop-3.0.3+ | F | F | T | T |
Hadoop-3.1.0 | F | F | F | F |
Hadoop-3.1.1+ | F | F | T | T |
Hbase有兩種運行模式,單機模式和分佈式模式。ssh
首先在這裏下載Hbase的一個穩定版本,https://www.apache.org/dyn/closer.lua/hbase/分佈式
建議點擊頂部連接,進入 HBase Releases 點擊 stable 的文件夾,而後下載將以 tar.gz 結尾的二進制文件到本地。暫時不要下載以 src.tar.gz 結尾的文件。
進入到那個要解壓的目錄
$ tar xzvf hbase-1.3.5-bin.tar.gz $ cd hbase-1.3.5/
在啓動 HBase 以前,您須要設置JAVA_HOME
環境變量。您能夠經過操做系統的經常使用設置來設置變量,HBase 也提供了一箇中心機制 conf/hbase-env.sh。編輯此文件,取消註釋以JAVA_HOME
開頭的行,並將其設置爲適合您的操做系統的路徑。
JAVA_HOME=/usr
編輯 HBase 主配置文件 conf/hbase-site.xml.
您須要在本地文件系統上指定 HBase 和 ZooKeeper 數據存儲目錄.
<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>
bin/start-hbase.sh 爲啓動 HBase
bin/start-hbase.sh爲中止 HBase
可使用 jps
確認 HMaster 和 HRegionServer 進程是否開啓關閉。
僞分佈模式意味着 HBase 仍然在單個主機上徹底運行,可是每一個 HBase 守護進程(HMaster,HRegionServer 和 ZooKeeper)做爲一個單獨的進程運行.
使用集羣模式前,要保證HDFS能夠正常運行。
編輯 HBase 主配置文件 conf/hbase-site.xml.
須要將分佈式模式開啓 指定hdfs的URI
<property> <name>hbase.cluster.distributed</name> <value>true</value> </property> <property> <name>hbase.rootdir</name> <value>hdfs://localhost:8020/hbase</value> </property>
使用 bin/start-hbase.sh 啓動 HBase. 若是您的系統配置正確,該jps
命令應顯示 HMaster 和 HRegionServer 進程正在運行。
啓動和中止備份 HBase 主(HMaster)服務器
你能夠啓動最多 9 個備份 HMaster 服務器,這個服務器總共有 10 個 HMaster 計算主服務器。
$ ./bin/local-master-backup.sh start 2 3 5
啓動和中止其餘 RegionServers
$ .bin/local-regionservers.sh start 2 3 4 5
實際上,您須要一個徹底分佈式的配置來全面測試 HBase,並將其用於實際場景中。在分佈式配置中,集羣包含多個節點,每一個節點運行一個或多個 HBase 守護進程。這些包括主要和備份主實例,多個 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免密和防火牆權限,並將zookeeper配置好啓動。
將Hbase下載並解壓,將配置文件同步到各個機器上。
$ bin/start-hbase.sh node-c.example.com: starting zookeeper, logging to /home/hbuser/hbase-0.98.3-hadoop2/bin/../logs/hbase-hbuser-zookeeper-node-c.example.com.out node-a.example.com: starting zookeeper, logging to /home/hbuser/hbase-0.98.3-hadoop2/bin/../logs/hbase-hbuser-zookeeper-node-a.example.com.out node-b.example.com: starting zookeeper, logging to /home/hbuser/hbase-0.98.3-hadoop2/bin/../logs/hbase-hbuser-zookeeper-node-b.example.com.out starting master, logging to /home/hbuser/hbase-0.98.3-hadoop2/bin/../logs/hbase-hbuser-master-node-a.example.com.out node-c.example.com: starting regionserver, logging to /home/hbuser/hbase-0.98.3-hadoop2/bin/../logs/hbase-hbuser-regionserver-node-c.example.com.out node-b.example.com: starting regionserver, logging to /home/hbuser/hbase-0.98.3-hadoop2/bin/../logs/hbase-hbuser-regionserver-node-b.example.com.out node-b.example.com: starting master, logging to /home/hbuser/hbase-0.98.3-hadoop2/bin/../logs/hbase-hbuser-master-nodeb.example.com.out
在 HBase 0.98.x 以上, HBase Web UI 的端口從主節點的 60010 和 RegionServer 的 60030 變化爲 16010 和 16030
在Hbase啓動之後能夠經過頁面查看。
在 HBase 安裝目錄 bin/ 目錄下使用hbase shell
命令鏈接正在運行的 HBase 實例。
$ ./bin/hbase shell hbase(main):001:0>
輸入help
並回車, 能夠看到 HBase Shell 的基本信息和一些示例命令.
使用 create
建立一個表 必須指定一個表名和列族名
hbase(main):001:0> create 'test', 'cf' 0 row(s) in 0.4170 seconds => Hbase::Table - test
使用 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
使用 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
從 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
使用 get
命令一次獲取一條數據
hbase(main):007:0> get 'test', 'row1' COLUMN CELL cf:a timestamp=1421762485768, value=value1 1 row(s) in 0.0350 seconds
使用 disable
命令禁用表
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
使用 enable
命令啓用表
hbase(main):010:0> disable 'test' 0 row(s) in 1.1820 seconds
hbase(main):011:0> drop 'test' 0 row(s) in 0.1370 seconds
使用quit
命令退出命令行並從集羣斷開鏈接。
Apache HBase 使用與 Apache Hadoop 相同的配置系統。全部配置文件都位於 conf/ 目錄中,須要保持羣集中每一個節點的同步。
backup-masters 默認狀況下不存在。這是一個純文本文件,其中列出了主服務器應在其上啓動備份主進程的主機,每行一臺主機。 hadoop-metrics2-hbase.properties 用於鏈接 HBase Hadoop 的 Metrics2 框架。默認狀況下只包含註釋出的示例。 hbase-env.cmd and hbase-env.sh 用於 Windows 和 Linux/Unix 環境的腳本,以設置 HBase 的工做環境,包括 Java、Java 選項和其餘環境變量的位置。該文件包含許多註釋示例來提供指導。 hbase-policy.xml RPC 服務器使用默認策略配置文件對客戶端請求進行受權決策。僅在啓用 HBase安全模式下使用。 hbase-site.xml 主要的 HBase 配置文件。該文件指定覆蓋 HBase 的默認配置的配置選項。您能夠在 docs/hbase-default.xml 中查看(但不要編輯)默認配置文件。您還能夠在 HBase Web UI 的 HBase 配置選項卡中查看羣集的整個有效配置(默認和覆蓋)。 log4j.properties 經過log4j進行 HBase 日誌記錄的配置文件。 regionservers 包含應該在 HBase 集羣中運行 RegionServer 的主機列表的純文本文件。默認狀況下,這個文件包含單個條目localhostt。它應該包含主機名或 IP 地址列表,每行一個,若是集羣中的每一個節點將在其localhost接口上運行 RegionServer 的話,則只應包含localhost
更多實時計算,Hbase,Flink,Kafka等相關技術博文,歡迎關注實時流式計算
原文出處:https://www.cnblogs.com/tree1123/p/11606588.html