阿里云HBase Shell操作指南

下载配置

下载HBase Shell
https://hbaseuepublic.oss-cn-beijing.aliyuncs.com/hbaseue-shell.tar.gz?spm=a2c4g.11186623.2.5.72e9404bqjt0C1&file=hbaseue-shell.tar.gz

解压,然后在解压后的tar包中的conf/目录下的hbase-site.xml文件中,加入如下配置:  
HBase的连接地址,在HBase控制界面内的"数据库连接-连接信息"中,Java API访问地址拿到外网地址.
这里的密码不是集群管理密码,而是连接信息上方的密码
<configuration>      
    <!—    集群的连接地址,在控制台页面的数据库连接界面获得(注意公网地址和VPC内网地址)    —>    
    <property>
        <name>hbase.zookeeper.quorum</name>
        <value>ld-xxxx-proxy-hbaseue.hbaseue.xxx.rds.aliyuncs.com:30020</value>
    </property>
    <!—    设置用户名密码    —>    
    <property>
        <name>hbase.client.username</name>
        <value>xxx</value>
    </property>
    <property>
        <name>hbase.client.password</name>
        <value>xxx</value>
    </property>
</configuration>
进入tar包解压路径里的bin/目录
注:
1、默认log文件在hbase tar包解压后的logs目录下
2、使用Shell连接增强版只能做简单的DDL操作和数据读写操作

在此目录打开cmd/powershell窗口,执行 ./hbase shell  就可以开始使用原生的HBase Shell访问HBase增强版

运行异常解决

2021-01-11 10:39:34,017 ERROR [main] util.Shell: Failed to locate the winutils binary in the hadoop binary path
java.io.IOException: Could not locate executable null\bin\winutils.exe in the Hadoop binaries.
        at org.apache.hadoop.util.Shell.getQualifiedBinPath(Shell.java:382)
        at org.apache.hadoop.util.Shell.getWinUtilsPath(Shell.java:397)
        at org.apache.hadoop.util.Shell.<clinit>(Shell.java:390)
        at org.apache.hadoop.util.StringUtils.<clinit>(StringUtils.java:80)
        at org.apache.hadoop.conf.Configuration.getBoolean(Configuration.java:1507)
        at org.apache.hadoop.hbase.HBaseConfiguration.checkDefaultsVersion(HBaseConfiguration.java:66)
        at org.apache.hadoop.hbase.HBaseConfiguration.addHbaseResources(HBaseConfiguration.java:80)
        at org.apache.hadoop.hbase.HBaseConfiguration.create(HBaseConfiguration.java:94)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:498)
        at org.jruby.javasupport.JavaMethod.invokeDirectWithExceptionHandling(JavaMethod.java:438)
        at org.jruby.javasupport.JavaMethod.invokeStaticDirect(JavaMethod.java:360)
        at org.jruby.java.invokers.StaticMethodInvoker.call(StaticMethodInvoker.java:40)
        at org.jruby.runtime.callsite.CachingCallSite.cacheAndCall(CachingCallSite.java:318)
        at org.jruby.runtime.callsite.CachingCallSite.call(CachingCallSite.java:131)
        at org.jruby.ir.interpreter.InterpreterEngine.processCall(InterpreterEngine.java:339)
        at org.jruby.ir.interpreter.StartupInterpreterEngine.interpret(StartupInterpreterEngine.java:73)
        at org.jruby.ir.interpreter.InterpreterEngine.interpret(InterpreterEngine.java:77)
        at org.jruby.internal.runtime.methods.MixedModeIRMethod.INTERPRET_METHOD(MixedModeIRMethod.java:144)
        at org.jruby.internal.runtime.methods.MixedModeIRMethod.call(MixedModeIRMethod.java:130)
        at org.jruby.runtime.callsite.CachingCallSite.cacheAndCall(CachingCallSite.java:328)
        at org.jruby.runtime.callsite.CachingCallSite.callBlock(CachingCallSite.java:141)
        at org.jruby.runtime.callsite.CachingCallSite.call(CachingCallSite.java:145)
        at org.jruby.RubyClass.newInstance(RubyClass.java:994)
        at org.jruby.RubyClass$INVOKER$i$newInstance.call(RubyClass$INVOKER$i$newInstance.gen)
        at org.jruby.internal.runtime.methods.DynamicMethod.call(DynamicMethod.java:192)
        at org.jruby.runtime.callsite.CachingCallSite.cacheAndCall(CachingCallSite.java:318)
        at org.jruby.runtime.callsite.CachingCallSite.call(CachingCallSite.java:131)
        at D_3a_.env.hbaseue_minus_shell.alihbase_minus_2_dot_0_dot_17.bin.$_dot_dot_.bin.hirb.invokeOther114:new(D:\env\hbaseue-shell\alihbase-2.0.17\bin\..\bin\hirb.rb:140)
        at D_3a_.env.hbaseue_minus_shell.alihbase_minus_2_dot_0_dot_17.bin.$_dot_dot_.bin.hirb.RUBY$script(D:\env\hbaseue-shell\alihbase-2.0.17\bin\..\bin\hirb.rb:140)
        at java.lang.invoke.MethodHandle.invokeWithArguments(MethodHandle.java:627)
        at org.jruby.ir.Compiler$1.load(Compiler.java:95)
        at org.jruby.Ruby.runScript(Ruby.java:828)
        at org.jruby.Ruby.runNormally(Ruby.java:747)
        at org.jruby.Ruby.runNormally(Ruby.java:765)
        at org.jruby.Ruby.runFromMain(Ruby.java:578)
        at org.jruby.Main.doRunFromMain(Main.java:417)
        at org.jruby.Main.internalRun(Main.java:305)
        at org.jruby.Main.run(Main.java:232)
        at org.jruby.Main.main(Main.java:204)
