要搭建Hbase集群模式必须先安装zookeeper.
参考:基础篇-Zookeeper
本文主要从以下方面展开。
下载 (略)
解压 (略)
配置
启停
基本操作
一、配置
0、环境变量
export ZK_HOME=/opt/liupuxiang/install/zookeeper-3.4.12export HADOOP_HOME=/opt/liupuxiang/install/hadoop-2.7.6/export HBASE_HOME=/opt/liupuxiang/install/hbase-2.0.1export PATH=$PATH:$ZK_HOME/bin:$HADOOP_HOME/bin:$HADOOP_HOME/sbin:$HBASE_HOME/bin
1、修改hbase-env.sh
//指定JDKexport JAVA_HOME=/mnt/software/jdk1.8.0_161//告诉hbase使用外部的zkexport HBASE_MANAGES_ZK=false
2、修改hbase-site.xml
<configuration> <property> <name>hbase.rootdirname> <value>hdfs://ns1/hbasevalue> property> <property> <name>hbase.cluster.distributedname> <value>truevalue> property> <property> <name>hbase.zookeeper.quorumname> <value>hadoop1:2181,hadoop2:2181,hadoop3:2181value> property> configuration>
注意:hbase.zookeeper.quorum 的value可带端口,也可不带,官方文档示例上不带,各种博客上几乎都带,本人2种情况实验都行。
3、regionservers文件,添加regionserver节点
#vim regionservershadoop1hadoop2hadoop3
4、将配置好的HBase配置文件从hadop1复制到每一个节点。
scp hbase-site.xml root@hadoop2:/opt/liupuxiang/install/hbase-2.0.1/conf/scp hbase-site.xml root@hadoop3:/opt/liupuxiang/install/hbase-2.0.1/conf/scp hbase-env.sh root@hadoop2:/opt/liupuxiang/install/hbase-2.0.1/conf/scp hbase-env.sh root@hadoop3:/opt/liupuxiang/install/hbase-2.0.1/conf/scp regionservers root@hadoop2:/opt/liupuxiang/install/hbase-2.0.1/conf/scp regionservers root@hadoop3:/opt/liupuxiang/install/hbase-2.0.1/conf/
二、启停
1、在hadoop3执行启动命令
启动
start-hbase.sh
停止
stop-hbase.sh
注意:在哪个节点上启动即执行start-hbase.sh 命令,哪个节点就作为Hmaster,同样,只能在Hmaster节点上执行 stop-hbase.sh 命令。
2、验证
1、jps 查看hbase进程
hadoop1
hadoop2
hadoop3
2、UI访问查看
三、基本操作
1、Connect to HBase.
$ ./bin/hbase shellhbase(main):001:0>
2、Display HBase Shell Help Text.
hbase(main):001:0> helpHBase Shell, version 2.0.1, r987f7b6d37c2fcacc942cc66e5c5122aba8fdfbe, Wed Jun 13 12:03:55 PDT 2018Type '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, 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 Group name: dml Commands: append, count, delete, deleteall, get, get_counter, get_splits, incr, put, scan, truncate, truncate_preserve Group name: tools Commands: assign, balance_switch, balancer, balancer_enabled, catalogjanitor_enabled, catalogjanitor_run, catalogjanitor_switch, cleaner_chore_enabled, cleaner_chore_run, cleaner_chore_switch, clear_block_cache, clear_compaction_queues, clear_deadservers, close_region, compact, compact_rs, compaction_state, flush, is_in_maintenance_mode, list_deadservers, major_compact, merge_region, move, normalize, normalizer_enabled, normalizer_switch, split, splitormerge_enabled, splitormerge_switch, trace, unassign, wal_roll, zk_dump Group name: replication Commands: add_peer, append_peer_namespaces, 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_namespaces, remove_peer_tableCFs, set_peer_bandwidth, set_peer_exclude_namespaces, set_peer_exclude_tableCFs, set_peer_namespaces, set_peer_replicate_all, set_peer_tableCFs, show_peer_tableCFs, update_peer_config Group name: snapshots Commands: clone_snapshot, delete_all_snapshot, delete_snapshot, delete_table_snapshots, list_snapshots, list_table_snapshots, restore_snapshot, snapshot Group name: configuration Commands: update_all_config, update_config Group name: quotas Commands: list_quota_snapshots, list_quota_table_sizes, list_quotas, list_snapshot_sizes, set_quota Group name: security Commands: grant, list_security_capabilities, revoke, user_permission Group name: procedures Commands: abort_procedure, list_locks, list_procedures Group name: visibility labels Commands: add_labels, clear_auths, get_auths, list_labels, set_auths, set_visibility Group name: rsgroup Commands: add_rsgroup, balance_rsgroup, get_rsgroup, get_server_rsgroup, get_table_rsgroup, list_rsgroups, move_namespaces_rsgroup, move_servers_namespaces_rsgroup, move_servers_rsgroup, move_servers_tables_rsgroup, move_tables_rsgroup, remove_rsgroup, remove_servers_rsgroup
3、Create a table.
Use the create
command to create a new table. You must specify the table name and the ColumnFamily name.
hbase(main):001:0> create 'test', 'cf'0 row(s) in 0.4170 seconds=> Hbase::Table - test
4、List Information About your Table
Use the list
command to confirm your table exists
hbase(main):002:0> list 'test'TABLEtest1 row(s) in 0.0180 seconds=> ["test"]
Now use the describe
command to see details, including configuration defaults
hbase(main):003:0> describe 'test'Table test is ENABLEDtestCOLUMN FAMILIES DESCRIPTION{NAME => 'cf', VERSIONS => '1', EVICT_BLOCKS_ON_CLOSE => 'false', NEW_VERSION_BEHAVIOR => 'false', KEEP_DELETED_CELLS => 'FALSE', CACHE_DATA_ON_WRITE =>'false', DATA_BLOCK_ENCODING => 'NONE', TTL => 'FOREVER', MIN_VERSIONS => '0', REPLICATION_SCOPE => '0', BLOOMFILTER => 'ROW', CACHE_INDEX_ON_WRITE => 'false', IN_MEMORY => 'false', CACHE_BLOOMS_ON_WRITE => 'false',PREFETCH_BLOCKS_ON_OPEN => 'false', COMPRESSION => 'NONE', BLOCKCACHE => 'true', BLOCKSIZE => '65536'}1 row(s)Took 0.9998 seconds
5、Put data into your table.
To put data into your table, use the put
command.
hbase(main):003:0> put 'test', 'row1', 'cf:a', 'value1'0 row(s) in 0.0850 secondshbase(main):004:0> put 'test', 'row2', 'cf:b', 'value2'0 row(s) in 0.0110 secondshbase(main):005:0> put 'test', 'row3', 'cf:c', 'value3'0 row(s) in 0.0100 seconds
Here, we insert three values, one at a time. The first insert is at row1
, column cf:a
, with a value of value1
. Columns in HBase are comprised of a column family prefix, cf
in this example, followed by a colon and then a column qualifier suffix, a
in this case.
6、Scan the table for all data at once.
One of the ways to get data from HBase is to scan. Use the scan
command to scan the table for data. You can limit your scan, but for now, all data is fetched.
hbase(main):006:0> scan 'test'ROW COLUMN+CELL row1 column=cf:a, timestamp=1421762485768, value=value1 row2 column=cf:b, timestamp=1421762491785, value=value2 row3 column=cf:c, timestamp=1421762496210, value=value33 row(s) in 0.0230 seconds
7、Get a single row of data.
To get a single row of data at a time, use the get
command.
hbase(main):007:0> get 'test', 'row1'COLUMN CELL cf:a timestamp=1421762485768, value=value11 row(s) in 0.0350 seconds
8、Disable a table.
If you want to delete a table or change its settings, as well as in some other situations, you need to disable the table first, using the disable
command. You can re-enable it using the enable
command.
hbase(main):008:0> disable 'test'0 row(s) in 1.1820 secondshbase(main):009:0> enable 'test'0 row(s) in 0.1770 seconds
Disable the table again if you tested the enable
command above:
hbase(main):010:0> disable 'test'0 row(s) in 1.1820 seconds
9、Drop the table.
To drop (delete) a table, use the drop
command.
hbase(main):011:0> drop 'test'0 row(s) in 0.1370 seconds
10、Exit the HBase Shell.
To exit the HBase Shell and disconnect from your cluster, use the quit
command. HBase is still running in the background.