HBase-0.90.4集羣安裝配置

HBase是Hadoop數據庫,能夠實現隨機、實時讀寫你的Big Data,它是Google的Bigtable的開源實現,可以參考Bigtable的論文Bigtable: A Distributed Storage System for Structured。HBase的存儲模型可以如下三個詞來概括:distributed, versioned, column-oriented。HBase並非只能在HDFS文件系統上使用, 你可以應用在你的本地文件系統上部署HBase實例來存儲數據。


準備工作


下面介紹Standalone和Distributed安裝過程。


Standalone模式


這種安裝模式,是在你的本地文件系統上安裝配置一個HBase實例,安裝配置比較簡單。

首先,要保證你的本地系統能夠通過ssh無密碼訪問,配置如下:

ssh-keygen -t dsa
cat ~/.ssh/id_dsa.pub >> ~/.ssh/authorized_keys
檢查一下權限:你的~/.ssh目錄的權限是否爲755,~/.ssh/authorized_keys的權限是否爲644,如果不是,執行下面的命令行:
chmod 755 ~/.ssh
chmod 644 ~/.ssh/authorized_keys
然後,安裝配置HBase,過程如下:
cd /home/shirdrn/hadoop
tar -xvzf hbase-0.90.4.tar.gz
cd hbase-0.90.4
修改conf/hbase-env.sh中JAVA_HOME配置,指定爲你的JAVA_HOME目錄:
export JAVA_HOME=/usr/java/jdk1.6.0_16
其他配置,如HBASE*指定配置項,如果需要可以進行配置。

修改hbase-site.xml中配置,示例如下:

<?xml version="1.0"?>
<?xml-stylesheet type="text/xsl" href="configuration.xsl"?>

<configuration>
  <property>
    <name>hbase.rootdir</name>
    <value>file:///home/shirdrn/hadoop/hbase-0.90.4/data</value>
  </property>
</configuration>
指定HBase的數據存儲目錄,使用的是本地文件系統的目錄。

接着,就可以啓動HBase實例,提供本地存儲服務:

bin/start-hbase.sh
啓動完成以後,你可以跟蹤一下HBase日誌,看看是否啓動成功了:

tail -500f logs/hbase-shirdrn-master-localhost.log
或者查看一下HMaster進程是否存在:

ps -ef | grep HMaster

通過日誌可以看出,HBase實例啓動了所有的HBase和Zookeeper守護進程,並且這些進程都是在同一個JVM中。下面,可以啓動HBase shell,來簡單測試HBase的數據存儲的基本命令:

cd bin
hbase shell
hbase(main):001:0> help
hbase(main):002:0> status
hbase(main):003:0> version
// 創建表'pagedb',列簇(Column Family)爲metadata、text、status
hbase(main):004:0> create 'pagedb', 'metadata', 'text', 'status'
// 插入數據
hbase(main):005:0> put 'pagedb', 'http://www.mafengwo.cn/i/764197.html', 'metadata:site', 'www.mafengwo.cn'
hbase(main):006:0> put 'pagedb', 'http://www.mafengwo.cn/i/764197.html', 'metadata:pubdate', '2011-12-20 22:09'
hbase(main):007:0> put 'pagedb', 'http://www.mafengwo.cn/i/764197.html', 'text:title', '南國之境'
hbase(main):008:0> put 'pagedb', 'http://www.mafengwo.cn/i/764197.html', 'text:content', '如果海會說話, 如果風愛上砂 我會聆聽浪花,...'
hbase(main):009:0> put 'pagedb', 'http://www.mafengwo.cn/i/764197.html', 'status:extracted', '0'
hbase(main):010:0> put 'pagedb', 'http://www.mafengwo.cn/i/764197.html', 'status:httpcode', '200'
hbase(main):011:0> put 'pagedb', 'http://www.mafengwo.cn/i/764197.html', 'status:indexed', '1'
// 掃描表'pagedb'
hbase(main):012:0> scan 'pagedb'
// 獲取記錄'http://www.mafengwo.cn/i/764197.html'的所有列的數據
hbase(main):013:0> get 'pagedb', 'http://www.mafengwo.cn/i/764197.html'
// 獲取記錄'http://www.mafengwo.cn/i/764197.html'的metadata列簇數據
hbase(main):014:0> get 'pagedb', 'http://www.mafengwo.cn/i/764197.html', 'metadata'
// 獲取記錄'http://www.mafengwo.cn/i/764197.html'的列metadata:site數據
hbase(main):015:0> get 'pagedb', 'http://www.mafengwo.cn/i/764197.html', 'metadata:site'
// 增加一個列status:state,並指定值爲4
hbase(main):016:0> incr 'pagedb', 'http://www.mafengwo.cn/i/764197.html', 'status:state', 4
// 修改status:httpcode的值爲500
hbase(main):017:0> put 'pagedb', 'http://www.mafengwo.cn/i/764197.html', 'status:httpcode', '500'
// 統計表'pagedb'中的記錄行數
hbase(main):018:0> count 'pagedb'
// disable表'pagedb'
hbase(main):019:0> disable 'pagedb'
// enable表pagedb
hbase(main):020:0> enable 'pagedb'
// 清空表'pagedb'
hbase(main):021:0> truncate 'pagedb'
// 列出所有表
hbase(main):022:0> list
// 刪除'http://www.mafengwo.cn/i/764197.html'數據行
hbase(main):023:0> deleteall 'pagedb','http://www.mafengwo.cn/i/764197.html'
// 刪除表'pagedb',刪除之前必須先disable表
hbase(main):024:0> drop 'pagedb'

