0.硬件环境:三台机器Ubuntu15.10内存1.5G硬板20G
1.name Ubuntu15.10内存1.5G硬板20G
2.sname Ubuntu15.10内存1.5G硬板20G
3.amrm Ubuntu15.10内存1.5G硬板20G
安装前的基本要求,安装zookeeper集群在三台机器上,ssh可无密码登陆
1.配置hosts
Sudo Vim /etc/hosts
127.0.0.1 localhost 192.168.159.136 name 192.168.159.135 sname 192.168.159.132 amrm
2.解除 Linux 系统的最大进程数和最大文件打开数限制:
vim /etc/security/limits.conf
# 添加如下的行 * soft noproc 32000 * hard noproc 32000 * soft nofile 32768 * hard nofile 32768
说明:* 代表针对所有用户,noproc 是代表最大进程数,nofile 是代表最大文件打开数
3.配置环境变量
sudo vim ~/.bahsrc 或/etc/profile
# the variable for hadoop export JAVA_HOME=/usr/lib/java/jdk1.7.0_79 export JRE_HOME=${JAVA_HOME}/jre export CLASS_PATH=.:${JAVA_HOME}/lib:${JRE_HOME}/lib export HADOOP_HOME=/hadoop/hadoop-2.7.1 export HBASE_HOME=/hadoop/hbase-1.2.1 export ZOOKEEPER_HOME=/hadoop/zookeeper-3.4.6 export PATH=${JAVA_HOME}/bin:${HADOOP_HOME}/bin:${HADOOP_HOME}/sbin:${ZOOKEEPER_HOME}/bin:${HBASE_HOME}/bin:${PATH} export HADOOP_MAPRED_HOME=${HADOOP_HOME} export HADOOP_COMMON_HOME=${HADOOP_HOME} export HADOOP_HDFS_HOME=${HADOOP_HOME} export HADOOP_COMMON_LIB_NATIVE_DIR=${HADOOP}/lib/native export YARN_HOME=${HADOOP_HOME} export HADOOP_OPT="-Djava.library.path=${HADOOP_HOME}/lib/native"
4.修改$HBASE_HOME/conf/hbase-env.sh
export JAVA_HOME=/usr/lib/java/jdk1.7.0_79 export HBASE_OPTS="-Xmn150m" export SERVER_GC_OPTS="-XX:CMSInitiatingOccupancyFraction=80 -XX:+UseParNewGC -XX:+UseConcMarkSweepGC" export HBASE_MANAGES_ZK=false
5.修改文件hbase-site.xml,修改内容如下
hbase.rootdir hdfs://name:9000/hbase hbase.cluster.distributed true hbase.zookeeper.quorum name,sname,amrm dfs.replication 3
6.修改文件regionservers,修改内容如下
sname amrm
注:修改backup-masters每行一个主机名,代表备用master提高,可用性及健壮性。
sname
7.启动Hbase
start-hbase.sh
8.启动hbase shell,进入shell环境
hbase shell
8.1创建表
create 'users','user_id','address','info'
(说明:表users,有三个列族user_id,address,info)
8.2列出全部表
list
8.3得到表的描述
describe 'users'
8.4添加记录
put ‘表名’,’行键(标识)’,’列族:字段’,’数值’
示例:
1.put 'users','xiaoming','info:age','24'; 2.put 'users','xiaoming','info:birthday','1987-06-17'; 3.put 'users','xiaoming','info:company','alibaba'; 4.put 'users','xiaoming','address:contry','china'; 5.put 'users','xiaoming','address:province','zhejiang'; 6.put 'users','xiaoming','address:city','hangzhou'; 7.put 'users','zhangyifei','info:birthday','1987-4-17'; 8.put 'users','zhangyifei','info:favorite','movie'; 9.put 'users','zhangyifei','info:company','alibaba'; 10.put 'users','zhangyifei','address:contry','china'; 11.put 'users','zhangyifei','address:province','guangdong'; 12.put 'users','zhangyifei','address:city','jieyang'; 13.put 'users','zhangyifei','address:town','xianqiao'
8.5获取一条记录
1. 取得一个id的所有数据
1.>get 'users','xiaoming'
2. 获取一个id,一个列族的所有数据
1.>get 'users','xiaoming','info'
3. 获取一个id,一个列族中一个列的所有数据
1.>get 'users','xiaoming','info:age'
8.6更新记录
1.>put 'users','xiaoming','info:age' ,'29' 2.>get 'users','xiaoming','info:age' 3.>put 'users','xiaoming','info:age' ,'30' 4.>get 'users','xiaoming','info:age'
8.7获取单元格数据的版本数据
1.>get 'users','xiaoming',{COLUMN=>'info:age',VERSIONS=>1} 2.>get 'users','xiaoming',{COLUMN=>'info:age',VERSIONS=>2} 3.>get 'users','xiaoming',{COLUMN=>'info:age',VERSIONS=>3}
8.8获取单元格数据的某个版本数据
1.〉get 'users','xiaoming',{COLUMN=>'info:age',TIMESTAMP=>1364874937056}
8.9全表扫描
1.>scan 'users'
8.10删除xiaoming值的'info:age'字段
1.>delete 'users','xiaoming','info:age' 2.>get 'users','xiaoming'
8.11删除整行
1.>deleteall 'users','xiaoming'
8.12统计表的行数
1.>count 'users'
8.13清空表
1.>truncate 'users'