HBase是Apache Hadoop中的一個子項目,是一個HBase是一個開源的、分佈式的、多版本的、面向列的、非關係(NoSQL)的、可伸縮性分佈式數據存儲模型,Hbase依託於Hadoop的HDFS做爲最基本存儲基礎單元。HBase的服務器體系結構聽從簡單的主從服務器架構,它由HRegion Server羣和HMaster Server構成。HMaster Server負責管理全部的HRegion Server,而HBase中的全部Server都是經過Zookeeper進行的分佈式信息共享與任務協調的工做。HMaster Server自己並不存儲HBase中的任何數據,HBase邏輯上的表可能會被劃分紅多個Region,而後存儲到HRegionServer羣中,HRegionServer響應用戶I/O請求,向HDFS文件系統中讀寫數據。HBase Master Server中存儲的是從數據到HRegion Server的映射。html
下面一幅圖是Hbase在Hadoop Ecosystem中的位置java
上圖描述了Hadoop EcoSystem中的各層系統,其中HBase位於結構化存儲層,Hadoop HDFS爲HBase提供了高可靠性的底層存儲支持,Hadoop MapReduce爲HBase提供了高性能的計算能力,Zookeeper爲HBase提供了穩定服務和failover機制。 此外,Pig和Hive還爲HBase提供了高層語言支持,使得在HBase上進行數據統計處理變的很是簡單。 Sqoop則爲HBase提供了方便的RDBMS數據導入功能,使得傳統數據庫數據向HBase中遷移變的很是方便。node
cd /usr/local tar -zxvf hbase-1.2.1-bin.tar.gz mv /home/hbase
配置工做具體以下:web
export JAVA_HOME=/usr/local/jdk1.8 export HBASE_PID_DIR=/home/hbase/pid #使用mkdir /home/hbase/pid命令先建立 export HBASE_MANAGES_ZK=false #不適用內置zookeeper,使用咱們本身安裝的(具體指定使用哪一個zookeeper是經過/etc/profile中的ZK_HOME變量來指定的)
<configuration> <property> <name>hbase.rootdir</name> <value>hdfs://master:9000/hbase</value> <description>設置 hbase 數據庫存放數據的目錄,這裏是放在hadoop hdfs上,這裏要與hadoop的core-site.xml文件中的fs.default.name中的值一致,而後在後面添加本身的子目錄,我這裏定義是hbase</description> </property> <property> <name>hbase.cluster.distributed</name> <value>true</value> <description>打開 hbase 分佈模式</description> </property> <property> <name>hbase.master</name> <value>master</value> <description>指定 hbase 集羣主控節點</description> </property> <property> <name>hbase.tmp.dir</name> <value>/home/user/tmp/hbase</value> <description>hbase的一些臨時文件存放目錄。</description> </property> <property> <name>hbase.zookeeper.quorum</name> <value>master,slave1,slave2</value> <description> 指定 zookeeper 集羣節點名 , 由於是由 zookeeper 表決算法決定的</description> </property> <property> <name>hbase.zookeeper.property.clientPort</name> <value>2181</value> <description> 鏈接到zookeeper的端口,默認是2181</description> </property> </configuration>
msater
slave1
slave2
scp /home/hbase root@slave1:/home/ scp /home/hbase root@slave2:/home/
完成後使用vi /etc/profile 設置各自節點的環境變量算法
啓動hbase前要確保,hadoop,zookeeper已經啓動,進入$HBASE_HOME/bin目錄下,輸入命令start-hbase.shshell
執行jps查看系統進程數據庫
其餘節點apache
啓動日誌會輸出到/home/hbase/logs/hbase-root-master-master.log中,能夠查看排除異常服務器
啓動完成後,執行以下命令能夠進入到hbase shell界面,使用命令status檢查集羣節點狀態
這裏可使用 hbase shell命令執行數據庫操做,具體參考 http://www.cnblogs.com/nexiyi/p/hbase_shell.html 數據結構
另外也能夠直接打開網址:http://192.168.137.122:16010/master-status,在web中查看集羣狀態,其中192.168.137.122是master所在節點的IP,16010爲hbase默認端口(老版本中爲60010)
本次安裝測試中主要出現了一下幾個錯誤:
org.apache.hadoop.hbase.ClockOutOfSyncException: org.apache.hadoop.hbase.ClockOutOfSyncException: Server hadoopslave2,60020,1372320861420 has been rejected; Reported time is too far out of sync with master. Time difference of 143732ms > max allowed of 30000ms at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57) at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) at java.lang.reflect.Constructor.newInstance(Constructor.java:525) at org.apache.hadoop.ipc.RemoteException.instantiateException(RemoteException.java:95) at org.apache.hadoop.ipc.RemoteException.unwrapRemoteException(RemoteException.java:79) at org.apache.hadoop.hbase.regionserver.HRegionServer.reportForDuty(HRegionServer.java:2093) at org.apache.hadoop.hbase.regionserver.HRegionServer.run(HRegionServer.java:744) at java.lang.Thread.run(Thread.java:722) Caused by: org.apache.hadoop.ipc.RemoteException: org.apache.hadoop.hbase.ClockOutOfSyncException: Server hadoopslave2,60020,1372320861420 has been rejected; Reported time is too far out of sync with master. Time difference of 143732ms > max allowed of 30000ms
在各節點的hbase-site.xml文件中加入下列代碼
<property> <name>hbase.master.maxclockskew</name> <value>200000</value> </property>
org.apache.hadoop.ipc.RemoteException(org.apache.hadoop.fs.PathIsNotEmptyDirectoryException): `/hbase/WALs/slave1,16000,1446046595488-splitting is non empty': Directory is not empty at org.apache.hadoop.hdfs.server.namenode.FSNamesystem.deleteInternal(FSNamesystem.java:3524) at org.apache.hadoop.hdfs.server.namenode.FSNamesystem.deleteInt(FSNamesystem.java:3479) at org.apache.hadoop.hdfs.server.namenode.FSNamesystem.delete(FSNamesystem.java:3463) at org.apache.hadoop.hdfs.server.namenode.NameNodeRpcServer.delete(NameNodeRpcServer.java:751) at org.apache.hadoop.hdfs.protocolPB.ClientNamenodeProtocolServerSideTranslatorPB.delete(ClientNamenodeProtocolServerSideTranslatorPB.java:562) at org.apache.hadoop.hdfs.protocol.proto.ClientNamenodeProtocolProtos$ClientNamenodeProtocol$2.callBlockingMethod(ClientNamenodeProtocolProtos.java) at org.apache.hadoop.ipc.ProtobufRpcEngine$Server$ProtoBufRpcInvoker.call(ProtobufRpcEngine.java:585) at org.apache.hadoop.ipc.RPC$Server.call(RPC.java:928) at org.apache.hadoop.ipc.Server$Handler$1.run(Server.java:2013) at org.apache.hadoop.ipc.Server$Handler$1.run(Server.java:2009) at java.security.AccessController.doPrivileged(Native Method) at javax.security.auth.Subject.doAs(Subject.java:415) at org.apache.hadoop.security.UserGroupInformation.doAs(UserGroupInformation.java:1614) at org.apache.hadoop.ipc.Server$Handler.run(Server.java:2007) at org.apache.hadoop.ipc.Client.call(Client.java:1411) at org.apache.hadoop.ipc.Client.call(Client.java:1364) at org.apache.hadoop.ipc.ProtobufRpcEngine$Invoker.invoke(ProtobufRpcEngine.java:206) at com.sun.proxy.$Proxy15.delete(Unknown Source) at org.apache.hadoop.hdfs.protocolPB.ClientNamenodeProtocolTranslatorPB.delete(ClientNamenodeProtocolTranslatorPB.java:490) at sun.reflect.GeneratedMethodAccessor7.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:606) at org.apache.hadoop.io.retry.RetryInvocationHandler.invokeMethod(RetryInvocationHandler.java:187) at org.apache.hadoop.io.retry.RetryInvocationHandler.invoke(RetryInvocationHandler.java:102) at com.sun.proxy.$Proxy16.delete(Unknown Source) at sun.reflect.GeneratedMethodAccessor7.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:606) at org.apache.hadoop.hbase.fs.HFileSystem$1.invoke(HFileSystem.java:279) at com.sun.proxy.$Proxy17.delete(Unknown Source) at sun.reflect.GeneratedMethodAccessor7.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:606) at org.apache.hadoop.hbase.fs.HFileSystem$1.invoke(HFileSystem.java:279) at com.sun.proxy.$Proxy17.delete(Unknown Source) at org.apache.hadoop.hdfs.DFSClient.delete(DFSClient.java:1726) at org.apache.hadoop.hdfs.DistributedFileSystem$11.doCall(DistributedFileSystem.java:588) at org.apache.hadoop.hdfs.DistributedFileSystem$11.doCall(DistributedFileSystem.java:584) at org.apache.hadoop.fs.FileSystemLinkResolver.resolve(FileSystemLinkResolver.java:81) at org.apache.hadoop.hdfs.DistributedFileSystem.delete(DistributedFileSystem.java:584) at org.apache.hadoop.hbase.master.SplitLogManager.splitLogDistributed(SplitLogManager.java:297) at org.apache.hadoop.hbase.master.MasterFileSystem.splitLog(MasterFileSystem.java:400) at org.apache.hadoop.hbase.master.MasterFileSystem.splitLog(MasterFileSystem.java:373) at org.apache.hadoop.hbase.master.MasterFileSystem.splitLog(MasterFileSystem.java:295) at org.apache.hadoop.hbase.master.procedure.ServerCrashProcedure.splitLogs(ServerCrashProcedure.java:388) at org.apache.hadoop.hbase.master.procedure.ServerCrashProcedure.executeFromState(ServerCrashProcedure.java:228) at org.apache.hadoop.hbase.master.procedure.ServerCrashProcedure.executeFromState(ServerCrashProcedure.java:72) at org.apache.hadoop.hbase.procedure2.StateMachineProcedure.execute(StateMachineProcedure.java:119) at org.apache.hadoop.hbase.procedure2.Procedure.doExecute(Procedure.java:452) at org.apache.hadoop.hbase.procedure2.ProcedureExecutor.execProcedure(ProcedureExecutor.java:1050) at org.apache.hadoop.hbase.procedure2.ProcedureExecutor.execLoop(ProcedureExecutor.java:841) at org.apache.hadoop.hbase.procedure2.ProcedureExecutor.execLoop(ProcedureExecutor.java:794) at org.apache.hadoop.hbase.procedure2.ProcedureExecutor.access$400(ProcedureExecutor.java:75) at org.apache.hadoop.hbase.procedure2.ProcedureExecutor$2.run(ProcedureExecutor.java:479)
參考https://issues.apache.org/jira/browse/HBASE-14729,進入hadoop文件系統,刪除掉報錯的目錄或真個WALs
zookeeper.MetaTableLocator: Failed verification of hbase:meta,,1 at address=slave1,16020,1428456823337, exception=org.apache.hadoop.hbase.NotServingRegionException: Region hbase:meta,,1 is not online on worker05,16020,1428461295266 at org.apache.hadoop.hbase.regionserver.HRegionServer.getRegionByEncodedName(HRegionServer.Java:2740) at org.apache.hadoop.hbase.regionserver.RSRpcServices.getRegion(RSRpcServices.java:859) at org.apache.hadoop.hbase.regionserver.RSRpcServices.getRegionInfo(RSRpcServices.java:1137) at org.apache.hadoop.hbase.protobuf.generated.AdminProtos$AdminService$2.callBlockingMethod(AdminProtos.java:20862) at org.apache.hadoop.hbase.ipc.RpcServer.call(RpcServer.java:2031) at org.apache.hadoop.hbase.ipc.CallRunner.run(CallRunner.java:107) at org.apache.hadoop.hbase.ipc.RpcExecutor.consumerLoop(RpcExecutor.java:130) at org.apache.hadoop.hbase.ipc.RpcExecutor$1.run(RpcExecutor.java:107) at java.lang.Thread.run(Thread.java:745)
HMaster啓動以後自動掛掉(或非正常重啓),而且master的log裏出現「TableExistsException: hbase:namespace」字樣;
極可能是更換了Hbase的版本事後zookeeper還保留着上一次的Hbase設置,因此形成了衝突.
刪除zookeeper信息,重啓以後就沒問題了
# sh zkCli.sh -server slave1:2181 [zk: slave1:2181(CONNECTED) 0] ls / [zk: slave1:2181(CONNECTED) 0] rmr /hbase [zk: slave1:2181(CONNECTED) 0] quit