Wednesday, April 17, 2013

HBaseのセットアップ手順



1.環境
1)OS CentOS-6.2 64 Bit
2)Hadoop-1.0.4 インストール済み
3)Open JDK-1.7.0_09-icedtea 64 Bit インストール済み

2.スタンドアローン・モード(Standalone Mode)
2.1.HBase-0.94.5.tar.gz を ダウンロード
 http://ftp.yz.yamagata-u.ac.jp/pub/network/apache/hbase/stable/
2.2.HBase-0.94.5.tar.gz を解凍
2.3.JAVA_HOMEの指定
1)JAVA_HOMEの環境変数が既に定義されていれば、そのまま使える.
2)JAVA_HOMEの環境変数が未定義であれば、インストール済みのJavaを指定するJAVA_HOMEの環境変数を設定する.
3)上記以外、conf/hbase-env.sh を編集し、JAVA_HOMEを定義することも出来る.
  # The java implementation to use.  Java 1.6 required.
  export JAVA_HOME=/usr/lib/jvm/jre-1.7.0-openjdk.x86_64
2.4.HBaseのバイナリーディレクトリをcommand-line pathに追加すれば、便利.
  export HBASE_HOME=/home/hadoop/hbase-0.94.5
  export PATH=$PATH:$HBASE_HOME/bin
2.5.conf/hbase-site.xml hbase.rootdir HBaseがデータを書き込むディレクトリー) hbase.zookeeper.property.dataDirZooKeeperがデータを書き込むディレクトリー)を定義できる.スタンドアローンモードではこれらを定義しなくてもHBaseは正常に動作する.この場合、デフォルト値が使われる:/tmp/hbase-${user.name} , ${hbase.tmp.dir}/zookeeper
2.6.HBaseの起動
  $ start-hbase.sh
2.7.HBase Shell を起動
 $ hbase shell
 HBase Shell; enter 'help<RETURN>' for list of supported commands.
 Type "exit<RETURN>" to leave the HBase Shell
 Version 0.94.5, r1443843, Fri Feb  8 05:51:25 UTC 2013

 hbase(main):001:0> create 'testTable', 'colFam1'
 0 row(s) in 2.0330 seconds

 hbase(main):002:0> list
 TABLE                                                                                                                                                                                                          
 testTable                                                                                                                                                                                                     
 1 row(s) in 0.0320 seconds

 hbase(main):003:0> put 'testTable', 'row1', 'colFam1:col1', 'value1'
 0 row(s) in 0.1090 seconds

 hbase(main):004:0> put 'testTable', 'row2', 'colFam1:col2', 'value2'
 0 row(s) in 0.0080 seconds

 hbase(main):005:0> put 'testTable', 'row3', 'colFam1:col3', 'value3'
 0 row(s) in 0.0080 seconds

 hbase(main):006:0> scan 'testTable'
 ROW                                                  COLUMN+CELL                                                                                                                                               
 row1                                                column=colFam1:col1, timestamp=1361870571841, value=value1                                                                                               
 row2                                                column=colFam1:col2, timestamp=1361870618755, value=value2                                                                                               
 row3                                                column=colFam1:col3, timestamp=1361870639961, value=value3                                                                                               
 3 row(s) in 0.0500 seconds

 hbase(main):007:0> disable 'testTable'
 0 row(s) in 2.0920 seconds

 hbase(main):008:0> drop 'testTable'
 0 row(s) in 1.1430 seconds

 hbase(main):009:0> exit

2.8.HBaseのシャットダウン
 $stop-hbase.sh

3.完全分散型(Fully Distributed Mode)
スタンドアローンモードを完全分散型にアップグレードするための設定手順は以下の通りである.
3.1.conf/hbase-site.xmlの設定
        <configuration>
        <property>
                <name>hbase.rootdir</name>
                <value>hdfs://master:54310/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.quorum</name>
                <value>
                cssec164.nda.ac.jp,cssec149.nda.ac.jp,cssec154.nda.ac.jp
                </value>
                <description>
                        Comma separated list of servers in the ZooKeeper Quorum. By default this is set to localhost for local and pseudo-distributed modes of operation. For a fully-distributed setup, this should be set to a full list of ZooKeeper quorum servers. If HBASE_MANAGES_ZK is set in hbase-env.sh, this is the list of servers which we will start/stop Zookeeper on.
                </description>
        </property>
        <property>
                <name>hbase.zookeeper.property.dataDir</name>
                <value>/home/hadoop/zookeeper</value>
                <description>
                        Property from ZooKeeper's config zoo.cfg. The directory where the snapshot is stored.
                </description>
        </property>
        <property>
                <name>hbase.master.info.bindAddress</name>
                <value>10.35.2.85</value>
                <description>
                        The bind address for the HBase Master web UI
                </description>
        </property>
</configuration>

3.2.conf/regionservers の設定
 リージョンサーバとなるマシーンのIPアドレスかホスト名を記述する.
Hadoopのデータノードと同じマシーンをリージョンサーバとして使用しているため、そのホスト名を記述した.
        conf/regionserversの内容は
        slave1
        slave2
        となっている.
3.3.ZooKeeperの設定
HBaseは予め設立されたZooKeeperクラスタに依存する.デフォルトとしては、HBaseは自分でZooKeeperクラスタを管理する.この場合、ZooKeeperクラスタはHBaseのスタートやシャットダウンのプロセスに入っており、毎回HBaseをスタートやシャットダウンすると同時に、ZooKeeperも自動的にスタートやシャットダウンされる.
3.4.HDFSクライアントの設定
HBaseHDFSの設定ファイルをHBaseの設定ディレクトリ(hbase-0.94.5/conf)から参照出来るように、それを明確に指定する必要がある.その一つの方法としては${HBASE_HOME}/conf${HADOOP_HOME}/conf/hdfs-site.xmlへのsymlinksを設定した.

  $ ln -s /home/hadoop/hadoop-1.0.4/conf/hdfs-site.xml ./hdfs-site.xml

3.5.HBaseに使用されるポート番号(デフォルト)
        ① 2181                :ZooKeeper client port.
        ② 2888                :ZooKeeper peers port.
        ③ 3888                :ZooKeeper leader election port.
        ④ 60000       :HBase Master port.
        ⑤ 60010       :HBase Master web UI port.
        ⑥ 60020       :HBase RegionServer port.
        ⑦ 60030       :HBase RegionServer web UI port.
        ⑧ 8080                :HBase REST server port.
 3.6.HBaseを起動し、動作を確認する.
        $ start-hbase.sh

  HMasterのステータスを確認する.
  http://10.35.2.85:60010/master-status
               

  HMasterweb UIではRegionServersのステータスも確認出来る.
       
        [hduser@cssec164 nfs]$ stop-hbase.sh
        stopping hbase...........
        cssec154.nda.ac.jp: stopping zookeeper.
        cssec149.nda.ac.jp: stopping zookeeper.
        cssec164.nda.ac.jp: stopping zookeeper.
       
  HBaseのシャットダウンは数秒間かかる.
以上でHBaseのスタンドアローンモードと完全分散型モードのセットアップ手順である.


Trouble shooting:
1.HADOOPHBASEを強制的にシャットダウンすると、次回に起動する時にHADOOPsafe mode 状態に入る.その結果としては、MAPREDUCEHBASEは正常に起動出来なくなってしまう、その時にHBASESTOPすると、STOPのプロセスは永久に終わらない.つまり、HBASESTOP出来なくなってしまう.
解決:HADOOP SAFE MODE 状態をNORMAL 状態に変更(以下のcommand line を実行):
        hadoop dfsadmin -safemode leave