如果想練習使用其他更多命令,可以通過help查看其他命令。


Distributed模式


基於分佈式模式安裝HBase,首先它是在安裝在HDFS集羣之上,所以,首先要做的就是能夠正確配置分佈式模式的HDFS集羣:保證Nanemode和Datanode進程都正確啓動。HBase是一個分佈式NoSQL數據庫,建立於HDFS之上,並且對於集羣模式的HBase需要對各個結點之間的數據進行協調(Coordination),所以HBase直接將ZooKeeper作爲一個分佈式協調系統來實現HBase數據複製(Replication)存儲。有關ZooKeeper的介紹可以參考官方文檔:http://zookeeper.apache.org

HBase的基於主從架構模式:HBase集羣中存在一個Hbase Master Server,類似於HDFS中的Namenode的角色;而作爲從結點的Region Server,類似於HDFS中的Datanode。

對於HBase分佈式模式的安裝,又基於Zookeeper的是否被HBase管理,分爲兩種模式:

  • 基於HBase管理的Zookeeper集羣,啓動和關閉HBase集羣,同時也控制Zookeeper集羣
  • 外部Zookeeper集羣:一個完全獨立於HBase的ZooKeeper集羣,不受HBase管理控制(啓動與停止ZooKeeper集羣)

下面,我們基於一個單獨安裝的ZooKeeper集羣,不基於HBase管理,進行安裝。根據官網文檔,很容易就能安裝配置好,並嘗試使用。
1、安裝配置HDFS集羣
啓動HDFS集羣實例,一臺master作爲Namenode結點,其餘3臺slaves作爲Datanode結點。
其中,master服務端口爲9000。
2、創建HBase存儲目錄
#創建目錄hdfs://master:9000/hbase
hadoop fs -mkdir /hbase
#驗證/hbase目錄創建成功
hadoop fs -lsr /
3、配置HBase
(1)解壓縮HBase軟件包,修改系統環境變量,在~/.bashrc中最後面加入如下配置:
export JAVA_HOME=/home/hadoop/installation/jdk1.6.0_30
export HADOOP_HOME=/home/hadoop/installation/hadoop-0.22.0
export HBASE_HEAPSIZE=128
export HBASE_MANAGES_ZK=false
使配置生效:
. ~/.bashrc
(2)修改hbase-0.90.4/conf/hbase-env.sh腳本內容:
首先要重命名hbase-0.90.4目錄下的一個目錄:
hadoop@master:~/installation/hbase-0.90.4$ mv hbase-webapps/ webapps
默認會查找webapps目錄。然後修改腳本,內容如下:
export JAVA_HOME=/home/hadoop/installation/jdk1.6.0_30
export HADOOP_HOME=/home/hadoop/installation/hadoop-0.22.0
export HBASE_HEAPSIZE=128
export HBASE_MANAGES_ZK=false
export HBASE_CLASSPATH=$HBASE_HOME/
最後一個表示使用外部Zookeeper集羣,而不讓HBase集羣去管理。
(3)修改conf/hbase-site.xml文件內容,如下所示:
<?xml version="1.0"?>
<?xml-stylesheet type="text/xsl" href="configuration.xsl"?>

