1.4-1.5 HBase部署及基本使用
一、部署
1、準(zhǔn)備
##先用Apache hadoop ##之前的cdh 服務(wù)器先全部停掉##解壓HBASE [root@hadoop-senior hbase]# tar zxf hbase-0.98.6-hadoop2-bin.tar.gz -C /opt/modules/##啟動(dòng)Apache hadoop (hdfs) [root@hadoop-senior hadoop-2.5.0]# pwd /opt/modules/hadoop-2.5.0[root@hadoop-senior hadoop-2.5.0]# sbin/hadoop-daemon.sh start namenode [root@hadoop-senior hadoop-2.5.0]# sbin/hadoop-daemon.sh start datanode[root@hadoop-senior hadoop-2.5.0]# jps 23159 Jps 23081 DataNode 22996 NameNode2、配置、啟動(dòng)
hbase-env.sh
export JAVA_HOME=/opt/modules/jdk1.7.0_80regionservers
改為主機(jī)名hbase-site.xml
<property><name>hbase.rootdir</name><value>hdfs://hadoop-senior.ibeifeng.com:8020/hbase</value></property><property><name>hbase.cluster.distributed</name><value>true</value></property><property><name>hbase.zookeeper.quorum</name><value>hadoop-senior.ibeifeng.com</value></property>啟動(dòng)
##替換jar包,事先準(zhǔn)備好的,(cdh應(yīng)該就不需要替換了)[root@hadoop-senior hbase-0.98.6-hadoop2]# mv lib/hadoop-* /tmp/[root@hadoop-senior hadoop-2.5.0-jars]# cp -r ./* /opt/modules/hbase-0.98.6-hadoop2/lib/[root@hadoop-senior hbase-0.98.6-hadoop2]# mv lib/zookeeper-3.4.6.jar /tmp/
##啟動(dòng)[root@hadoop-senior hbase-0.98.6-hadoop2]# bin/start-hbase.sh [root@hadoop-senior hbase-0.98.6-hadoop2]# jps 24548 Jps 24155 HMaster 23081 DataNode 24084 HQuorumPeer 24266 HRegionServer 22996 NameNode端口:60010 //可以web訪問(wèn):ip:port
3、hdfs上HBASE各個(gè)目錄
[root@hadoop-senior hadoop-2.5.0]# bin/hdfs dfs -ls / Found 3 items drwxr-xr-x - root supergroup 0 2019-05-20 14:45 /hbase drwx-w---- - root supergroup 0 2019-04-18 17:33 /tmp drwxr-xr-x - root supergroup 0 2019-04-18 17:21 /user[root@hadoop-senior hadoop-2.5.0]# bin/hdfs dfs -ls /hbase Found 6 items drwxr-xr-x - root supergroup 0 2019-05-20 14:45 /hbase/.tmp drwxr-xr-x - root supergroup 0 2019-05-20 14:45 /hbase/WALs drwxr-xr-x - root supergroup 0 2019-05-20 14:31 /hbase/data -rw-r--r-- 3 root supergroup 42 2019-05-20 14:31 /hbase/hbase.id -rw-r--r-- 3 root supergroup 7 2019-05-20 14:31 /hbase/hbase.version drwxr-xr-x - root supergroup 0 2019-05-20 14:46 /hbase/oldWALs## /hbase/.tmp當(dāng)對(duì)表做創(chuàng)建或者刪除操作的時(shí)候,會(huì)將表move 到該 tmp 目錄下,然后再去做處理操作。/hbase/WALsHBase 是支持 WAL(Write Ahead Log) 的,HBase 會(huì)在第一次啟動(dòng)之初會(huì)給每一臺(tái) RegionServer 在WALs下創(chuàng)建一個(gè)目錄,若客戶端如果開啟WAL 模式, 會(huì)先將數(shù)據(jù)寫入一份到WALs下,當(dāng) RegionServer crash 或者目錄達(dá)到一定大小,會(huì)開啟 replay 模式,類似 MySQL 的 binlog。/hbase/data存儲(chǔ)hbase數(shù)據(jù),下面含有兩個(gè)命名空間default和hbase,/hbase/data/default這個(gè)默認(rèn)的namespace即沒有指定namespace 的表都將會(huì)flush 到該目錄下面。/hbase/data/hbase這個(gè)namespace 下面存儲(chǔ)了 HBase 的 namespace、meta 和acl 三個(gè)表,這里的 meta 表跟0.94版本的.META.是一樣的,自0.96之后就已經(jīng)將 ROOT 表去掉了,直接從Zookeeper 中找到meta 表的位置,然后通過(guò) meta 表定位到 region。 namespace 中存儲(chǔ)了 HBase 中的所有 namespace 信息,包括預(yù)置的hbase 和 default。acl 則是表的用戶權(quán)限控制。 如果自定義一些 namespace 的話,就會(huì)再/hbase/data 目錄下新建一個(gè) namespace 文件夾,該 namespace 下的表都將 flush 到該目錄下。/hbase/hbase.id它是一個(gè)文件,存儲(chǔ)集群唯一的 cluster id 號(hào),是一個(gè) uuid。/hbase/hbase.version同樣也是一個(gè)文件,存儲(chǔ)集群的版本號(hào),貌似是加密的,看不到,只能通過(guò)web-ui 才能正確顯示出來(lái)。/hbase/oldWALs當(dāng)WALs文件夾中的 HLog 沒用之后會(huì) move 到.oldWALs 中,HMaster 會(huì)定期去清理。二、HBase Shell基本使用
1、登入命令行
[root@hadoop-senior hbase-0.98.6-hadoop2]# bin/hbase Usage: hbase [<options>] <command> [<args>] Options:--config DIR Configuration direction to use. Default: ./conf--hosts HOSTS Override the list in 'regionservers' fileCommands: Some commands take arguments. Pass no args or -h for usage.shell Run the HBase shellhbck Run the hbase 'fsck' toolhlog Write-ahead-log analyzerhfile Store file analyzerzkcli Run the ZooKeeper shellupgrade Upgrade hbasemaster Run an HBase HMaster noderegionserver Run an HBase HRegionServer nodezookeeper Run a Zookeeper serverrest Run an HBase REST serverthrift Run the HBase Thrift serverthrift2 Run the HBase Thrift2 serverclean Run the HBase clean up scriptclasspath Dump hbase CLASSPATHmapredcp Dump CLASSPATH entries required by mapreducepe Run PerformanceEvaluationltt Run LoadTestToolversion Print the versionCLASSNAME Run the class named CLASSNAME[root@hadoop-senior hbase-0.98.6-hadoop2]# bin/hbase shell //進(jìn)入HBASE命令行 hbase(main):001:0> help //查看幫助2、操作命令
hbase(main):007:0> help 'create' //查看建表幫助 hbase(main):004:0> create 'user', 'info' //創(chuàng)建一個(gè)表,user:表名; info:列簇 hbase(main):005:0> list //列出表 hbase(main):006:0> describe 'user' //查看表結(jié)構(gòu)##插入數(shù)據(jù) hbase(main):008:0> put 'user', '10001', 'info:name', 'zhangsan' //user:表名; 10001:rowkey; info:name:列簇的其中一列; zhangsan:值 0 row(s) in 0.0770 seconds hbase(main):010:0> put 'user', '10001', 'info:age', '25' 0 row(s) in 0.0060 secondshbase(main):011:0> put 'user', '10001', 'info:sex', 'male' 0 row(s) in 0.0040 secondshbase(main):012:0> put 'user', '10001', 'info:address', 'shanghai'##查詢 HBase的數(shù)據(jù)查詢有三種方式: *依據(jù)rowkey查詢,最快的get*范圍查詢scan range*全表掃描scan##查詢10001這個(gè)rowkey下的所有列數(shù)據(jù) hbase(main):014:0> get 'user', '10001' COLUMN CELL info:address timestamp=1558342595476, value=shanghai info:age timestamp=1558342530687, value=25 info:name timestamp=1558342470065, value=zhangsan info:sex timestamp=1558342551186, value=male 4 row(s) in 0.0160 seconds##單獨(dú)列查詢hbase(main):015:0> get 'user', '10001', 'info:name' COLUMN CELL info:name timestamp=1558342470065, value=zhangsan 1 row(s) in 0.0080 seconds3、操作命令
##插入數(shù)據(jù),rowkey:10002 hbase(main):016:0> put 'user', '10002', 'info:name', 'wangwu' 0 row(s) in 0.0040 secondshbase(main):017:0> put 'user', '10002', 'info:age', '30' 0 row(s) in 0.0040 secondshbase(main):018:0> put 'user', '10002', 'info:tel', '231294737' 0 row(s) in 0.0030 secondshbase(main):019:0> put 'user', '10002', 'info:qq', '231294737' 0 row(s) in 0.0030 seconds##全表掃描查詢 hbase(main):020:0> scan 'user' ROW COLUMN+CELL 10001 column=info:address, timestamp=1558342595476, value=shanghai 10001 column=info:age, timestamp=1558342530687, value=25 10001 column=info:name, timestamp=1558342470065, value=zhangsan 10001 column=info:sex, timestamp=1558342551186, value=male 10002 column=info:age, timestamp=1558343570256, value=30 10002 column=info:name, timestamp=1558343559457, value=wangwu 10002 column=info:qq, timestamp=1558343612746, value=231294737 10002 column=info:tel, timestamp=1558343607851, value=231294737 2 row(s) in 0.0220 seconds##插入數(shù)據(jù),rowkey:10003 hbase(main):021:0> put 'user', '10003', 'info:name', 'zhaoliu' 0 row(s) in 0.0050 seconds##范圍查詢,只查詢name和age兩個(gè)列 hbase(main):022:0> scan 'user', {COLUMNS => ['info:name', 'info:age']} ROW COLUMN+CELL 10001 column=info:age, timestamp=1558342530687, value=25 10001 column=info:name, timestamp=1558342470065, value=zhangsan 10002 column=info:age, timestamp=1558343570256, value=30 10002 column=info:name, timestamp=1558343559457, value=wangwu 10003 column=info:name, timestamp=1558345826709, value=zhaoliu ##只從某個(gè)rowkey開始往后查 hbase(main):023:0> scan 'user', {STARTROW => '10002'} ROW COLUMN+CELL 10002 column=info:age, timestamp=1558343570256, value=30 10002 column=info:name, timestamp=1558343559457, value=wangwu 10002 column=info:qq, timestamp=1558343612746, value=231294737 10002 column=info:tel, timestamp=1558343607851, value=231294737 10003 column=info:name, timestamp=1558345826709, value=zhaoliu 2 row(s) in 0.0120 seconds#從某個(gè)rowkey到某個(gè)rowkey(包前不包后)hbase(main):002:0> scan 'user', {STARTROW => '10001',ENDROW => '10003'}
ROW?????????????????????????????????? COLUMN+CELL???????????????????????????????????????????????????????????????????????????????????????????????????????????????????
? 10001??????????????????????????????? column=info:address, timestamp=1558342595476, value=shanghai??????????????????????????????????????????????????????????????????
? 10001??????????????????????????????? column=info:age, timestamp=1558342530687, value=25????????????????????????????????????????????????????????????????????????????
? 10001??????????????????????????????? column=info:name, timestamp=1558342470065, value=zhangsan?????????????????????????????????????????????????????????????????????
? 10001??????????????????????????????? column=info:sex, timestamp=1558342551186, value=male??????????????????????????????????????????????????????????????????????????
? 10002??????????????????????????????? column=info:age, timestamp=1558343570256, value=30????????????????????????????????????????????????????????????????????????????
? 10002??????????????????????????????? column=info:name, timestamp=1558343559457, value=wangwu???????????????????????????????????????????????????????????????????????
? 10002??????????????????????????????? column=info:qq, timestamp=1558343612746, value=231294737??????????????????????????????????????????????????????????????????????
? 10002??????????????????????????????? column=info:tel, timestamp=1558343607851, value=231294737
轉(zhuǎn)載于:https://www.cnblogs.com/weiyiming007/p/10898494.html
總結(jié)
以上是生活随笔為你收集整理的1.4-1.5 HBase部署及基本使用的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: elasticsearch 问题
- 下一篇: 【微波】【1】色散关系式与 TEM导波、