本文档风哥主要介绍HBase Shell命令操作实战,包括DDL操作、DML操作、管理操作等内容,风哥教程参考HBase官方文档Shell Commands、Data Model Operations等内容,适合大数据开发运维人员在学习和测试中使用,如果要应用于生产环境则需要自行确认。更多视频教程www.fgedu.net.cn
Part01-基础概念与理论知识
1.1 HBase Shell概述
HBase Shell是HBase提供的命令行交互工具,基于JRuby实现,用于管理和操作HBase数据库。学习交流加群风哥微信: itpux-com
- DDL操作:创建、修改、删除表
- DML操作:数据的增删改查
- 管理操作:集群管理、Region管理
- 安全操作:用户权限管理
- 快照操作:快照创建和恢复
1.2 命令分类
HBase Shell命令分类详解:
1. DDL命令
– create:创建表
– alter:修改表
– disable:禁用表
– enable:启用表
– drop:删除表
– describe:查看表结构
– list:列出表
2. DML命令
– put:插入数据
– get:获取数据
– scan:扫描数据
– delete:删除数据
– deleteall:删除整行
– count:统计行数
– append:追加数据
– increment:增量操作
3. 管理命令
– status:集群状态
– balance_switch:负载均衡开关
– balancer:触发负载均衡
– move:移动Region
– split:分裂Region
– merge:合并Region
– major_compact:主压缩
– flush:刷写MemStore
4. 安全命令
– grant:授权
– revoke:撤销权限
– user_permission:查看权限
5. 快照命令
– snapshot:创建快照
– list_snapshots:列出快照
– restore_snapshot:恢复快照
– clone_snapshot:克隆快照
– delete_snapshot:删除快照
1.3 语法规则
HBase Shell语法规则详解:
1. 命令格式
命令 ‘参数1’, ‘参数2’, {属性名 => ‘属性值’}
2. 字符串引号
– 单引号:’value’
– 双引号:”value”
– 推荐使用单引号
3. 列族定义
{NAME => ‘cf’, VERSIONS => 3, COMPRESSION => ‘SNAPPY’}
4. 多参数格式
‘table_name’, {NAME => ‘cf1’}, {NAME => ‘cf2’}
5. Ruby语法
# 变量定义
table_name = ‘fgedu_user’
create table_name, ‘cf1’, ‘cf2’
# 条件判断
if exists?(table_name)
disable table_name
drop table_name
end
# 启动HBase Shell
$ hbase shell
HBase Shell
Use “help” to get list of supported commands.
Use “exit” to quit this interactive shell.
Version 2.5.5, rUnknown, Mon Apr 8 13:00:00 CST 2026
hbase(main):001:0>
# 查看帮助
hbase(main):001:0> help
HBase Shell, version 2.5.5, rUnknown, Mon Apr 8 13:00:00 CST 2026
Type ‘help “COMMAND”‘, (e.g. ‘help “get”‘ — the quotes are necessary) for help on a specific command.
Commands are grouped. Type ‘help “COMMAND_GROUP”‘, (e.g. ‘help “general”‘) for help on a command group.
COMMAND GROUPS:
Group name: general
Commands: processlist, status, table_help, version, whoami
Group name: ddl
Commands: alter, alter_async, alter_status, clone_table_schema, create, describe, disable, disable_all, drop, drop_all, enable, enable_all, exists, get_table, is_disabled, is_enabled, list, list_regions, locate_region, show_filters
Group name: namespace
Commands: alter_namespace, create_namespace, describe_namespace, drop_namespace, list_namespace, list_namespace_tables
…
Part02-生产环境规划与建议
2.1 表设计规划
表设计规划建议:
1. 列族数量
– 建议:1-3个
– 原因:每个列族一个Store,影响性能
2. 列族名称
– 简短:info, data, cf
– 有意义:basic, detail, behavior
3. 版本数
– 默认:1
– 根据需求设置:VERSIONS => 3
4. 压缩
– 推荐:SNAPPY
– 高压缩比:GZIP
– 快速:LZ4
5. 预分区
– 根据RowKey设计
– 避免热点
# 表设计示例
create ‘fgedu_user’,
{NAME => ‘basic’, VERSIONS => 1, COMPRESSION => ‘SNAPPY’, BLOOMFILTER => ‘ROW’},
{NAME => ‘behavior’, VERSIONS => 3, COMPRESSION => ‘SNAPPY’, TTL => 2592000},
{NAME => ‘tag’, VERSIONS => 1, COMPRESSION => ‘SNAPPY’},
SPLITS => [‘10000000’, ‘20000000’, ‘30000000’, ‘40000000’, ‘50000000’]
2.2 RowKey设计规划
RowKey设计规划建议:
1. 唯一性
– 必须唯一标识一行数据
2. 长度
– 建议:10-100字节
– 最大:64KB
3. 散列性
– 避免热点
– 使用散列前缀
4. 有序性
– 支持范围查询
– 根据查询模式设计
# RowKey设计方案
1. 用户ID方案
RowKey: user_id
示例: user_00000001
2. 散列前缀方案
RowKey: MD5(user_id).substring(0,4) + user_id
示例: a1b2_user_00000001
3. 时间戳方案
RowKey: user_id + Long.MAX_VALUE – timestamp
示例: user_00000001_9223372036854775807
4. 组合键方案
RowKey: user_id + ‘_’ + item_id
示例: user_00000001_item_001
# RowKey设计示例
# 用户行为表
RowKey: MD5(user_id).substring(0,4) + ‘_’ + user_id + ‘_’ + timestamp
# 示例数据
a1b2_user_00000001_1680940800000
a1b2_user_00000001_1680940801000
c3d4_user_00000002_1680940800000
2.3 列族设计规划
列族设计规划建议:
1. 相关性
– 相关数据放在同一列族
2. 访问模式
– 经常一起访问的数据放同一列族
3. 数据类型
– 相同类型数据放同一列族
4. TTL
– 根据数据生命周期设置
# 列族属性配置
1. VERSIONS
– 版本数,默认1
– VERSIONS => 3
2. COMPRESSION
– 压缩算法
– COMPRESSION => ‘SNAPPY’
3. BLOOMFILTER
– 布隆过滤器
– BLOOMFILTER => ‘ROW’
4. TTL
– 数据存活时间(秒)
– TTL => 2592000 # 30天
5. BLOCKSIZE
– 块大小
– BLOCKSIZE => 65536 # 64KB
6. IN_MEMORY
– 是否常驻内存
– IN_MEMORY => true
# 列族设计示例
{NAME => ‘basic’, VERSIONS => 1, COMPRESSION => ‘SNAPPY’, BLOOMFILTER => ‘ROW’}
{NAME => ‘behavior’, VERSIONS => 3, COMPRESSION => ‘SNAPPY’, TTL => 2592000}
{NAME => ‘detail’, VERSIONS => 1, COMPRESSION => ‘GZIP’, BLOCKSIZE => 131072}
Part03-生产环境项目实施方案
3.1 DDL操作实战
3.1.1 创建表
$ hbase shell
# 创建简单表
hbase(main):001:0> create ‘fgedu_user’, ‘info’
Created table fgedu_user
# 创建多列族表
hbase(main):002:0> create ‘fgedu_order’, ‘basic’, ‘detail’, ‘status’
Created table fgedu_order
# 创建带属性的表
hbase(main):003:0> create ‘fgedu_product’,
{NAME => ‘basic’, VERSIONS => 3, COMPRESSION => ‘SNAPPY’, BLOOMFILTER => ‘ROW’},
{NAME => ‘price’, VERSIONS => 1, COMPRESSION => ‘SNAPPY’, TTL => 2592000}
Created table fgedu_product
# 创建预分区表
hbase(main):004:0> create ‘fgedu_behavior’, ‘info’,
SPLITS => [’10’, ’20’, ’30’, ’40’, ’50’, ’60’, ’70’, ’80’, ’90’]
Created table fgedu_behavior
# 使用分区文件创建
hbase(main):005:0> create ‘fgedu_log’, ‘data’, SPLITS_FILE => ‘/tmp/splits.txt’
Created table fgedu_log
# 查看表列表
hbase(main):006:0> list
TABLE
fgedu_behavior
fgedu_log
fgedu_order
fgedu_product
fgedu_user
5 row(s)
Took 0.1234 seconds.
=> [“fgedu_behavior”, “fgedu_log”, “fgedu_order”, “fgedu_product”, “fgedu_user”]
# 查看表结构
hbase(main):007:0> describe ‘fgedu_product’
Table fgedu_product is ENABLED
fgedu_product
COLUMN FAMILIES DESCRIPTION
{NAME => ‘basic’, BLOOMFILTER => ‘ROW’, VERSIONS => ‘3’, IN_MEMORY => ‘false’, KEEP_DELETED_CELLS => ‘FALSE’, DATA_BLOCK_ENCODING => ‘NONE’, TTL => ‘FOREVER’, COMPRESSION => ‘SNAPPY’, MIN_VERSIONS => ‘0’, BLOCKCACHE => ‘true’, BLOCKSIZE => ‘65536’, REPLICATION_SCOPE => ‘0’}
{NAME => ‘price’, BLOOMFILTER => ‘ROW’, VERSIONS => ‘1’, IN_MEMORY => ‘false’, KEEP_DELETED_CELLS => ‘FALSE’, DATA_BLOCK_ENCODING => ‘NONE’, TTL => ‘2592000’, COMPRESSION => ‘SNAPPY’, MIN_VERSIONS => ‘0’, BLOCKCACHE => ‘true’, BLOCKSIZE => ‘65536’, REPLICATION_SCOPE => ‘0’}
2 row(s)
Took 0.0123 seconds.
3.1.2 修改表
hbase(main):008:0> alter ‘fgedu_user’, ‘detail’
Updating all regions with the new schema…
1/1 regions updated.
Done.
Took 1.2345 seconds.
# 修改列族属性
hbase(main):009:0> alter ‘fgedu_user’, {NAME => ‘info’, VERSIONS => 5}
Updating all regions with the new schema…
1/1 regions updated.
Done.
Took 1.2345 seconds.
# 删除列族
hbase(main):010:0> alter ‘fgedu_user’, {NAME => ‘detail’, METHOD => ‘delete’}
Updating all regions with the new schema…
1/1 regions updated.
Done.
Took 1.2345 seconds.
# 修改表属性
hbase(main):011:0> alter ‘fgedu_user’, MAX_FILESIZE => ‘21474836480’
Updating all regions with the new schema…
1/1 regions updated.
Done.
Took 1.2345 seconds.
# 禁用表
hbase(main):012:0> disable ‘fgedu_user’
Took 0.5678 seconds.
# 启用表
hbase(main):013:0> enable ‘fgedu_user’
Took 0.7890 seconds.
# 检查表状态
hbase(main):014:0> is_enabled ‘fgedu_user’
true
Took 0.0123 seconds.
hbase(main):015:0> is_disabled ‘fgedu_user’
false
Took 0.0123 seconds.
# 删除表
hbase(main):016:0> disable ‘fgedu_test’
Took 0.5678 seconds.
hbase(main):017:0> drop ‘fgedu_test’
Took 0.7890 seconds.
# 检查表是否存在
hbase(main):018:0> exists ‘fgedu_user’
Table fgedu_user does exist
Took 0.0123 seconds.
3.2 DML操作实战
3.2.1 数据插入
hbase(main):019:0> put ‘fgedu_user’, ‘user_00000001’, ‘info:name’, ‘fgedu01’
Took 0.1234 seconds.
hbase(main):020:0> put ‘fgedu_user’, ‘user_00000001’, ‘info:age’, ’25’
Took 0.0123 seconds.
hbase(main):021:0> put ‘fgedu_user’, ‘user_00000001’, ‘info:city’, ‘北京’
Took 0.0123 seconds.
# 插入多版本数据
hbase(main):022:0> put ‘fgedu_user’, ‘user_00000001’, ‘info:name’, ‘fgedu01_new’, 1680940800000
Took 0.0123 seconds.
# 使用脚本批量插入
hbase(main):023:0> load ‘put_data.rb’
# put_data.rb内容
put ‘fgedu_user’, ‘user_00000002’, ‘info:name’, ‘fgedu02’
put ‘fgedu_user’, ‘user_00000002’, ‘info:age’, ’30’
put ‘fgedu_user’, ‘user_00000002’, ‘info:city’, ‘上海’
put ‘fgedu_user’, ‘user_00000003’, ‘info:name’, ‘fgedu03’
put ‘fgedu_user’, ‘user_00000003’, ‘info:age’, ’28’
put ‘fgedu_user’, ‘user_00000003’, ‘info:city’, ‘广州’
# 使用ImportTsv批量导入
$ hbase org.apache.hadoop.hbase.mapreduce.ImportTsv \
-Dimporttsv.separator=’,’ \
-Dimporttsv.columns=HBASE_ROW_KEY,info:name,info:age,info:city \
fgedu_user \
/data/user_import.csv
# 使用Bulk Load导入
$ hbase org.apache.hadoop.hbase.mapreduce.LoadIncrementalHFiles \
/output/hfiles \
fgedu_user
3.2.2 数据查询
hbase(main):024:0> get ‘fgedu_user’, ‘user_00000001’
COLUMN CELL
info:age timestamp=1680940800001, value=25
info:city timestamp=1680940800002, value=北京
info:name timestamp=1680940800000, value=fgedu01
1 row(s)
Took 0.0123 seconds.
# 获取指定列族
hbase(main):025:0> get ‘fgedu_user’, ‘user_00000001’, {COLUMN => ‘info’}
COLUMN CELL
info:age timestamp=1680940800001, value=25
info:city timestamp=1680940800002, value=北京
info:name timestamp=1680940800000, value=fgedu01
1 row(s)
Took 0.0123 seconds.
# 获取指定列
hbase(main):026:0> get ‘fgedu_user’, ‘user_00000001’, {COLUMN => ‘info:name’}
COLUMN CELL
info:name timestamp=1680940800000, value=fgedu01
1 row(s)
Took 0.0123 seconds.
# 获取多个版本
hbase(main):027:0> get ‘fgedu_user’, ‘user_00000001’, {COLUMN => ‘info:name’, VERSIONS => 3}
COLUMN CELL
info:name timestamp=1680940800000, value=fgedu01_new
info:name timestamp=1680940700000, value=fgedu01
2 row(s)
Took 0.0123 seconds.
# 获取指定时间范围
hbase(main):028:0> get ‘fgedu_user’, ‘user_00000001’, {TIMERANGE => [1680940700000, 1680940900000]}
COLUMN CELL
info:age timestamp=1680940800001, value=25
info:city timestamp=1680940800002, value=北京
info:name timestamp=1680940800000, value=fgedu01_new
1 row(s)
Took 0.0123 seconds.
# 扫描全表
hbase(main):029:0> scan ‘fgedu_user’
ROW COLUMN+CELL
user_00000001 column=info:age, timestamp=1680940800001, value=25
user_00000001 column=info:city, timestamp=1680940800002, value=北京
user_00000001 column=info:name, timestamp=1680940800000, value=fgedu01
user_00000002 column=info:age, timestamp=1680940800011, value=30
user_00000002 column=info:city, timestamp=1680940800012, value=上海
user_00000002 column=info:name, timestamp=1680940800010, value=fgedu02
user_00000003 column=info:age, timestamp=1680940800021, value=28
user_00000003 column=info:city, timestamp=1680940800022, value=广州
user_00000003 column=info:name, timestamp=1680940800020, value=fgedu03
3 row(s)
Took 0.0456 seconds.
# 范围扫描
hbase(main):030:0> scan ‘fgedu_user’, {STARTROW => ‘user_00000001’, STOPROW => ‘user_00000003’}
ROW COLUMN+CELL
user_00000001 column=info:age, timestamp=1680940800001, value=25
user_00000001 column=info:city, timestamp=1680940800002, value=北京
user_00000001 column=info:name, timestamp=1680940800000, value=fgedu01
user_00000002 column=info:age, timestamp=1680940800011, value=30
user_00000002 column=info:city, timestamp=1680940800012, value=上海
user_00000002 column=info:name, timestamp=1680940800010, value=fgedu02
2 row(s)
Took 0.0345 seconds.
# 限制返回行数
hbase(main):031:0> scan ‘fgedu_user’, {LIMIT => 2}
ROW COLUMN+CELL
user_00000001 column=info:age, timestamp=1680940800001, value=25
user_00000001 column=info:city, timestamp=1680940800002, value=北京
user_00000001 column=info:name, timestamp=1680940800000, value=fgedu01
user_00000002 column=info:age, timestamp=1680940800011, value=30
user_00000002 column=info:city, timestamp=1680940800012, value=上海
user_00000002 column=info:name, timestamp=1680940800010, value=fgedu02
2 row(s)
Took 0.0234 seconds.
# 过滤器查询
hbase(main):032:0> scan ‘fgedu_user’, {FILTER => “ValueFilter(=, ‘binary:25’)”}
ROW COLUMN+CELL
user_00000001 column=info:age, timestamp=1680940800001, value=25
1 row(s)
Took 0.0123 seconds.
# 统计行数
hbase(main):033:0> count ‘fgedu_user’
3 row(s)
Took 0.1234 seconds.
=> 3
3.2.3 数据删除
hbase(main):034:0> delete ‘fgedu_user’, ‘user_00000001’, ‘info:city’
Took 0.0123 seconds.
# 删除指定版本
hbase(main):035:0> delete ‘fgedu_user’, ‘user_00000001’, ‘info:name’, 1680940800000
Took 0.0123 seconds.
# 删除整行
hbase(main):036:0> deleteall ‘fgedu_user’, ‘user_00000003’
Took 0.0123 seconds.
# 删除指定列族
hbase(main):037:0> deleteall ‘fgedu_user’, ‘user_00000002’, ‘info’
Took 0.0123 seconds.
# 增量操作
hbase(main):038:0> increment ‘fgedu_user’, ‘user_00000001’, ‘info:login_count’, 1
COUNTER VALUE = 1
Took 0.0123 seconds.
# 追加操作
hbase(main):039:0> append ‘fgedu_user’, ‘user_00000001’, ‘info:tags’, ‘,vip’
CURRENT VALUE = vip,active,vip
Took 0.0123 seconds.
3.3 管理操作实战
hbase(main):040:0> status
active master: fgedu-node1:16000
1 backup masters
fgedu-node2:16000
3 live servers
fgedu-node3:16020
requestsPerSecond=10.0, numberOfOnlineRegions=10, usedHeapMB=1024, maxHeapMB=32768
fgedu-node4:16020
requestsPerSecond=8.0, numberOfOnlineRegions=10, usedHeapMB=1024, maxHeapMB=32768
fgedu-node5:16020
requestsPerSecond=12.0, numberOfOnlineRegions=10, usedHeapMB=1024, maxHeapMB=32768
0 dead servers
Master is fgedu-node1:16000
# 查看详细状态
hbase(main):041:0> status ‘detailed’
# 查看Region分布
hbase(main):042:0> list_regions ‘fgedu_user’
# 手动触发压缩
hbase(main):043:0> major_compact ‘fgedu_user’
Took 0.0123 seconds.
# 手动刷写MemStore
hbase(main):044:0> flush ‘fgedu_user’
Took 0.0123 seconds.
# 分裂Region
hbase(main):045:0> split ‘fgedu_user,,1680940800000.xxx’
Took 0.0123 seconds.
# 移动Region
hbase(main):046:0> move ‘region_encoded_name’, ‘fgedu-node3,16020,1680940800000’
Took 0.0123 seconds.
# 触发负载均衡
hbase(main):047:0> balancer
true
Took 0.0123 seconds.
# 开启/关闭负载均衡
hbase(main):048:0> balance_switch true
true
Took 0.0123 seconds.
# 创建快照
hbase(main):049:0> snapshot ‘fgedu_user’, ‘fgedu_user_snapshot_20260408’
Took 0.1234 seconds.
# 列出快照
hbase(main):050:0> list_snapshots
SNAPSHOT TABLE + CREATION TIME
fgedu_user_snapshot_20260408 fgedu_user (Mon Apr 08 13:00:00 +0800 2026)
1 row(s)
Took 0.0123 seconds.
# 恢复快照
hbase(main):051:0> disable ‘fgedu_user’
Took 0.5678 seconds.
hbase(main):052:0> restore_snapshot ‘fgedu_user_snapshot_20260408’
Took 0.7890 seconds.
hbase(main):053:0> enable ‘fgedu_user’
Took 0.5678 seconds.
# 删除快照
hbase(main):054:0> delete_snapshot ‘fgedu_user_snapshot_20260408’
Took 0.0123 seconds.
Part04-生产案例与实战讲解
4.1 用户表操作案例
# 1. 创建用户表
hbase(main):055:0> create ‘fgedu_user_profile’,
{NAME => ‘basic’, VERSIONS => 1, COMPRESSION => ‘SNAPPY’, BLOOMFILTER => ‘ROW’},
{NAME => ‘behavior’, VERSIONS => 3, COMPRESSION => ‘SNAPPY’, TTL => 2592000},
{NAME => ‘tag’, VERSIONS => 1, COMPRESSION => ‘SNAPPY’},
SPLITS => [‘10000000’, ‘20000000’, ‘30000000’, ‘40000000’, ‘50000000’, ‘60000000’, ‘70000000’, ‘80000000’, ‘90000000’]
Created table fgedu_user_profile
# 2. 插入用户数据
hbase(main):056:0> put ‘fgedu_user_profile’, ‘user_00000001’, ‘basic:name’, ‘fgedu01’
hbase(main):057:0> put ‘fgedu_user_profile’, ‘user_00000001’, ‘basic:age’, ’25’
hbase(main):058:0> put ‘fgedu_user_profile’, ‘user_00000001’, ‘basic:city’, ‘北京’
hbase(main):059:0> put ‘fgedu_user_profile’, ‘user_00000001’, ‘basic:phone’, ‘13800138001’
hbase(main):060:0> put ‘fgedu_user_profile’, ‘user_00000001’, ‘behavior:login_count’, ‘100’
hbase(main):061:0> put ‘fgedu_user_profile’, ‘user_00000001’, ‘behavior:buy_count’, ’10’
hbase(main):062:0> put ‘fgedu_user_profile’, ‘user_00000001’, ‘tag:level’, ‘VIP’
hbase(main):063:0> put ‘fgedu_user_profile’, ‘user_00000001’, ‘tag:interest’, ‘科技,旅游’
# 3. 查询用户数据
hbase(main):064:0> get ‘fgedu_user_profile’, ‘user_00000001’
COLUMN CELL
basic:age timestamp=1680940800001, value=25
basic:city timestamp=1680940800002, value=北京
basic:name timestamp=1680940800000, value=fgedu01
basic:phone timestamp=1680940800003, value=13800138001
behavior:buy_count timestamp=1680940800005, value=10
behavior:login_count timestamp=1680940800004, value=100
tag:interest timestamp=1680940800007, value=科技,旅游
tag:level timestamp=1680940800006, value=VIP
1 row(s)
# 4. 更新用户数据
hbase(main):065:0> put ‘fgedu_user_profile’, ‘user_00000001’, ‘basic:age’, ’26’
hbase(main):066:0> increment ‘fgedu_user_profile’, ‘user_00000001’, ‘behavior:login_count’, 1
# 5. 查看用户行为历史
hbase(main):067:0> get ‘fgedu_user_profile’, ‘user_00000001’, {COLUMN => ‘behavior’, VERSIONS => 3}
4.2 批量操作案例
# 创建批量插入脚本
$ cat > /tmp/batch_put.rb << 'EOF'
# batch_put.rb
# from:www.itpux.com.qq113257174.wx:itpux-com
# web: http://www.fgedu.net.cn
table = 'fgedu_user_profile'
(1..1000).each do |i|
user_id = format('user_%08d', i)
name = "fgedu#{format('%02d', i % 100)}"
age = (20 + rand(40)).to_s
cities = ['北京', '上海', '广州', '深圳', '杭州']
city = cities[rand(cities.length)]
put table, user_id, 'basic:name', name
put table, user_id, 'basic:age', age
put table, user_id, 'basic:city', city
end
puts "Batch insert completed!"
EOF
# 执行批量脚本
hbase(main):068:0> load ‘/tmp/batch_put.rb’
Batch insert completed!
# 使用ImportTsv导入数据
$ cat > /tmp/user_data.csv << 'EOF'
user_00001001,fgedu1001,25,北京
user_00001002,fgedu1002,30,上海
user_00001003,fgedu1003,28,广州
EOF
$ hbase org.apache.hadoop.hbase.mapreduce.ImportTsv \
-Dimporttsv.separator=',' \
-Dimporttsv.columns=HBASE_ROW_KEY,basic:name,basic:age,basic:city \
fgedu_user_profile \
/tmp/user_data.csv
# 导出数据
$ hbase org.apache.hadoop.hbase.mapreduce.Export \
fgedu_user_profile \
/output/fgedu_user_profile_export
4.3 常见问题处理
4.3.1 命令执行慢
# 排查步骤
# 1. 检查RegionServer状态
hbase(main):069:0> status ‘detailed’
# 2. 检查Region分布
hbase(main):070:0> list_regions ‘fgedu_user_profile’
# 解决方案
# 1. 触发压缩
hbase(main):071:0> major_compact ‘fgedu_user_profile’
# 2. 检查BlockCache
# Web UI -> RegionServer -> Memory
# 3. 优化查询
# 使用过滤器减少返回数据
hbase(main):072:0> scan ‘fgedu_user_profile’,
{FILTER => “PrefixFilter(‘user_00001’)”, LIMIT => 100}
4.3.2 表被锁定
# 排查步骤
# 1. 检查表状态
hbase(main):073:0> describe ‘fgedu_user_profile’
# 2. 检查Region状态
hbase(main):074:0> list_regions ‘fgedu_user_profile’
# 解决方案
# 1. 强制解锁
hbase(main):075:0> disable ‘fgedu_user_profile’
hbase(main):076:0> enable ‘fgedu_user_profile’
# 2. 检查是否有长时间运行的操作
# Web UI -> Procedures
Part05-风哥经验总结与分享
5.1 Shell最佳实践
HBase Shell最佳实践建议:
1. 使用脚本文件执行批量操作
2. 合理使用过滤器减少数据传输
3. 避免全表扫描
4. 定期执行压缩
5. 使用快照备份重要数据
5.2 操作建议
操作建议:
- 生产环境谨慎使用删除操作
- 大批量操作使用ImportTsv
- 定期创建快照备份
- 监控集群状态
5.3 工具推荐
HBase管理工具:
- HBase Shell:命令行工具
- HBase Web UI:Web管理界面
- Phoenix:SQL层
- Hue:Web界面
本文由风哥教程整理发布,仅用于学习测试使用,转载注明出处:http://www.fgedu.net.cn/10327.html
