HBase基础知识(二):HBase集群部署、HBaseShell操作
2023-12-21 17:44:31
1. HBase安装部署
1.1 Zookeeper正常部署
首先保证Zookeeper集群的正常部署,并启动之:
创建集群启动脚本:
#!/bin/bash
case $1 in
"start"){
for i in hadoop100 hadoop101 hadoop102
do
echo----------zookeeper $i 启动------------
ssh $i "/opt/module/zookeeper-3.4.10/bin/zkServer.sh start"
done
};;
?
"stop"){
for i in hadoop100 hadoop101 hadoop102
do
echo----------zookeeper $i 停止------------
ssh $i "/opt/module/zookeeper-3.4.10/bin/zkServer.sh stop"
done
};;
?
"status"){
for i in hadoop100 hadoop101 hadoop102
do
echo----------zookeeper $i 状态------------
ssh $i "/opt/module/zookeeper-3.4.10/bin/zkServer.sh status"
done
};;
esac
1.2 Hadoop正常部署
Hadoop集群的正常部署并启动:
sbin/start-dfs.sh
sbin/start-yarn.sh
1.3 HBase的解压
解压Hbase到指定目录:
tar -zxvf hbase-1.3.1-bin.tar.gz -C /opt/module
1.4 HBase的配置文件
修改HBase对应的配置文件。
1)hbase-env.sh修改内容:
先获取自己环境的java信息
echo $JAVA_HOME
/opt/module/jdk1.8.0_161
注释下面的信息:
修改一下信息:
export JAVA_HOME=/opt/module/jdk1.8.0_161
export HBASE_MANAGES_ZK=false
2)hbase-site.xml修改内容:
<?xmlversion="1.0"?>
<configuration>
<property>
? ?<name>hbase.rootdir</name>
? ?<value>hdfs://hadoop100:8020/HBase</value>
</property>
? ?
<property>
? ?<name>hbase.cluster.distributed</name>
? ?<value>true</value>
</property>
<!--0.98后的新变动,之前版本没有.port,默认端口为60000-->
<property>
? ?<name>hbase.master.port</name>
? ?<value>16000</value>
</property>
<property>
? ?<name>hbase.zookeeper.quorum</name>
? ?<value>hadoop100,hadoop101,hadoop102</value>
</property>
<property>
? ?<name>hbase.zookeeper.property.dataDir</name>
? ?<value>/opt/module/zookeeper-3.4.10/zkData</value>
</property>
</configuration>
3)regionservers:
hadoop100
hadoop101
hadoop102
4)软连接hadoop配置文件到HBase:
ln -s /opt/module/hadoop-3.1.3/etc/hadoop/core-site.xml/opt/module/hbase-1.3.1/conf/core-site.xml
ln -s /opt/module/hadoop-3.1.3/etc/hadoop/hdfs-site.xml/opt/module/hbase-1.3.1/conf/hdfs-site.xml
可以看到两个文件都做好了引用:
1.5 HBase远程发送到其他集群
xsync.sh hbase-1.3.1
1.6 HBase服务的启动
1.启动方式
bin/hbase-daemon.sh start master
startingmaster,loggingto/opt/module/hbase-1.3.1/bin/../logs/hbase-atguigu-master-hadoop100.out
bin/hbase-daemon.sh start regionserver
startingregionserver,loggingto/opt/module/hbase-1.3.1/bin/../logs/hbase-atguigu-regionserver-hadoop100.out
提示:如果集群之间的节点时间不同步,会导致regionserver无法启动,抛出ClockOutOfSyncException异常。修复提示:
a、同步时间服务请参看帮助文档:《尚硅谷大数据技术之Hadoop入门》
b、属性:hbase.master.maxclockskew设置更大的值
<property>
? ?<name>hbase.master.maxclockskew</name>
? ?<value>180000</value>
? ?<description>Timedifferenceofregionserverfrommaster</description>
</property>
2.启动方式
bin/start-hbase.sh
可以看到输出:
startingmaster,loggingto/opt/module/hbase-1.3.1/bin/../logs/hbase-atguigu-master-hadoop100.out
hadoop101:startingregionserver,loggingto/opt/module/hbase-1.3.1/bin/../logs/hbase-atguigu-regionserver-hadoop101.out
hadoop102:startingregionserver,loggingto/opt/module/hbase-1.3.1/bin/../logs/hbase-atguigu-regionserver-hadoop102.out
hadoop100:startingregionserver,loggingto/opt/module/hbase-1.3.1/bin/../logs/hbase-atguigu-regionserver-hadoop100.out
对应的停止服务:
bin/stop-hbase.sh
2.?HBaseShell操作
2.1 基本操作
1.进入HBase客户端命令行
bin/hbaseshell
2.查看帮助命令
hbase(main):001:0>help
HBaseShell,version1.3.1,r930b9a55528fe45d8edce7af42fef2d35e77677a,ThuApr619:36:54PDT2017
Type'help"COMMAND"',(e.g.'help"get"'--thequotesarenecessary)forhelponaspecificcommand.
Commandsaregrouped.Type'help"COMMAND_GROUP"',(e.g.'help"general"')forhelponacommandgroup.
?
COMMANDGROUPS:
Groupname:general
Commands:status,table_help,version,whoami
?
#Groupname:ddl
#Commands:alter,alter_async,alter_status,create,describe,disable,disable_all,drop,drop_all,enable,enable_all,exists,get_table,is_disabled,is_enabled,list,locate_region,show_filters
?
Groupname:namespace
Commands:alter_namespace,create_namespace,describe_namespace,drop_namespace,list_namespace,list_namespace_tables
?
#Groupname:dml
#Commands:append,count,delete,deleteall,get,get_counter,get_splits,incr,put,scan,truncate,truncate_preserve
?
Groupname:tools
Commands:assign,balance_switch,balancer,balancer_enabled,catalogjanitor_enabled,catalogjanitor_run,catalogjanitor_switch,close_region,compact,compact_rs,flush,major_compact,merge_region,move,normalize,normalizer_enabled,normalizer_switch,split,splitormerge_enabled,splitormerge_switch,trace,unassign,wal_roll,zk_dump
?
Groupname:replication
Commands:add_peer,append_peer_tableCFs,disable_peer,disable_table_replication,enable_peer,enable_table_replication,get_peer_config,list_peer_configs,list_peers,list_replicated_tables,remove_peer,remove_peer_tableCFs,set_peer_tableCFs,show_peer_tableCFs
?
Groupname:snapshots
Commands:clone_snapshot,delete_all_snapshot,delete_snapshot,delete_table_snapshots,list_snapshots,list_table_snapshots,restore_snapshot,snapshot
?
Groupname:configuration
Commands:update_all_config,update_config
?
Groupname:quotas
Commands:list_quotas,set_quota
?
Groupname:security
Commands:grant,list_security_capabilities,revoke,user_permission
?
Groupname:procedures
Commands:abort_procedure,list_procedures
?
Groupname:visibilitylabels
Commands:add_labels,clear_auths,get_auths,list_labels,set_auths,set_visibility
?
SHELLUSAGE:
QuoteallnamesinHBaseShellsuchastableandcolumnnames.Commasdelimit
commandparameters.Type<RETURN>afterenteringacommandtorunit.
Dictionariesofconfigurationusedinthecreationandalterationoftablesare
RubyHashes.Theylooklikethis:
?
{'key1'=>'value1','key2'=>'value2',...}
?
andareopenedandclosedwithcurley-braces.Key/valuesaredelimitedbythe
'=>'charactercombination.Usuallykeysarepredefinedconstantssuchas
NAME,VERSIONS,COMPRESSION,etc.Constantsdonotneedtobequoted.Type
'Object.constants'toseea(messy)listofallconstantsintheenvironment.
?
Ifyouareusingbinarykeysorvaluesandneedtoenterthemintheshell,use
double-quote'dhexadecimalrepresentation.Forexample:
?
hbase>get't1',"key\x03\x3f\xcd"
hbase>get't1',"key\003\023\011"
hbase>put't1',"test\xef\xff",'f1:',"\x01\x33\x40"
?
TheHBaseshellisthe(J)RubyIRBwiththeaboveHBase-specificcommandsadded.
FormoreontheHBaseShell,seehttp://hbase.apache.org/book.html
3.查看当前数据库中有哪些表
hbase(main):002:0>list
TABLE
0row(s)in0.6350seconds
?
=>[]
2.2 表的操作
1.创建表
hbase(main):003:0>create 'student','info'
0row(s)in2.4680seconds
?
=>Hbase::Table-student
hbase(main):004:0>create 'stu','info1','info2'
0row(s)in1.2800seconds
?
=>Hbase::Table-stu
hbase(main):005:0>list
TABLE
stu
student
2row(s)in0.0200seconds
?
=>["stu","student"]
2.插入数据到表
hbase(main):003:0>put 'student','1001','info:sex','male'
hbase(main):004:0>put 'student','1001','info:age','18'
hbase(main):005:0>put 'student','1002','info:name','Janna'
hbase(main):006:0>put 'student','1002','info:sex','female'
hbase(main):007:0>put 'student','1002','info:age','20'
3.扫描查看表数据
hbase(main):008:0>scan 'student'
hbase(main):009:0>scan 'student',{STARTROW=>'1001',STOPROW=>'1001'}
hbase(main):010:0>scan 'student',{STARTROW=>'1001'}
4.查看表结构
describe ‘student’
5.更新指定字段的数据
hbase(main):012:0>put 'student','1001','info:name','Nick'
hbase(main):013:0>put 'student','1001','info:age','100'
6.查看“指定行”或“指定列族:列”的数据
hbase(main):014:0>get 'student','1001'
hbase(main):015:0>get 'student','1001','info:name'
7.统计表数据行数
hbase(main):021:0>count 'student'
8.删除数据
删除某rowkey的全部数据:
hbase(main):016:0>deleteall 'student','1001'
删除某rowkey的某一列数据:
hbase(main):017:0>delete 'student','1002','info:sex'
9.清空表数据
hbase(main):018:0>truncate 'student'
提示:清空表的操作顺序为先disable,然后再truncate。
10.删除表
首先需要先让该表为disable状态:
hbase(main):019:0>disable 'student'
然后才能drop这个表:
hbase(main):020:0>drop 'student'
提示:如果直接drop表,会报错:ERROR:Tablestudentisenabled.Disableitfirst.
11.变更表信息
将info列族中的数据存放3个版本:
hbase(main):022:0>alter 'student',{NAME=>'info',VERSIONS=>3}
hbase(main):022:0>get 'student','1001',{COLUMN=>'info:name',VERSIONS=>3}
文章来源:https://blog.csdn.net/zuodingquan666/article/details/135133886
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。 如若内容造成侵权/违法违规/事实不符,请联系我的编程经验分享网邮箱:veading@qq.com进行投诉反馈,一经查实,立即删除!
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。 如若内容造成侵权/违法违规/事实不符,请联系我的编程经验分享网邮箱:veading@qq.com进行投诉反馈,一经查实,立即删除!