HBase的安装与使用

HBase的安装:

安装环境:
有三台虚拟机,并且已经将Hadoop环境和Zookeeper环境搭建好。
HBase的下载:
官网:
https://hbase.apache.org/
下载地址:
http://archive.apache.org/dist/hbase/
安装部署:
(1)将安装包上传到服务器并解压

[liu@master software]$ tar -zxf hbase-0.98.24-hadoop2-bin.tar.gz -C /hone/liu/module/

(2)修改Hbase目录下conf/hbase-env.sh 文件

vim conf/hbase-env.sh
//添加下面两个配置
export JAVA_HOME=/liu/module/jdk1.8.0_144
export HBASE_MANAGES_ZK=false

(3)修改Hbase目录下conf/hbase-site.xml 文件

<configuration>
        <property>     
                <name>hbase.rootdir</name>     
                <value>hdfs://liu/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>master:2181,server1:2181,server2:2181</value>
        </property>
        <property>   
              	<name>hbase.zookeeper.property.dataDir</name>
            	<value>/home/liu/zkdata</value>
        </property>
        <property>
    			<name>hbase.coprocessor.region.classes</name>
    			<value>com.demo.consumer.CalleeWriteObserver</value>
        </property>
</configuration>

(4)修改Hbase目录下conf/regionservers 文件

//三台主机名
master
server1
server2

(5)软连接hadoop配置文件到hbase

[liu@master module]$ ln -s /liu/module/hadoop-2.7.2/etc/hadoop/core-site.xml 
/liu/module/hbase/conf/core-site.xml

[liu@master module]$ ln -s /liu/module/hadoop-2.7.2/etc/hadoop/hdfs-site.xml 
/liu/module/hbase/conf/hdfs-site.xml

(6)将HBase远程发送到另外两台从机

[liu@master modules]$ scp -r hbase-1.3.1/ liu@server1:/home/liu/modules/
[liu@master modules]$ scp -r hbase-1.3.1/ liu@server2:/home/liu/modules/

HBase的使用

1.开启/关闭HBase服务

[liu@master hbase]$ bin/start-hbase.sh
[liu@master hbase]$ bin/stop-hbase.sh

2.HBase Shell操作

//进入HBase客户端命令行
[liu@master hbase]$ bin/hbase shell
命令 描述 语法
help 查看帮助命令 help ‘命令名’
whoami 我是谁 whoami
version 返回hbase版本信息 version
status 返回hbase集群的状态信息 status
table_help 查看如何操作表 table_help
create 创建表 create ‘表名’, ‘列族名1’, ‘列族名2’, ‘列族名N’
alter 修改列族 (1)添加一个列族:alter ‘表名’, ‘列族名’(2)删除列族:alter ‘表名’, {NAME=> ‘列族名’, METHOD=> ‘delete’}
describe 显示表相关的详细信息 describe ‘表名’
list 列出hbase中存在的所有表 list
exists 测试表是否存在 exists ‘表名’
put 添加或修改的表的值 put ‘表名’, ‘行键’, ‘列族名’, ‘列值’put ‘表名’, ‘行键’, ‘列族名:列名’, ‘列值’
scan 通过对表的扫描来获取对用的值 scan ‘表名’ (1)扫描某个列族: scan ‘表名’, {COLUMN=>‘列族名’}(2)扫描某个列族的某个列: scan ‘表名’, {COLUMN=>‘列族名:列名’} (3) 查询同一个列族的多个列: scan ‘表名’, {COLUMNS => [ ‘列族名1:列名1’, ‘列族名1:列名2’, …]}
get 获取行或单元(cell)的值 get ‘表名’, ‘行键’ get ‘表名’, ‘行键’, ‘列族名’
count 统计表中行的数量 count ‘表名’
incr 增加指定表行或列的值 incr ‘表名’, ‘行键’, ‘列族:列名’, 步长值
get_counter 获取计数器 get_counter ‘表名’, ‘行键’, ‘列族:列名’
delete 删除指定对象的值(可以为表,行,列对应的值,另外也可以指定时间戳的值) 删除列族的某个列: delete ‘表名’, ‘行键’, ‘列族名:列名’
deleteall 删除指定行的所有元素值 deleteall ‘表名’, ‘行键’
truncate 重新创建指定表 truncate ‘表名’
enable 使表有效 enable ‘表名’
is_enabled 是否启用 is_enabled ‘表名’
disable 使表无效 disable ‘表名’
is_disabled 是否无效 is_disabled ‘表名’
drop 删除表 drop的表必须是disable的 disable ‘表名’ drop ‘表名’
shutdown 关闭hbase集群(与exit不同) shutdown
tools 列出hbase所支持的工具 tools
exit 退出hbase shell exit
发布了13 篇原创文章 · 获赞 14 · 访问量 657

猜你喜欢

转载自blog.csdn.net/LCY_1013/article/details/104705171