HBase安装及测试
HBase安装及测试
? 1.单机安装
1.1安装HBase
?? 执行命令:
?? cd /usr/hadoop
?? mkdir v20hadoop
将hbase-0.20.0拷贝至/usr/hadoop/v20hadoop
1.2启动/关闭HBase
?? bin/start-hbase.sh
?? bin/stop-hbase.sh
1.3测试HBase
?? bin/hbase shell
?? create ‘bigtable1’ ‘data’
?? put ‘bigtable1’,’row1’,’data:aa’,’value1’
?? put ‘bigtable1’,’row2’,’data:bb’,’value2’
?? list
?? scan ‘bigtable1’
???? 1.4HBase数据格式概述
??????? HBase以键值对的形式来表示数据,如
??????? 001云计算: {0001:电信研究院云计算组,0002:北京邮电大学实验室
? ?2.多机安装
??? 2.1安装hadoop-0.20.1
????? 安装步骤同hadoop0.18.3,区别在于配置文件设置
??????? conf/core-site.xml配置:
<configuration>
<property>
? <name>fs.default.name</name>
? <value>hadoop6:9000</value>
</property>
</configuration>
?????? ?conf/hdfs-site.xml配置:
<configuration>
<property>
? <name>dfs.name.dir</name>
? <value>/usr/hadoop/filesystem/name</value>
</property>
<property>
? <name>dfs.data.dir</name>
? <value>/usr/hadoop/filesystem/data</value>
</property>
</configuration>
??????? conf/mapred-site.xml配置:
<configuration>
<property>
? <name>mapred.job.tracker</name>
? <value>hadoop5:9001</value>
</property>
<property>
? <name>mapred.local.dir</name>
? <value>/usr/hadoop/mr/localdata</value>
</property>
<property>
? <name>mapred.system.dir</name>
? <value>/usr/hadoop/mr/systemdata</value>
</property>
<property>
? <name>mapred.tasktracker.map.tasks.maximum</name>
? <value>2</value>
</property>
<property>
? <name>mapred.tasktracker.reduce.tasks.maximum</name>
? <value>2</value>
</property>
?? 2.2配置hbase-0.20.0
????? ??在conf/hbase_env.sh尾部加入
?????? ???export JAVA_HOME=/usr/java/jdk1.6.0_12
??????? 在conf/regionservers尾部加入
????????? hadoop3
??????? conf/hbase-site.xml配置:
?????? ??<property>
?????????? ??<name>hbase.rootdir</name>
? ???????????<value>hdfs://hadoop6:9000/hbase</value>
??????????</property>
?????????? <property>
?????????? ??<name>hbase.zookeeper.property.clientPort</name>
? ???????????<value>2181</value>
??????????</property>
?????? ??<property>
?????????? ??<name>hbase.cluster.distributed</name>
? ???????????<value>true</value>
??????????</property>
?????? 在stop-hbase.sh文件中加入"$bin"/hbase-daemons.sh --config "${HBASE_CONF_DIR}" \
? --hosts "${HBASE_REGIONSERVERS}" start regionserver。
?? 3.常用API
?
?
函数名/对象名
?
简述
?
所在包/类
?
备注
?
HBaseConfiguratio.HBaseConfiguration()
?
HBase配置对象
?
org.apache.hadoop.hbase.HBaseConfiguratio
?
?
?
HTable.HTable(HBaseConfiguration
?
conf, byte[]?tableName)
?
?
定位HBase之table
?
org.apache.hadoop.hbase.client.HTable
?
?
?
HTable.put(Put
?
put)
?
?
添加提交
?
org.apache.hadoop.hbase.client.HTable
?
?
?
HTable.get(Get
?
get)
?
?
读提交
?
org.apache.hadoop.hbase.client.HTable
?
?
?
HTable.getScanner(byte[]?family)
?
?
表扫描
?
org.apache.hadoop.hbase.client.HTable
?
?
?
Put.put(byte[]?row)
?
?
定位行
?
org.apache.hadoop.hbase.client.Put
?
?
?
Put.add
(byte[]?family, byte[]?qualifier, long?ts, byte[]?value)
?
?
添加值
?
org.apache.hadoop.hbase.client.Put
?
?
?
Get.Get(byte[]?row)
?
?
读定位行
?
org.apache.hadoop.hbase.client.Get
?
?
?
Get.addColumn(byte[]?column)
?
?
读定位列
?
org.apache.hadoop.hbase.client.Get
?
?
?
Result
?
结果对象
?
org.apache.hadoop.hbase.client.Result
?
?
?
ResultScanner
?
扫描结果对象
?
org.apache.hadoop.hbase.client.ResultScanner
?
?
?
?
?
?
?
?
?
?
?
?
?
?
?
?
?
?
?
?