操作Hbase(NoSql关系型数据库)

操作Hbase

<1.启动服务

 启动服务:
a) start-all.sh                       启动hadoop各个服务(用这个  $jsp验证)
b) zkServer.sh start                  启动zookeeper(这两个用于Hbase数据库服务开启)
c) start-hbase.sh                     启动hbase
e) systemctl stop firewalld.service   #停止firewall
f)hbase  shell                         从hadoop进入hbase数据库

一.hbase数据库操作[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-2oJ6CT6i-1583066887814)(E:\Typora\info\Hbase\操作Hbase.assets\Hbase数据结构.png)]命令

  1. 创建表:create
  2. craet '表名','列名1','列名2','列名3','....','列名N'
  3. 查看所有表:list
  4. list
  5. 查看表结构:describe
  6. describe '表名'
  7. 添加数据:put
  8. put '表名','行键','列键','值'
  9. 扫描表:'scan'
  10. scan '表名',{COLUMNS=>['列族1','列族2','....'],参数名=>'参数值'}
    scan '表名','行键',{COLUMN=>['列键1','列键2','....'],参数名=>'参数值'}
    • COLUMNS: scan '表名',{COLUMNS=>'info'}
    • COLUMNS: scan '表名',{COLUMN=>'info:name'}
  11. 获取数据:get
  12. get '表名','行键',{COLUMNS=>['列族1','列族2','....'],参数名=>'参数值'}
    get '表名','行键',{COLUMN=>['列键1','列键2','....'],参数名=>'参数值'}
  13. 删除数据:delete
  14. delete '表名','行键','列键'
    deleteall '表名','行键'
  15. 修改表:alter
  16. alter '表名',参数名=>'参数值',....
    同时修改两个列族 alter '表名',{参数名=>'参数值'},{参数名=>'参数值'}
  17. 删除表:drop
  18. disable '表名'
    drop '表名'

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-oNE5lAqV-1583066887816)(E:\Typora\info\操作Hbase.assets\1571727304074.png)]

<2.配置环境变量和xml文件

一.找到{计算机/usr/local/hadoop/etc/hadoop/hadoop-env.sh}下配置环境变量

export HADOOP_CLASSPATH=$HADOOP_CLASSPATH:~/hbase-1.2.5/lib/*

二.配置core-site.xml

<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="configuration.xsl"?>
<!--
  Licensed under the Apache License, Version 2.0 (the "License");
  you may not use this file except in compliance with the License.
  You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

  Unless required by applicable law or agreed to in writing, software
  distributed under the License is distributed on an "AS IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  See the License for the specific language governing permissions and
  limitations under the License. See accompanying LICENSE file.
-->

<!-- Put site-specific property overrides in this file. -->

<configuration>
    <property>
        <name>hadoop.tmp.dir</name>
        <value>file:/usr/local/hadoop/tmp</value>
        <description>Abase for other temporary directories.</description>
    </property>
    <property>
        <name>fs.defaultFS</name>
        <value>hdfs://szxs.hadoop:9000</value>
    </property>
    <property>
	<name>fs.default.name</name>
	<value>hdfs://szxs.hadoop:9000</value>
    </property>
</configuration>

❤️.测试jar是否有用

$ hadoop jar hbase-server-1.2.5.jar rowcounter music

<4.找到 {计算机/usr/local/hadoop/share/hadoop/mapreduce}

$ hadoop jar hbase-server-1.0.2.jar importtsv -Dimporttsv.bulk.output=tmp -Dimporttsv.columns=HBASE_ROW_KEY,info:name,info:singer:info:gender,info:ryghme,info:terminal  music2 /accp/music/music2.txt

<5.运行将代码导入文件到Hbase数据库中

$ hadoop jar hbase-server-1.0.2.jar completebulkload tmp music

异常报错

ClassNotFound:              检查MapReduce和Hbase集成环境是否配置正确
music表不存在                 创建music表或者对importtsv使用-Dcreate.table=yes
tmp目录已存在   				  删除HDFS上"user/hduser/tmp"目录
ZooKeeper session超时或过期    尝试重新启动Hbase 
创建music表或者对importtsv使用-Dcreate.table=yes

tmp目录已存在 删除HDFS上"user/hduser/tmp"目录
ZooKeeper session超时或过期 尝试重新启动Hbase


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值