2021-01-11 10:39:34,044 WARN  [main] util.NativeCodeLoader: Unable to load native-hadoop library for your platform... using builtin-java classes where applicable
HBase Shell
Use "help" to get list of supported commands.
Use "exit" to quit this interactive shell.
For Reference, please visit: http://hbase.apache.org/2.0/book.html#shell
Version 2.0.16, r9bcceba0a47f17b3260d2c219288cc0155dc8dd1, Tue Jun  9 16:11:55 CST 2020
[ERROR] Terminal initialization failed; falling back to unsupported
java.lang.NoClassDefFoundError: Could not initialize class org.fusesource.jansi.internal.Kernel32
        at org.fusesource.jansi.internal.WindowsSupport.getConsoleMode(WindowsSupport.java:50)
        at jline.WindowsTerminal.getConsoleMode(WindowsTerminal.java:177)
        at jline.WindowsTerminal.init(WindowsTerminal.java:80)
        at jline.TerminalFactory.create(TerminalFactory.java:101)
        at jline.TerminalFactory.get(TerminalFactory.java:159)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:498)
        at org.jruby.javasupport.JavaMethod.invokeDirectWithExceptionHandling(JavaMethod.java:438)
        at org.jruby.javasupport.JavaMethod.invokeStaticDirect(JavaMethod.java:360)
        at org.jruby.java.invokers.StaticMethodInvoker.call(StaticMethodInvoker.java:40)
        at org.jruby.runtime.callsite.CachingCallSite.cacheAndCall(CachingCallSite.java:318)
        at org.jruby.runtime.callsite.CachingCallSite.call(CachingCallSite.java:131)
        at org.jruby.ir.interpreter.InterpreterEngine.processCall(InterpreterEngine.java:339)
        at org.jruby.ir.interpreter.StartupInterpreterEngine.interpret(StartupInterpreterEngine.java:73)
        at org.jruby.ir.interpreter.InterpreterEngine.interpret(InterpreterEngine.java:77)
        at org.jruby.internal.runtime.methods.MixedModeIRMethod.INTERPRET_METHOD(MixedModeIRMethod.java:144)
        at org.jruby.internal.runtime.methods.MixedModeIRMethod.call(MixedModeIRMethod.java:130)
        at org.jruby.internal.runtime.methods.DynamicMethod.call(DynamicMethod.java:192)
        at org.jruby.runtime.callsite.CachingCallSite.cacheAndCall(CachingCallSite.java:318)
        at org.jruby.runtime.callsite.CachingCallSite.call(CachingCallSite.java:131)
        at org.jruby.ir.interpreter.InterpreterEngine.processCall(InterpreterEngine.java:339)
        at org.jruby.ir.interpreter.StartupInterpreterEngine.interpret(StartupInterpreterEngine.java:73)
        at org.jruby.ir.interpreter.InterpreterEngine.interpret(InterpreterEngine.java:77)
        at org.jruby.internal.runtime.methods.MixedModeIRMethod.INTERPRET_METHOD(MixedModeIRMethod.java:144)
        at org.jruby.internal.runtime.methods.MixedModeIRMethod.call(MixedModeIRMethod.java:130)
        at org.jruby.runtime.callsite.CachingCallSite.cacheAndCall(CachingCallSite.java:328)
        at org.jruby.runtime.callsite.CachingCallSite.callBlock(CachingCallSite.java:141)
        at org.jruby.runtime.callsite.CachingCallSite.call(CachingCallSite.java:145)
        at org.jruby.RubyClass.newInstance(RubyClass.java:994)
        at org.jruby.RubyClass$INVOKER$i$newInstance.call(RubyClass$INVOKER$i$newInstance.gen)
        at org.jruby.internal.runtime.methods.DynamicMethod.call(DynamicMethod.java:192)
        at org.jruby.runtime.callsite.CachingCallSite.cacheAndCall(CachingCallSite.java:318)
        at org.jruby.runtime.callsite.CachingCallSite.call(CachingCallSite.java:131)
        at org.jruby.ir.interpreter.InterpreterEngine.processCall(InterpreterEngine.java:339)
        at org.jruby.ir.interpreter.StartupInterpreterEngine.interpret(StartupInterpreterEngine.java:73)
        at org.jruby.ir.interpreter.InterpreterEngine.interpret(InterpreterEngine.java:77)
        at org.jruby.internal.runtime.methods.MixedModeIRMethod.INTERPRET_METHOD(MixedModeIRMethod.java:144)
        at org.jruby.internal.runtime.methods.MixedModeIRMethod.call(MixedModeIRMethod.java:130)
        at org.jruby.internal.runtime.methods.DynamicMethod.call(DynamicMethod.java:192)
        at org.jruby.runtime.callsite.CachingCallSite.cacheAndCall(CachingCallSite.java:318)
        at org.jruby.runtime.callsite.CachingCallSite.call(CachingCallSite.java:131)
        at org.jruby.ir.interpreter.InterpreterEngine.processCall(InterpreterEngine.java:339)
        at org.jruby.ir.interpreter.StartupInterpreterEngine.interpret(StartupInterpreterEngine.java:73)
        at org.jruby.internal.runtime.methods.MixedModeIRMethod.INTERPRET_METHOD(MixedModeIRMethod.java:109)
        at org.jruby.internal.runtime.methods.MixedModeIRMethod.call(MixedModeIRMethod.java:95)
        at org.jruby.runtime.callsite.CachingCallSite.cacheAndCall(CachingCallSite.java:298)
        at org.jruby.runtime.callsite.CachingCallSite.callBlock(CachingCallSite.java:79)
        at org.jruby.runtime.callsite.CachingCallSite.call(CachingCallSite.java:83)
        at org.jruby.ir.instructions.CallBase.interpret(CallBase.java:428)
        at org.jruby.ir.interpreter.InterpreterEngine.processCall(InterpreterEngine.java:355)
        at org.jruby.ir.interpreter.StartupInterpreterEngine.interpret(StartupInterpreterEngine.java:73)
        at org.jruby.internal.runtime.methods.MixedModeIRMethod.INTERPRET_METHOD(MixedModeIRMethod.java:109)
        at org.jruby.internal.runtime.methods.MixedModeIRMethod.call(MixedModeIRMethod.java:95)
        at org.jruby.runtime.callsite.CachingCallSite.cacheAndCall(CachingCallSite.java:298)
        at org.jruby.runtime.callsite.CachingCallSite.callBlock(CachingCallSite.java:79)
        at org.jruby.runtime.callsite.CachingCallSite.call(CachingCallSite.java:83)
        at org.jruby.ir.instructions.CallBase.interpret(CallBase.java:428)
        at org.jruby.ir.interpreter.InterpreterEngine.processCall(InterpreterEngine.java:355)
        at org.jruby.ir.interpreter.StartupInterpreterEngine.interpret(StartupInterpreterEngine.java:73)
        at org.jruby.ir.interpreter.InterpreterEngine.interpret(InterpreterEngine.java:83)
        at org.jruby.internal.runtime.methods.MixedModeIRMethod.INTERPRET_METHOD(MixedModeIRMethod.java:179)
        at org.jruby.internal.runtime.methods.MixedModeIRMethod.call(MixedModeIRMethod.java:165)
        at org.jruby.internal.runtime.methods.DynamicMethod.call(DynamicMethod.java:200)
        at org.jruby.runtime.callsite.CachingCallSite.cacheAndCall(CachingCallSite.java:338)
        at org.jruby.runtime.callsite.CachingCallSite.call(CachingCallSite.java:163)
        at org.jruby.ir.interpreter.InterpreterEngine.processCall(InterpreterEngine.java:314)
        at org.jruby.ir.interpreter.StartupInterpreterEngine.interpret(StartupInterpreterEngine.java:73)
        at org.jruby.ir.interpreter.InterpreterEngine.interpret(InterpreterEngine.java:77)
        at org.jruby.internal.runtime.methods.MixedModeIRMethod.INTERPRET_METHOD(MixedModeIRMethod.java:144)
        at org.jruby.internal.runtime.methods.MixedModeIRMethod.call(MixedModeIRMethod.java:130)
        at org.jruby.internal.runtime.methods.DynamicMethod.call(DynamicMethod.java:192)
        at org.jruby.runtime.callsite.CachingCallSite.cacheAndCall(CachingCallSite.java:318)
        at org.jruby.runtime.callsite.CachingCallSite.call(CachingCallSite.java:131)
        at D_3a_.env.hbaseue_minus_shell.alihbase_minus_2_dot_0_dot_17.bin.$_dot_dot_.bin.hirb.invokeOther172:print_banner(D:\env\hbaseue-shell\alihbase-2.0.17\bin\..\bin\hirb.rb:190)
        at D_3a_.env.hbaseue_minus_shell.alihbase_minus_2_dot_0_dot_17.bin.$_dot_dot_.bin.hirb.RUBY$script(D:\env\hbaseue-shell\alihbase-2.0.17\bin\..\bin\hirb.rb:190)
        at java.lang.invoke.MethodHandle.invokeWithArguments(MethodHandle.java:627)
        at org.jruby.ir.Compiler$1.load(Compiler.java:95)
        at org.jruby.Ruby.runScript(Ruby.java:828)
        at org.jruby.Ruby.runNormally(Ruby.java:747)
        at org.jruby.Ruby.runNormally(Ruby.java:765)
        at org.jruby.Ruby.runFromMain(Ruby.java:578)
        at org.jruby.Main.doRunFromMain(Main.java:417)
        at org.jruby.Main.internalRun(Main.java:305)
        at org.jruby.Main.run(Main.java:232)
        at org.jruby.Main.main(Main.java:204)

