hbase2单节点安装与数据操作

操作系统:centos7.4
Java:java version 1.8.0
Hadoop:Hadoop 2.7.2
Zookeeper:zookeeper 3.4.12
本文是单节点hbase快速安装 不用hadoop和单独的zookeeper。后面有hbase集群模式的文章

创建目录

mkdir -p /opt/fffmo/java

进入目录

cd /opt/fffmo/java

下载java1.8
wget https://download.oracle.com/otn-pub/java/jdk/8u191-b12/2787e4a523244c269598db4e85c51e0c/jdk-8u191-linux-x64.tar.gz?AuthParam=1543544760_047387daf91d76694521379fc5a04398c
解压
tar -zxvf jdk-8u191-linux-x64.tar.gz?AuthParam=1543544760_047387daf91d76694521379fc5a04398c
移动
mv jdk-8u191-linux-x64 jdk8

配置环境变量


vi /etc/profile

最底下加入java环境
export JAVA_HOME=/opt/fffmo/java/jdk8
export JAVA_BIN=/opt/fffmo/java/jdk8
export PATH=$PATH:$JAVA_HOME/bin
export CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
export JAVA_HOME JAVA_BIN PATH CLASSPATH

启用环境变量
source /etc/profile
创建目录
mkdir -p /opt/fffmo/hbase
cd /opt/fffmo/hbase
下载hbase2.1
wget http://archive.apache.org/dist/hbase/2.1.1/hbase-2.1.1-bin.tar.gz

解压
tar -zxvf hbase-2.1.1-bin.tar.gz
移动hbase
mv hbase-2.1.1-bin hbase2

进入 Hbase2

cd hbase2

文件系统可以选用本地文件系统。可以使用hdfs
修改配置文件

vi conf/hbase-site.xml

配置文件如下

<configuration>
    <property>
        <name>hbase.rootdir</name>
        <value>file:///opt/fffmo/hbase/hbase2/rootdir</value>  <!-- hbase共享目录,持久化hbase数据  存放在对应的目录上可以放hdfs -->
    </property>
    <property>
        <name>hbase.zookeeper.property.dataDir</name>
        <value>/opt/fffmo/hbase/hbase2/zookeeper</value>   <!-- zookeeper配置信息快照的位置 -->
    </property>
</configuration>
./bin/start-hbase.sh

提示running master 证明成功

访问页面

http://ip:16010
./bin/stop-hbase.sh

连接hbase

hbase/bin/hbase shell

出现如下界面,表示连接成功,可以输入hbase的命令。

··
hbase(main):001:0>

创建表student

hbase(main):004:0> create 'student', 'f1'
0 row(s) in 1.3200 seconds

=> Hbase::Table - student

查看有哪些表

hbase(main):006:0> list
TABLE                   
student                                                                 1 row(s) in 0.0490 seconds
=> ["student"]

添加数据
分别输入下面语句,将三个学生的信息添加到hbase中。

put 'student', '2019001','f1:name','zhangsan'
put 'student', '2019001','f1:sex','male'
put 'student', '2019001','f1:age','23'


put 'student', '2019002','f1:name','fffmo'
put 'student', '2019002','f1:sex','female'
put 'student', '2019002','f1:age','22'


put 'student', '2019003','f1:name','wanwu'
put 'student', '2019003','f1:sex','male'
put 'student', '2019003','f1:age','24'

显示表的所有记录

hbase(main):022:0> scan 'student'
ROW                                         COLUMN+CELL                                                                                                                   
 2019001                                    column=f1:age, timestamp=1514122123963, value=23                                                                              
 2019001                                    column=f1:name, timestamp=1514122123729, value=zhangsan                                                                       
 2019001                                    column=f1:sex, timestamp=1514122123843, value=male                                                                            
 2019002                                    column=f1:age, timestamp=1514122124178, value=22                                                                              
 2019002                                    column=f1:name, timestamp=1514122124062, value=fffmo                                                                           
 2019002                                    column=f1:sex, timestamp=1514122124129, value=female                                                                          
 2019003                                    column=f1:age, timestamp=1514122127361, value=24                                                                              
 2019003                                    column=f1:name, timestamp=1514122124292, value=wanwu                                                                          
 2019003                                    column=f1:sex, timestamp=1514122124394, value=male                                                                            
3 row(s) in 0.1050 seconds

根据行键id为查看某一条记录
显示行键id为2019001的学生信息

get 'student','2019001'
COLUMN                                      CELL                                                                                                                          
 f1:age                                     timestamp=1514122123963, value=23                                                                                             
 f1:name                                    timestamp=1514122123729, value=zhangsan                                                                                       
 f1:sex                                     timestamp=1514122123843, value=male                                                                                           
3 row(s) in 0.0200 seconds

修改一条记录
将id为2019003的学生age改为25

put 'student', '2019003','f1:age','25'
0 row(s) in 0.0190 seconds

删除某一条记录
删除id为2019002的学生信息

deleteall 'student','2019002'
0 row(s) in 0.0500 seconds

随机文章