<configuration>
        <property>
                <name>hbase.rootdir</name>
                <value>hdfs://master:9000/hbase</value>
                <description>The directory shared by RegionServers.</description>
        </property>
        <property>
                <name>hbase.cluster.distributed</name>
                <value>true</value>
                <description>The mode the cluster will be in. Possible values are false: standalone and pseudo-distributed setups with managed Zookeeper true: fully-distributed with unmanaged Zookeeper Quorum (see hbase-env.sh)</description>
        </property>
        <property>
                <name>hbase.zookeeper.property.dataDir</name>
                <value>/home/hadoop/storage/zookeeper</value>
                <description>Property from ZooKeeper's config zoo.cfg. The directory where the snapshot is stored.</description>
        </property>
        <property>
                <name>hbase.zookeeper.quorum</name>
                <value>slave-01,slave-02,slave-03</value>
                <description>The directory shared by RegionServers.</description>
        </property>
</configuration>
上面配置中:
  • hbase.rootdir 指定了HBase存儲的根目錄是在HDFS的hdfs://master:9000/hbase目錄下,該目錄要被HBase集羣中Region Server共享。不要忘記了,在啓動HBase集羣之前,在HDFS集羣中創建/hbase目錄,在master上執行命令hadoop fs -mkdir /hbase即可。
  • hbase.cluster.distributed 指定了我們使用完全分佈的模式進行安裝
  • hbase.zookeeper.property.dataDir 指定了HBase集羣使用的ZooKeeper集羣的存儲目錄
  • hbase.zookeeper.quorum指定了用於協調HBase集羣的ZooKeeper集羣結點,必須配置奇數個結點,否則HBase集羣啓動會失敗
