Apache Hbase安裝及執行
安裝hbase1.4,確保在這之前hadoop是正常執行的。設定相應的環境變數,
export HADOOP_HOME=/u01/hadoop
export HBASE_HOME=/u01/hbase
export PATH=$PATH:$HADOOP_HOME/bin:$HBASE_HOME/bin
啟動hbase
./start-hbase.sh
確保hadoop, hbase能正常啟動,如有問題,可自行搜尋文件解決。
[oracle@ol66 bin]$ jps
11685 NodeManager
11157 SecondaryNameNode
10844 NameNode
11405 ResourceManager
13135 HMaster
13455 Jps
10959 DataNode
確保hbase在hadoop上正常執行
[oracle@ol66 u01]$ hdfs dfs -ls /
Found 3 items
drwxr-xr-x - oracle supergroup 0 2018-02-28 00:52 /hbase
drwxr-xr-x - oracle supergroup 0 2018-02-27 23:14 /ogg
drwxr-xr-x - oracle supergroup 0 2018-02-28 00:33 /tmp
[oracle@ol66 bin]$ ./hbase shell
HBase Shell
Use "help" to get list of supported commands.
Use "exit" to quit this interactive shell.
Version 1.4.0, r10b9b9fae6b557157644fb9a0dc641bb8cb26e39, Fri Dec 8 16:09:13 PST 2017
hbase(main):001:0> list
TABLE
0 row(s) in 0.3800 seconds
=> []
hbase(main):002:0>
可以看到,系統中還沒有任何表。
OGG安裝及測試
配置OGG for bigdata的環境變數
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$JAVA_HOME/jre/lib/amd64/server
安裝ogg for bigdata 12.3版本軟體
進入ggsci
ggsci>create subdirs
退回到作業系統命令列,在OGG安裝目錄下執行如下命令,拷貝hbase示例投遞引數後進行修改
cp AdapterExamples/big-data/hbase/* dirprm/
在dirprm目錄下,編輯hbase.props檔案。
根據安裝的hbase的路徑,修改gg.classpath中 hbase lib的路徑;儲存退出。
hbase.props的完整內容如下:
gg.handlerlist=hbase gg.handler.hbase.type=hbase gg.handler.hbase.mode=tx goldengate.userexit.timestamp=utc gg.log=log4j gg.classpath=/u01/hbase/lib/*:/u01/hbase/conf/: javawriter.bootoptions=-Xmx512m -Xms32m -Djava.class.path=ggjava/ggjava.jar |
重新進入GGSCI,使用示例引數和示例佇列建立投遞程式。
GGSCI>add replicat rhbase, exttrail AdapterExamples/trail/tr
rhbase.prm的內容如下:
REPLICAT rhbase -- Trail file for this example is located in "AdapterExamples/trail" directory -- Command to add REPLICAT -- add replicat rhbase, exttrail AdapterExamples/trail/tr TARGETDB LIBFILE libggjava.so SET property=dirprm/hbase.props REPORTCOUNT EVERY 1 MINUTES, RATE GROUPTRANSOPS 10000 MAP QASOURCE.*, TARGET QASOURCE.*; |
測試
啟動投遞程式
GGSCI (ol66) 19> start rhbase
Sending START request to MANAGER ...
REPLICAT RHBASE starting
GGSCI (ol66) 20> info rhbase
REPLICAT RHBASE Initialized 2018-02-28 00:53 Status STARTING
Checkpoint Lag 00:00:00 (updated 00:02:16 ago)
Process ID 15424
Log Read Checkpoint File AdapterExamples/trail/tr000000000
First Record RBA 0
GGSCI (ol66) 22> info rhbase
REPLICAT RHBASE Last Started 2018-02-28 00:55 Status RUNNING
Checkpoint Lag 00:00:00 (updated 00:02:20 ago)
Process ID 15424
Log Read Checkpoint File /u01/ogg4bd/AdapterExamples/trail/tr000000000
First Record RBA 0
GGSCI (ol66) 27> info rhbase
REPLICAT RHBASE Last Started 2018-02-28 00:55 Status RUNNING
Checkpoint Lag 00:00:00 (updated 00:00:01 ago)
Process ID 15424
Log Read Checkpoint File /u01/ogg4bd/AdapterExamples/trail/tr000000000
2015-11-06 02:45:39.000000 RBA 5660
投遞完成,在OGG中檢查投遞結果
GGSCI (ol66) 28> stats rhbase, total
Sending STATS request to REPLICAT RHBASE ...
Start of Statistics at 2018-02-28 00:56:23.
Replicating from QASOURCE.TCUSTMER to QASOURCE.TCUSTMER:
*** Total statistics since 2018-02-28 00:55:43 ***
Total inserts 5.00
Total updates 1.00
Total deletes 0.00
Total discards 0.00
Total operations 6.00
Replicating from QASOURCE.TCUSTORD to QASOURCE.TCUSTORD:
*** Total statistics since 2018-02-28 00:55:43 ***
Total inserts 5.00
Total updates 3.00
Total deletes 2.00
Total discards 0.00
Total operations 10.00
End of Statistics.
在hbase上檢視,已經比剛開始多了2張表
hbase(main):002:0> list
TABLE
QASOURCE:TCUSTMER
QASOURCE:TCUSTORD
2 row(s) in 0.0190 seconds
=> ["QASOURCE:TCUSTMER", "QASOURCE:TCUSTORD"]
檢視資料
hbase(main):005:0> scan 'QASOURCE:TCUSTMER'
ROW COLUMN+CELL
ANN column=cf:CITY, timestamp=1519750550592, value=NEW YORK
ANN column=cf:CUST_CODE, timestamp=1519750550592, value=ANN
ANN column=cf:NAME, timestamp=1519750550592, value=ANN'S BOATS
ANN column=cf:STATE, timestamp=1519750550592, value=NY
BILL column=cf:CITY, timestamp=1519750550592, value=DENVER
BILL column=cf:CUST_CODE, timestamp=1519750550592, value=BILL
BILL column=cf:NAME, timestamp=1519750550592, value=BILL'S USED CARS
BILL column=cf:STATE, timestamp=1519750550592, value=CO
DAVE column=cf:CITY, timestamp=1519750550592, value=TALLAHASSEE
DAVE column=cf:CUST_CODE, timestamp=1519750550592, value=DAVE
DAVE column=cf:NAME, timestamp=1519750550592, value=DAVE'S PLANES INC.
DAVE column=cf:STATE, timestamp=1519750550592, value=FL
JANE column=cf:CITY, timestamp=1519750550421, value=DENVER
JANE column=cf:CUST_CODE, timestamp=1519750550421, value=JANE
JANE column=cf:NAME, timestamp=1519750550421, value=ROCKY FLYER INC.
JANE column=cf:STATE, timestamp=1519750550421, value=CO
WILL column=cf:CITY, timestamp=1519750550421, value=SEATTLE
WILL column=cf:CUST_CODE, timestamp=1519750550421, value=WILL
WILL column=cf:NAME, timestamp=1519750550421, value=BG SOFTWARE CO.
WILL column=cf:STATE, timestamp=1519750550421, value=WA
5 row(s) in 0.3150 seconds
hbase(main):001:0> scan 'QASOURCE:TCUSTORD'
ROW COLUMN+CELL
BILL|1995-12-31 15:00:00|CAR|765 column=cf:CUST_CODE, timestamp=1519750550614, value=BILL
BILL|1995-12-31 15:00:00|CAR|765 column=cf:ORDER_DATE, timestamp=1519750550614, value=1995-12-31 15:00:00
BILL|1995-12-31 15:00:00|CAR|765 column=cf:ORDER_ID, timestamp=1519750550614, value=765
BILL|1995-12-31 15:00:00|CAR|765 column=cf:PRODUCT_AMOUNT, timestamp=1519750550614, value=3
BILL|1995-12-31 15:00:00|CAR|765 column=cf:PRODUCT_CODE, timestamp=1519750550614, value=CAR
BILL|1995-12-31 15:00:00|CAR|765 column=cf:PRODUCT_PRICE, timestamp=1519750550614, value=14000.00
BILL|1995-12-31 15:00:00|CAR|765 column=cf:TRANSACTION_ID, timestamp=1519750550614, value=100
BILL|1996-01-01 00:00:00|TRUCK|333 column=cf:CUST_CODE, timestamp=1519750550614, value=BILL
BILL|1996-01-01 00:00:00|TRUCK|333 column=cf:ORDER_DATE, timestamp=1519750550614, value=1996-01-01 00:00:00
BILL|1996-01-01 00:00:00|TRUCK|333 column=cf:ORDER_ID, timestamp=1519750550614, value=333
BILL|1996-01-01 00:00:00|TRUCK|333 column=cf:PRODUCT_AMOUNT, timestamp=1519750550614, value=15
BILL|1996-01-01 00:00:00|TRUCK|333 column=cf:PRODUCT_CODE, timestamp=1519750550614, value=TRUCK
BILL|1996-01-01 00:00:00|TRUCK|333 column=cf:PRODUCT_PRICE, timestamp=1519750550614, value=25000.00
BILL|1996-01-01 00:00:00|TRUCK|333 column=cf:TRANSACTION_ID, timestamp=1519750550614, value=100
WILL|1994-09-30 15:33:00|CAR|144 column=cf:CUST_CODE, timestamp=1519750550614, value=WILL
WILL|1994-09-30 15:33:00|CAR|144 column=cf:ORDER_DATE, timestamp=1519750550614, value=1994-09-30 15:33:00
WILL|1994-09-30 15:33:00|CAR|144 column=cf:ORDER_ID, timestamp=1519750550614, value=144
WILL|1994-09-30 15:33:00|CAR|144 column=cf:PRODUCT_AMOUNT, timestamp=1519750550453, value=3
WILL|1994-09-30 15:33:00|CAR|144 column=cf:PRODUCT_CODE, timestamp=1519750550614, value=CAR
WILL|1994-09-30 15:33:00|CAR|144 column=cf:PRODUCT_PRICE, timestamp=1519750550614, value=16520.00
WILL|1994-09-30 15:33:00|CAR|144 column=cf:TRANSACTION_ID, timestamp=1519750550453, value=100
3 row(s) in 0.6770 seconds
可以看到,OGG配置投遞到Hbase非常簡單,可以根據DB中表的主鍵欄位建立key,如果沒有PK欄位,則投遞時會報錯。以下是當前OGG版本支援的Hbase版本