环境版本: ·HDP 2.5.3 ·HBase 1.1.2HBase 提供了 REST API,为开发者增加了更多选择。

环境版本: ·HDP 2.5.3  ·HBase 1.1.2复制代码

HBase 提供了 REST API,为开发者增加了更多选择。我们可以使用 HBase REST API 对表进行增删改查,但本篇博客主要使用查询功能。 请注意 HBase 版本! 请注意 HBase 版本! 请注意 HBase 版本!

1 启动 HBase REST Server

[root@hqc-test-hdp3 ~]
2020-05-12 16:26:02,062 INFO  [main] util.VersionInfo: HBase 1.1.2.2.5.3.0-37
2020-05-12 16:26:02,064 INFO  [main] util.VersionInfo: Source code repository git://c66-slave-20176e25-10/grid/0/jenkins/workspace/HDP-parallel-centos6/SOURCES/hbase revision=cb8c969d1089f1a34e9df11b6eeb96e69bcf878d
2020-05-12 16:26:02,064 INFO  [main] util.VersionInfo: Compiled by jenkins on Tue Nov 29 18:48:22 UTC 2016


[root@hqc-test-hdp3 ~]
[root@hqc-test-hdp3 hbase]
bin  conf  doc  etc  hbase-webapps  include  lib  logs  man  pids
[root@hqc-test-hdp3 hbase]
[root@hqc-test-hdp3 bin]
draining_servers.rb   hbase             hbase.cmd        hbase-config.cmd  hbase-daemon.sh  hbase-jruby  region_mover.rb   replication               start-hbase.cmd  test
get-active-master.rb  hbase-cleanup.sh  hbase-common.sh  hbase-config.sh   hbase.distro     hirb.rb      region_status.rb  shutdown_regionserver.rb  stop-hbase.cmd   thread-pool.rb
[root@hqc-test-hdp3 bin]
starting rest, logging to /var/log/hbase/hbase-root-rest-hqc-test-hdp3.out```

更多内容请访问官网:
http://hbase.apache.org/book.html

101.1. Starting and Stopping the REST Server
The included REST server can run as a daemon which starts an embedded Jetty servlet container and deploys the servlet into it. Use one of the following commands to start the REST server in the foreground or background. The port is optional, and defaults to 8080.

 Foreground
$ bin/hbase rest start -p <port>

 Background, logging to a file in $HBASE_LOGS_DIR
$ bin/hbase-daemon.sh start rest -p <port>
To stop the REST server, use Ctrl-C if you were running it in the foreground, or the following command if you were running it in the background.

$ bin/hbase-daemon.sh stop rest复制代码

2 使用 rowkey 进行查询

http://hqc-test-hdp3:8888/表名/rowkey 

{
    "Row": [
        {
            "key": "MDAxMDcyOTg1MQ==",
            "Cell": [
                {
                    "column": "dmFsdWU6UkVW",
                    "timestamp": 1589268991882,
                    "$": "MzMzLjA="
                },
                ...
                {
                    "column": "dmFsdWU6VlQ4MDA4QQ==",
                    "timestamp": 1589268991882,
                    "$": "ODYuODMx"
                }
            ]
        }
    ]
}复制代码

2.1 查询单列指定时间段内的数据

http://hqc-test-hdp3:8888/表名/*/列簇名:列名/开始时间戳,结束时间戳


{
    "Row": [
        {
            "key": "MDExMDcyOTg1MQ==",
            "Cell": [
                {
                    "column": "dmFsdWU6VkkxOTAyWA==",
                    "timestamp": 1589269001868,
                    "$": "NC40OTY="
                }
            ]
        },
        {
            "key": "NTAxMDcyOTg1MQ==",
            "Cell": [
                {
                    "column": "dmFsdWU6VkkxOTAyWA==",
                    "timestamp": 1589268996879,
                    "$": "NC44NDU="
                }
            ]
        }
    ]
}复制代码

2.2 查询多列指定时间段内的数据

http://hqc-test-hdp3:8888/表名/*/列簇名:列名,列簇名:列名/开始时间戳,结束时间戳


{
    "Row": [
        {
            "key": "MDExMDcyOTg1MQ==",
            "Cell": [
                {
                    "column": "dmFsdWU6VkkxOTAyWA==",
                    "timestamp": 1589269001868,
                    "$": "NC40OTY="
                },
                {
                    "column": "dmFsdWU6VkkxOTAyWQ==",
                    "timestamp": 1589269001868,
                    "$": "My45MzQ="
                }
            ]
        },
        {
            "key": "NTAxMDcyOTg1MQ==",
            "Cell": [
                {
                    "column": "dmFsdWU6VkkxOTAyWA==",
                    "timestamp": 1589268996879,
                    "$": "NC44NDU="
                },
                {
                    "column": "dmFsdWU6VkkxOTAyWQ==",
                    "timestamp": 1589268996879,
                    "$": "NC4zMjE="
                }
            ]
        }
    ]
}复制代码