报错是因为缺少jansi-1.4.jar包导致的,下载jansi-1.4.jar包放到hbase-xx\lib下,下载地址:https://mvnrepository.com/artifact/org.fusesource.jansi/jansi/1.4

常用命令

# 查看表列信息
describe 'table_name'
----------------------
COLUMN FAMILIES DESCRIPTION                                                                                             
{NAME => 'column_family_name', VERSIONS => '1' ...

# 从上面可得, NAME即column family, 列族. HBase修改压缩格式, 需要一个列族一个列族的修改, 注意大小写, 不要弄错了
NAME => 'column_family_name'
# 列出名字空间
list_namespace

# 查看default名字空间下的表
list_namespace_tables 'default'

# 查看指定名称空间下面的表
desc 'namespace:table_name'
describe 'table_name'

# 操作生效
major_compact 'table_name'

# 开启
enable 'table_name'

# 清空表数据
# 其内部实现是将指定的表下线、删除、重建,并且Region分区与旧表保留一致
truncate_preserve 'table_name'

# 删除索引表
offline_index 'idx_table_name', 'table_name'
remove_index 'idx_table_name', 'table_name'

压缩算法参考

image.png

表开启压缩, 释放空间, 极限利用(五步走)

# 首先观察表是否已经开启压缩, 列簇属性COMPRESSION是否为NONE, 如果是, 说明还未开启压缩
# 禁用表
disable 'table_name'
# 提交变更
alter 'table_name', {NAME => 'column_family_name', COMPRESSION => 'ZSTD', DATA_BLOCK_ENCODING =>'DIFF', TTL=>'86400'}
# 启用表
enable 'table_name'
# 对表进行major_compact操作, 使压缩生效
major_compact 'table_name'

日常实操

HBase锁盘解决

# 找阿里云解锁
# 下线并删除超大表的索引表
# 如果有索引表得先删除索引, 再清空表
offline_index 'idx_table_name', 'table_name'
remove_index 'idx_table_name', 'table_name'
# 清空主表数据
truncate_preserve 'table_name'
# 操作生效
major_compact 'table_name'

Linux环境下, HBase Shell

wget https://hbaseuepublic.oss-cn-beijing.aliyuncs.com/hbaseue-shell.tar.gz?spm=5176.connect.0.0.7ecc4fa43z5ScL&file=hbaseue-shell.tar.gz

mv hbaseue-shell.tar.gz\?spm\=5176.connect.0.0.7ecc4fa43z5ScL hbaseue-shell.tar.gz

tar -xzvf hbaseue-shell.tar.gz

rm -f hbaseue-shell.tar.gz

# 修改链接地址、连接用户名、连接密码
vi alihbase-2.0.18/conf/hbase-site.xml

# 连接hbase
./alihbase-2.0.18/bin/hbase shell

# 查询某表某列数据
get 'tableName', 'RowKey'

# 查询以指定开头的rowkey数据
scan 'stu',{ROWPREFIXFILTER => 'c1'}

# 模糊查询
scan 'scan_records',{COLUMNS => 'f:name', TIMERANGE => [1625052620, 9625552620]}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

凌 烨

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值