所以,在啓動HBase集羣之前,首先要保證ZooKeeper集羣已經成功啓動。
(4)接下來,檢查HBase的lib中的Hadoop的版本是否之前我們啓動的HDFS集羣使用的版本一致:
rm ~/installation/hbase-0.90.4/lib/hadoop-core-0.20-append-r1056497.jar
cp ~/installation/hadoop-0.22.0/*.jar ~/installation/hbase-0.90.4/lib/
我直接將HBase解壓縮包中的hadoop的jar文件刪除,用當前使用版本的Hadoop的jar文件。這一步很重要,如果不細看官方文檔,你可能會感覺很怪異,實際HBase軟件包中lib下的Hadoop的版本默認是0.20的,如果你啓動的HDFS使用的是0.22,則HBase啓動會報版本不一致的錯誤。
(5)修改conf/regionservers文件,配置HBase集羣中的從結點Region Server,如下所示:
slave-01
slave-02
slave-03
一行一個主機字符串,上面使用是從結點主機的域名。上面配置,與HDFS的從結點的配置非常類似。
(6)經過上面幾個驟,基本已經在一臺機器上(master)配置好HBase了,這時,需要將上述的全部環境變量配置,也在各個從結點上進行配置,然後將配置好的HBase安裝文件拷貝分發到各個從結點上:
scp -r ~/installation/hbase-0.90.4 hadoop@slave-01:/home/hadoop/installation
scp -r ~/installation/hbase-0.90.4 hadoop@slave-02:/home/hadoop/installation
scp -r ~/installation/hbase-0.90.4 hadoop@slave-03:/home/hadoop/installation
4、配置Zookeeper集羣
具體安裝、配置和啓動,詳見文章 http://blog.csdn.net/shirdrn/article/details/7183503 的說明。
在開始啓動HBase集羣之前,要先啓動Zookeeper集羣,保證其運行正常。

5、啓動HBase集羣

啓動HBase集羣了,執行如下腳本:
start-hbase.sh
你可以使用jps查看一下,當前master上啓動的全部進程,如下所示:
hadoop@master:~/installation/hbase-0.90.4$ jps
15899 SecondaryNameNode
15553 NameNode
21677 Jps
21537 HMaster
其中,HMaster進程就是HBase集羣的主結點服務進程。
slaves結點上啓動的進程,以slave-03爲例:
hadoop@slave-03:~/installation/hbase-0.90.4$ jps
6919 HRegionServer
4212 QuorumPeerMain
7053 Jps
3483 DataNode
上面,HReginServer是HBase集羣的從結點服務進程,QuorumPeerMain是ZooKeeper集羣的結點服務進程。
或者,查看日誌,是否出現啓動異常:
master上  :  tail -500f $HBASE_HOME/logs/hbase-hadoop-master-master.log
slave-01上:  tail -500f $HBASE_HOME/logs/hbase-hadoop-zookeeper-slave-01.log
slave-02上:  tail -500f $HBASE_HOME/logs/hbase-hadoop-zookeeper-slave-02.log
slave-03上:  tail -500f $HBASE_HOME/logs/hbase-hadoop-zookeeper-slave-03.log
6、驗證HBase安裝
啓動HBase shell,如果能夠顯示如下信息則說明HBase集羣啓動成功:
hadoop@master:~/installation/hbase-0.90.4$ hbase shell
12/01/09 01:14:09 WARN conf.Configuration: hadoop.native.lib is deprecated. Instead, use io.native.lib.available
12/01/09 01:14:09 WARN conf.Configuration: hadoop.native.lib is deprecated. Instead, use io.native.lib.available
12/01/09 01:14:09 WARN conf.Configuration: hadoop.native.lib is deprecated. Instead, use io.native.lib.available
HBase Shell; enter 'help<RETURN>' for list of supported commands.
Type "exit<RETURN>" to leave the HBase Shell
Version 0.90.4, r1150278, Sun Jul 24 15:53:29 PDT 2011


hbase(main):001:0> help
HBase Shell, version 0.90.4, r1150278, Sun Jul 24 15:53:29 PDT 2011
Type 'help "COMMAND"', (e.g. 'help "get"' -- the quotes are necessary) for help on a specific command.
Commands are grouped. Type 'help "COMMAND_GROUP"', (e.g. 'help "general"') for help on a command group.


COMMAND GROUPS:
  Group name: general
  Commands: status, version


  Group name: ddl
  Commands: alter, create, describe, disable, drop, enable, exists, is_disabled, is_enabled, list


  Group name: dml
  Commands: count, delete, deleteall, get, get_counter, incr, put, scan, truncate


  Group name: tools
  Commands: assign, balance_switch, balancer, close_region, compact, flush, major_compact, move, split, unassign, zk_dump


  Group name: replication
  Commands: add_peer, disable_peer, enable_peer, remove_peer, start_replication, stop_replication


SHELL USAGE:
Quote all names in HBase Shell such as table and column names.  Commas delimit
command parameters.  Type <RETURN> after entering a command to run it.
Dictionaries of configuration used in the creation and alteration of tables are
Ruby Hashes. They look like this:


  {'key1' => 'value1', 'key2' => 'value2', ...}


and are opened and closed with curley-braces.  Key/values are delimited by the
'=>' character combination.  Usually keys are predefined constants such as
NAME, VERSIONS, COMPRESSION, etc.  Constants do not need to be quoted.  Type
'Object.constants' to see a (messy) list of all constants in the environment.


If you are using binary keys or values and need to enter them in the shell, use
double-quote'd hexadecimal representation. For example:


  hbase> get 't1', "key\x03\x3f\xcd"
  hbase> get 't1', "key\003\023\011"
  hbase> put 't1', "test\xef\xff", 'f1:', "\x01\x33\x40"


The HBase shell is the (J)Ruby IRB with the above HBase-specific commands added.
For more on the HBase Shell, see http://hbase.apache.org/docs/current/book.html
hbase(main):002:0> status
3 servers, 0 dead, 0.0000 average load


hbase(main):003:0> version
0.90.4, r1150278, Sun Jul 24 15:53:29 PDT 2011


hbase(main):004:0> 
你可以按照前面使用本地文件系統安裝過程中,使用的命令來進行相關的操作。

總結說明

1、出現版本不一致錯誤

如果啓動時出現版本不一致的錯誤,如下所示:

2012-01-06 21:27:18,384 FATAL org.apache.hadoop.hbase.master.HMaster: Unhandled exception. Starting shutdown.
org.apache.hadoop.ipc.RemoteException: Server IPC version 5 cannot communicate with client version 3
        at org.apache.hadoop.ipc.Client.call(Client.java:740)
        at org.apache.hadoop.ipc.RPC$Invoker.invoke(RPC.java:220)
        at $Proxy5.getProtocolVersion(Unknown Source)
        at org.apache.hadoop.ipc.RPC.getProxy(RPC.java:359)
        at org.apache.hadoop.hdfs.DFSClient.createRPCNamenode(DFSClient.java:113)
        at org.apache.hadoop.hdfs.DFSClient.<init>(DFSClient.java:215)
        at org.apache.hadoop.hdfs.DFSClient.<init>(DFSClient.java:177)
        at org.apache.hadoop.hdfs.DistributedFileSystem.initialize(DistributedFileSystem.java:82)
        at org.apache.hadoop.fs.FileSystem.createFileSystem(FileSystem.java:1378)
        at org.apache.hadoop.fs.FileSystem.access$200(FileSystem.java:66)
        at org.apache.hadoop.fs.FileSystem$Cache.get(FileSystem.java:1390)
        at org.apache.hadoop.fs.FileSystem.get(FileSystem.java:196)
        at org.apache.hadoop.fs.Path.getFileSystem(Path.java:175)
        at org.apache.hadoop.hbase.util.FSUtils.getRootDir(FSUtils.java:364)
        at org.apache.hadoop.hbase.master.MasterFileSystem.<init>(MasterFileSystem.java:81)
        at org.apache.hadoop.hbase.master.HMaster.finishInitialization(HMaster.java:346)
        at org.apache.hadoop.hbase.master.HMaster.run(HMaster.java:282)
2012-01-02 21:27:18,384 INFO org.apache.hadoop.hbase.master.HMaster: Aborting
這就是說明Hadoop和HBase版本不匹配,仔細閱讀文檔,你會在http://hbase.apache.org/book.html#hadoop發現,解釋如下所示:
Because HBase depends on Hadoop, it bundles an instance of the Hadoop jar under its lib directory. The bundled jar is ONLY 

for use in standalone mode. In 
distributed mode, it is critical that the version of Hadoop that is out on your cluster match what is under HBase. Replace the hadoop jar found in the HBase lib 
directory with the hadoop jar you are running on your cluster to avoid version mismatch issues. Make sure you replace the jar in HBase everywhere on your cluster. 
Hadoop version mismatch issues have various manifestations but often all looks like its hung up.

將HBase解壓縮包中lib的Hadoop Core jar文件替換爲當前你所使用的Hadoop版本即可。

2、HBase集羣啓動以後,執行相關操作時拋出異常

如果HBase集羣正常啓動,但是在想要創建一個table的時候,出現如下異常,如下所示:

ERROR: org.apache.hadoop.hbase.NotAllMetaRegionsOnlineException: org.apache.hadoop.hbase.NotAllMetaRegionsOnlineException: Timed out (10000ms)
        at org.apache.hadoop.hbase.catalog.CatalogTracker.waitForMeta(CatalogTracker.java:334)
        at org.apache.hadoop.hbase.master.HMaster.createTable(HMaster.java:769)
        at org.apache.hadoop.hbase.master.HMaster.createTable(HMaster.java:743)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:597)
        at org.apache.hadoop.hbase.ipc.HBaseRPC$Server.call(HBaseRPC.java:570)
        at org.apache.hadoop.hbase.ipc.HBaseServer$Handler.run(HBaseServer.java:1039)

解決方法就是,修改/etc/hosts文件,修改內容以master爲例,如下所示:

#127.0.0.1       localhost
192.168.0.180   master
192.168.0.191   slave-01
192.168.0.190   slave-02
192.168.0.189   slave-03
# The following lines are desirable for IPv6 capable hosts
#::1     ip6-localhost ip6-loopback
#fe00::0 ip6-localnet
#ff00::0 ip6-mcastprefix
#ff02::1 ip6-allnodes
#ff02::2 ip6-allrouters

然後,再進行相關操作就沒有問題了。

參考如下鏈接:http://comments.gmane.org/gmane.comp.java.hadoop.hbase.user/18868


參考鏈接




發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章