3.Hbase安装
1.系统版本信息
OS:Debian-8.2 JDK:1.8.0_181 Hadoop-2.8.4 Zookeeper-3.4.10 Hbase:1.3.1
主机信息
192.168.74.131 master 192.168.74.133 slave1 192.168.74.134 slave2 192.168.74.135 slave3
2.前提条件
- A:安装好jdk并配置好环境变量
- B:安装好Hadoop并能够跑通example下的wordcout
- C:安装好zookeeper,并能够跑通
3.首先在master上安装hbase
A:下载hbase1.4.6
使用wget下载镜像站下的某个版本,如wget http://mirror.bit.edu.cn/apache/hbase/1.4.6/hbase-1.4.6-bin.tar.gz
http://mirror.bit.edu.cn/apache/hbase/
B:解压并移动hbase到指定文件夹下
tar zxvf hbase-1.4.6-bin.tar.gz mv hbase-1.4.6 /home/hadoop/opt/
C:配置环境变量
sudo vim /etc/profile #Set Hbase Path export HBASE_HOME=/home/hadoop/opt/hbase-1.4.6 export PATH=$PATH:$HBASE_HOME/bin ##立即生效 source /etc/profile
D:配置Hbase配置文件hbase-site.xml,注意的是这个配置文件是与hadoop,zookeeper密切相关的,所以前提是已经配置好hadoop和zookeeper
cd /home/hadoop/opt/hbase-1.4.6/conf vim hbase-site.xml <configuration> <property> <name>hbase.rootdir</name> <value>hdfs://master:9000/hbase</value> </property> <property> <name>hbase.cluster.distributed</name> <value>true</value> </property> <property> <name>hbase.zookeeper.quorum</name> <value>master,slave1,slave2,slave3</value> </property> <property> <name>hbase.zookeeper.property.dataDir</name> <value>/home/hadoop/opt/zookeeper-3.4.10/data</value> </property> <property> <name>hbase.tmp.dir</name> <value>/home/hadoop/opt/hbase-1.4.6/tmp</value> </property> <property> <name>hbase.master</name> <value>hdfs://master:60000</value> </property> </configuration>
E:配置hbase的Java_home,配置文件为hbase-env.sh
cd /home/hadoop/opt/hbase-1.4.6/conf vim hbase-env.sh export JAVA_HOME=/home/hadoop/opt/jdk1.8.0_181
4.建立hbase数据文件夹
因为在上一步中设置了hbase.tmp.dir的目录,这里需要手动建立目录/home/hadoop/opt/hbase-1.4.6/tmp
cd /home/hadoop/opt/hbase-1.4.6 mkdir -p tmp/hbase
5.使用scp将master上的hbase拷贝到每个slave机器上
scp -r /home/hadoop/opt/hbase-1.4.6 hadoop@slave1:/home/hadoop/opt/ scp -r /home/hadoop/opt/hbase-1.4.6 hadoop@slave2:/home/hadoop/opt/ scp -r /home/hadoop/opt/hbase-1.4.6 hadoop@slave3:/home/hadoop/opt/ ##拷贝完成之后修改环境变量sudo vim /etc/profile #Set Hbase Path export HBASE_HOME=/home/hadoop/opt/hbase-1.4.6 export PATH=$PATH:$HBASE_HOME/bin #立即生效 source /etc/profile
6.在master上启动habse
需要保证hdfs和zookeeper服务已开启
#在master上启动 cd /home/hadoop/opt/hbase-1.4.6/bin start-hbase.sh #在master和slave上分别输入jps查看开启的服务 jps
在浏览器中输入http://192.168.74.131:16010/master-status查看
7.使用hbase shell创建表
注意的是在使用shell的时候需要启动hbase集群,zookeeper管理
cd /home/hadoop/opt/hbase-1.4.6/bin hbase shell
下面创建这样一张表customer
rowkey | address | info | phone | |||
province | city | country | age | company | ||
zhangsan | hubei | wuhan | china | 24 | douyu | 101 |
lisi | guangdong | guangzhou | china | 24 | netease | 102 |
create 'customer','address','info', 'phone' put 'customer','zhangsan','phone:','101' put 'customer','zhangsan','address:province','hubie' put 'customer','zhangsan','address:city','wuhan' put 'customer','zhangsan','address:country','china' put 'customer','zhangsan','info:age','24' put 'customer','zhangsan','info:company','douyu' put 'customer','lisi','phone:','102' put 'customer','lisi','address:province','guangdong' put 'customer','lisi','address:city','guangzhou' put 'customer','lisi','address:country','china' put 'customer','lisi','info:age','24' put 'customer','lisi','info:company','netease'
扫描所有数据
scan 'customer'
根据键值查询数据
get 'customer','zhangsan' get 'customer','zhangsan','phone'
删除指定数据
delete 'customer','lisi','phone' delete 'customer','lisi'
修改表结构
disable 'customer' alter 'customer',PHONE=>'tel' enable 'customer'
改变或者添加一个列族
disable 'customer' alter 'customer',PHONE=>'tel' ,'VERSION=>5' enable 'customer
删除一个列族
disable 'customer' alter 'customer', NAME => 'f1', METHOD => 'delete' alter 'customer', 'delete' => 'f1' enable 'customer
统计行数
count 'customer'
表的删除
drop 'customer'
退出shell
quit
http://www.cnblogs.com/makexu/