操作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)]命令
- 创建表:create
- craet '表名','列名1','列名2','列名3','....','列名N'
- 查看所有表:list
- list
- 查看表结构:describe
- describe '表名'
- 添加数据:put
- put '表名','行键','列键','值'
- 扫描表:'scan'
- scan '表名',{COLUMNS=>['列族1','列族2','....'],参数名=>'参数值'}scan '表名','行键',{COLUMN=>['列键1','列键2','....'],参数名=>'参数值'}
- COLUMNS: scan '表名',{COLUMNS=>'info'}
- COLUMNS: scan '表名',{COLUMN=>'info:name'}
- 获取数据:get
- get '表名','行键',{COLUMNS=>['列族1','列族2','....'],参数名=>'参数值'}get '表名','行键',{COLUMN=>['列键1','列键2','....'],参数名=>'参数值'}
- 删除数据:delete
- delete '表名','行键','列键'deleteall '表名','行键'
- 修改表:alter
- alter '表名',参数名=>'参数值',....同时修改两个列族 alter '表名',{参数名=>'参数值'},{参数名=>'参数值'}
- 删除表:drop
- 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