启动和停止Hbase

首先使用hadoop用户启动hadoop
start-dfs.sh
image.png

start-hbase.sh
image.png
jps
image.png

停止Hbase

stop-hbase.sh


hbase shell
hbase(main):001:0> quit

image.png


hbase> status
image.png

hbase> status ‘simple’
image.png
hbase> status ‘summary’
image.png

hbase> status ‘detailed’

hbase> whoami
image.png

hbase> version
image.png


hbase> list
image.png



hbase> create ‘apple’,’price’,’volume’
image.png


hbase> disable ‘apple’
hbase> drop ‘apple’

image.png


hbase> create ‘apple’,’price’,’volume’


put ‘apple’,’6-May-15’,’price:open’,’126.56’
put ‘apple’,’6-May-15’,’price:high’,’126.75’
put ‘apple’,’6-May-15’,’price:low’,’123.36’
put ‘apple’,’6-May-15’,’price:close’,’125.01’
put ‘apple’,’6-May-15’,’volume’,’71820387’


hbase> scan ‘apple’

image.png


hbase> get ‘apple’,’6-May-15’

image.png


hbase> get ‘apple’,’6-May-15’,{COLUMN => ‘price:low’}

image.png

hbase> get ‘apple’,’6-May-15’,{COLUMN => [‘price:low’,’price:high’]}

image.png

hbase> get ‘apple’,’6-May-15’,{COLUMN => [‘price:low’,’price:high’ ,’volume’]}

image.png

hbase> get ‘apple’,’6-May-15’

hbase> delete ‘apple’,’6-May-15’,’price:low’

hbase> get ‘apple’,’6-May-15’


image.png


hbase> deleteall ‘apple’,’6-May-15’

hbase> get ‘apple’,’6-May-15’
image.png

hbase> describe ‘apple’
image.png

重新为表’apple’插入数据


put ‘apple’,’6-May-15’,’price:open’,’126.56’
put ‘apple’,’6-May-15’,’price:high’,’126.75’
put ‘apple’,’6-May-15’,’price:low’,’123.36’
put ‘apple’,’6-May-15’,’price:close’,’125.01’
put ‘apple’,’6-May-15’,’volume’,’71820387’


hbase> truncate ‘apple’
image.png
hbase>describe ‘apple’
image.png
重新为表’apple’插入数据


put ‘apple’,’6-May-15’,’price:open’,’126.56’
put ‘apple’,’6-May-15’,’price:high’,’126.75’
put ‘apple’,’6-May-15’,’price:low’,’123.36’
put ‘apple’,’6-May-15’,’price:close’,’125.01’
put ‘apple’,’6-May-15’,’volume’,’71820387’

hbase> scan ‘apple’
image.png

  1. HBase中,namespace命名空间指对一组表的逻辑分组,类似RDBMS中的database,方便对表在业务上划分。<br /> <br />alter_namespace<br />create_namespace<br />describe_namespace<br />drop_namespace<br />list_namespace<br />list_namespace_tables<br />


hbase> list_namespace

image.png



hbase> list_namespace_tables ‘default’
image.png

hbase> list_namespace_tables ‘hbase’

image.png



hbase> create_namespace ‘dyydb’

hbase> list_namespace

image.png

hbase> list_namespace

hbase> drop_namespace ‘dyydb’

hbase> list_namespace

image.png

hbase> list_namespace

hbase> create_namespace ‘dyydb’

hbase> list_namespace


以下命令在命名空间dyydb下创建apple表

hbase> create ‘dyydb:apple’,’price’,’volume’

hbase> list_namespace_tables ‘dyydb’

image.png

hbase> describe_namespace ‘dyydb’

image.png

hbase> describe_namespace ‘dyydb’
image.png
hbase> alter_namespace ‘dyydb’,{METHOD=>’set’,’TEST_PROPERTY’=>’TEST_VALUE’}
image.png


hbase> disable ‘apple’

hbase> drop ‘apple’


hbase> create ‘apple’,’price’,’volume’

put ‘apple’,’6-May-15’,’price:open’,’126.56’
put ‘apple’,’6-May-15’,’price:high’,’126.75’
put ‘apple’,’6-May-15’,’price:low’,’123.36’
put ‘apple’,’6-May-15’,’price:close’,’125.01’
put ‘apple’,’6-May-15’,’volume’,’71820387’

hbase> describe ‘apple’
image.png

