1. Zookeeper正常部署

2. Hadoop正常部署

date -s “218-08-09 12:12:12”

3. HBase安装部署

wget https://dlcdn.apache.org/hbase/2.4.8/hbase-2.4.8-bin.tar.gz
①. HBase的解压
tar -zxvf hbase-2.4.8-bin.tar.gz -C /opt/module
hbase-env.sh
export JAVA_HOME=/opt/java/jdk1.8.0_181
export HBASE_MANAGES_ZK=false # 由HBase负责启动和关闭Zookeeper 可以注释
# Configure PermSize. Only needed in JDK7. You can safely remove it for >JDK8+
#export HBASE_MASTER_OPTS=”$HBASE_MASTER_OPTS -?>XX:PermSize=128m -XX:MaxPermSize=128m” #export HBASE_REGIONSERVER_OPTS=”$ HBASE_REGIONSERVER_OPTS ->XX:PermSize=128m XX:MaxPermSize=128m”

hbase-site.xml

hbase.rootdir
hdfs://master:9000/hbase


hbase.cluster.distributed
true


hbase.master.port
16000


hbase.zookeeper.quorum
master:2181,slaver1:2181,slaver2:2181


hbase.zookeeper.property.dataDir
/opt/module/zookeeper-3.4.5/zkData

regionservers
master
slaver1
slaver2

③. 软连接hadoop配置文件到hbase
ln -s /usr/hadoop-3.3.1/etc/hadoop/core-site.xml /opt/module/hbase-2.4.8/conf/core-site.xml
ln -s /usr/hadoop-3.3.1/etc/hadoop/hdfs-site.xml /opt/module/hbase-2.4.8/conf/hdfs-site.xml

④. 远程发送到其他集群
scp -r /opt/module/hbase-2.4.8/ root@slaver1:/opt/module/
scp -r /opt/module/hbase-2.4.8/ root@slaver2:/opt/module/


Hbase的启动

  1. 单节点启动

cd /opt/module/hbase-2.4.8/
bin/hbase-daemon.sh start master
bin/hbase-daemon.sh start regionserver
如果集群之间的节点时间不同步,会导致regionserver无法启动,抛出ClockOutOfSyncException异常。

  1. 群起

cd /opt/module/hbase-2.4.8/
bin/start-hbase.sh

  1. 查看HBase页面
    http://master:16010

HBase Shell基本操作

  1. 进入HBase客户端命令行
    bin/hbase shell
  2. 查看帮助命令
    help
  3. 查看当前数据库中有哪些表
    list

表的操作

  1. 创建表
    create ‘student’,’info’
  2. 插入数据到表
    put ‘student’,’1001’,’info:sex’,’male’
    put ‘student’,’1001’,’info:age’,’18’
    put ‘student’,’1002’,’info:name’,’Janna’
    put ‘student’,’1002’,’info:sex’,’female’
    put ‘student’,’1002’,’info:age’,’20’
  3. 扫描查看表数据
    scan ‘student’
    scan ‘student’,{STARTROW => ‘1001’, STOPROW => ‘1001’}
    scan ‘student’,{STARTROW => ‘1001’}
  4. 查看“指定行”或“指定列族:列”的数据
    get ‘student’,’1001’
    get ‘student’,’1001’,’info:name’
  5. 查看表结构
    describe ‘student’
  6. 更新指定字段的数据
    put ‘student’,’1001’,’info:name’,’Nick’
    put ‘student’,’1001’,’info:age’,’100’
  7. 统计表数据行数
    count ‘student’
  8. 变更表信息
    alter ‘student’,{NAME=>’info’,VERSIONS=>3}
    get ‘student’,’1001’,{COLUMN=>’info:name’,VERSIONS=>3}
  9. 删除数据
  • 删除某rowkey的全部数据:
    deleteall ‘student’,’1001’
  • 删除某rowkey的某一列数据:
    delete ‘student’,’1002’,’info:sex’
  1. 清空表数据
    truncate ‘student’
  2. 删除表
  • 首先需要先让该表为disable状态:
    disable ‘student’
  • 然后才能drop这个表:
    drop ‘student’
    $\color{red}{如果直接drop表,会报错:ERROR: Table student is enabled. Disable it first.}$
  1. 导入数据
    创建文件
    vi text.csv

1,”Tony” 2,”Ivy” 3,”Tom” 4,”Spark” 5,”Storm”

上传文件
hdfs dfs -put text.csv /jj
hdfs dfs -ls /jj
创建表
hbase(main):001:0> create ‘demo’,’cf’
执行mapreduce导入数据
hbase org.apache.hadoop.hbase.mapreduce.ImportTsv -Dimporttsv.separator=”,” -Dimporttsv.columns=HBASE_ROW_KEY,cf demo /jj/test.csv
||
hbase org.apache.hadoop.hbase.mapreduce.ImportTsv \ -Dimporttsv.separator=”,” \ -Dimporttsv.columns=HBASE_ROW_KEY,cf demo /jj/test.csv