hbase> alter ‘apple’,{NAME => ‘NewCF2’,VERSIONS =>1}

hbase> describe ‘apple’

put ‘apple’,’6-May-15’,’NewCF2:NewColumn’,’dyy’

hbase> scan ‘apple’
image.png


以下两条命令均可删除列族!

hbase> alter ‘apple’,{NAME => ‘NewCF2’, METHOD => ‘delete’}
或者
hbase> alter ‘apple’, ‘delete’ => ‘NewCF2’


hbase> scan ‘apple’
image.png

hbase> alter ‘apple’,{NAME => ‘NewCF2’, VERSIONS => 3}


改变一个列族的最大大小为128MB
alter ‘apple’, METHOD => ‘table_att’, MAX_FILESIZE => ‘134217728’

**
删除NewCF2,增加NewCF3
alter ‘apple’, {NAME => ‘NewCF3’}, {NAME => ‘NewCF2’, METHOD => ‘delete’}

hbase> describe ‘apple’
image.png

hbase> exists ‘apple’
image.png

hbase> exists ‘dyydb:apple’
image.png

hbase> exists ‘dyydb:cisco’
image.png


hbase> is_enabled ‘dyydb:apple’

hbase> disable ‘dyydb:apple’

hbase> is_enabled ‘dyydb:apple’

hbase> is_disabled ‘dyydb:apple’
image.png

====
hbase> disable ‘apple’

hbase> enable ‘apple’

=====


hbase> show_filters
image.png

put ‘apple’,’6-May-15’,’price:testcount’,’1’
image.png

vi testHbaseShellScript2.sh

hbase shell<disable ‘apple’
drop ‘apple’
create ‘apple’,’price’,’volume’
put ‘apple’,’6-May-15’,’price:open’,’126.56’
put ‘apple’,’6-May-15’,’price:high’,’126.75’
put ‘apple’,’6-May-15’,’price:low’,’123.36’
put ‘apple’,’6-May-15’,’price:close’,’125.01’
put ‘apple’,’6-May-15’,’volume’,’71820387’
exit
EOF

sh

image.png

运行脚本input_to_hbase.sh,将AppleStock.csv文件导入Hbase
vim input_to_hbase.sh

#!/bin/bash
# Loads stock data in to Hbase table
TABLENAME="apple"
if ! [ -e "$1" ]; then
echo "Usage: provide file name"
exit 1
fi
# remove the first line
sed  -e "1d" $1 > clean_$1
while IFS=, read Date Open High Low Close Volume
do
#    echo "$Date|$Open|$High|$Low|$Close|$Volume"
echo -e put "'"$TABLENAME"','"$Date"','price:open','"$Open"'\n"\
put "'"$TABLENAME"','"$Date"','price:high','"$High"'\n"\
put "'"$TABLENAME"','"$Date"','price:low','"$Low"'\n"\
put "'"$TABLENAME"','"$Date"','price:close','"$Close"'\n"\
put "'"$TABLENAME"','"$Date"','volume','"$Volume"'" | hbase shell
status=$?
if [ $status -ne 0 ]; then
  echo "Error: HBase input failed. Input data:"
  echo "date=$Date|open=$Open|high=$High|low=$Low|close=$Close|volume=$Volume" 
fi
done < clean_$1
/bin/rm clean_$1


hbase> disable ‘apple’
hbase> drop ‘apple’

hbase> create ‘apple’,’price’,’volume’


cd /home/hadoop/Desktop/Section-Apache-Hbase
./input_to_hbase.sh Apple-stock.csv
image.png





hbase> disable ‘apple’
hbase> drop ‘apple’

hbase> create ‘apple’,’price’,’volume’

将文件AppleStock.csv

cd /home/hadoop/Desktop/Section-Apache-HBase
./convert-to-tsv.sh Apple-stock.csv

运行之前先开启hadoop和hbase
start-dfs.sh
start-yarn.sh
start-hbase.sh

将转换后的文件拷贝到HDFS上
hdfs dfs -put Apple-stock.tsv
**

hbase org.apache.hadoop.hbase.mapreduce.ImportTsv -Dimporttsv.columns=HBASE_ROW_KEY,price:open,price:high,price:low,price:close,volume apple /tmp/Apple-stock.tsv
image.png

hbase>scan ‘apple’image.png


http://192.168.100.13:16010/master-status

http://test:16010/master-status


http://localhost:16010/master-status