hbase rest api的使用

本文介绍了如何启动和停止HBase的REST Server,并通过REST API进行基本操作,如查看版本信息、集群状态、表数量和命名空间。通过示例展示了使用curl命令调用API的步骤。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

1.打开hbase的官网:

http://hbase.apache.org/

2.找到rest api的使用指南后,执行以下命令启动REST Server:

 bin/hbase rest start -p4444 #端口自己指定即可

关闭REST Server的命令:

 bin/hbase rest stop -p4444

启动成功以后使用jps命令查看进程:

会发现出现RESTSERVER的进程,此时说明RESTSERVER启动成功。

3.打开浏览器的web页面进行查看:


因为我的hbase中只有三张表,所以web界面直接就显示出来三张表

4.下面进行rest api的简使用:

1)/version/cluster 是查看版本信息:

curl -vi -X GET \
-H "Accept: text/xml" \
"http://192.168.179.160:4444/version/cluster"


2)/status/cluster 是查看集群状态:

curl -vi -X GET \
-H "Accept: text/xml" \
"http://192.168.179.160:4444/status/cluster"

3)/ 是查看当前有多少张表:

curl -vi -X GET \
-H "Accept: text/xml" \
"http://192.168.179.160:4444/"

4)/namespaces 是列出所有的namespaces:

curl -vi -X GET \
-H "Accept: text/xml" \
"http://192.168.179.160:4444/namespaces/"

由于rest api是在是太多,我在此处就简单列出几个的使用,其余的api在官网查找即可,使用是类似的。

Endpoint HTTP Verb Description Example

/version/cluster

GET

Version of HBase running on this cluster

curl -vi -X GET \
  -H "Accept: text/xml" \
  "http://example.com:8000/version/cluster"

/status/cluster

GET

Cluster status

curl -vi -X GET \
  -H "Accept: text/xml" \
  "http://example.com:8000/status/cluster"

/

GET

List of all non-system tables

curl -vi -X GET \
  -H "Accept: text/xml" \
  "http://example.com:8000/"
Table 12. Namespace Endpoints
Endpoint HTTP Verb Description Example

/namespaces

GET

List all namespaces

curl -vi -X GET \
  -H "Accept: text/xml" \
  "http://example.com:8000/namespaces/"

/namespaces/namespace

GET

Describe a specific namespace

curl -vi -X GET \
  -H "Accept: text/xml" \
  "http://example.com:8000/namespaces/special_ns"

/namespaces/namespace

POST

Create a new namespace

curl -vi -X POST \
  -H "Accept: text/xml" \
  "example.com:8000/namespaces/special_ns"

/namespaces/namespace/tables

GET

List all tables in a specific namespace

curl -vi -X GET \
  -H "Accept: text/xml" \
  "http://example.com:8000/namespaces/special_ns/tables"

/namespaces/namespace

PUT

Alter an existing namespace. Currently not used.

curl -vi -X PUT \
  -H "Accept: text/xml" \
  "http://example.com:8000/namespaces/special_ns

/namespaces/namespace

DELETE

Delete a namespace. The namespace must be empty.

curl -vi -X DELETE \
  -H "Accept: text/xml" \
  "example.com:8000/namespaces/special_ns"
Table 13. Table Endpoints
Endpoint HTTP Verb Description Example

/table/schema

GET

Describe the schema of the specified table.

curl -vi -X GET \
  -H "Accept: text/xml" \
  "http://example.com:8000/users/schema"

/table/schema

POST

Create a new table, or replace an existing table’s schema

curl -vi -X POST \
  -H "Accept: text/xml" \
  -H "Content-Type: text/xml" \
  -d '<?xml version="1.0" encoding="UTF-8"?><TableSchema name="users"><ColumnSchema name="cf" /></TableSchema>' \
  "http://example.com:8000/users/schema"

/table/schema

PUT

Update an existing table with the provided schema fragment

curl -vi -X PUT \
  -H "Accept: text/xml" \
  -H "Content-Type: text/xml" \
  -d '<?xml version="1.0" encoding="UTF-8"?><TableSchema name="users"><ColumnSchema name="cf" KEEP_DELETED_CELLS="true" /></TableSchema>' \
  "http://example.com:8000/users/schema"

/table/schema

DELETE

Delete the table. You must use the /table/schemaendpoint, not just /table/.

curl -vi -X DELETE \
  -H "Accept: text/xml" \
  "http://example.com:8000/users/schema"

/table/regions

GET

List the table regions

curl -vi -X GET \
  -H "Accept: text/xml" \
  "http://example.com:8000/users/regions
Table 14. Endpoints for Get Operations
Endpoint HTTP Verb Description Example

/table/row

GET

Get all columns of a single row. Values are Base-64 encoded. This requires the "Accept" request header with a type that can hold multiple columns (like xml, json or protobuf).

curl -vi -X GET \
  -H "Accept: text/xml" \
  "http://example.com:8000/users/row1"

/table/row/column:qualifier/timestamp

GET

Get the value of a single column. Values are Base-64 encoded.

curl -vi -X GET \
  -H "Accept: text/xml" \
  "http://example.com:8000/users/row1/cf:a/1458586888395"

/table/row/column:qualifier

GET

Get the value of a single column. Values are Base-64 encoded.

curl -vi -X GET \
  -H "Accept: text/xml" \
  "http://example.com:8000/users/row1/cf:a"

curl -vi -X GET \
  -H "Accept: text/xml" \
   "http://example.com:8000/users/row1/cf:a/"

/table/row/column:qualifier/?v=number_of_versions

GET

Multi-Get a specified number of versions of a given cell. Values are Base-64 encoded.

curl -vi -X GET \
  -H "Accept: text/xml" \
  "http://example.com:8000/users/row1/cf:a?v=2"
Table 15. Endpoints for Scan Operations
Endpoint HTTP Verb Description Example

/table/scanner/

PUT

Get a Scanner object. Required by all other Scan operations. Adjust the batch parameter to the number of rows the scan should return in a batch. See the next example for adding filters to your scanner. The scanner endpoint URL is returned as the Location in the HTTP response. The other examples in this table assume that the scanner endpoint is http://example.com:8000/users/scanner/145869072824375522207.

curl -vi -X PUT \
  -H "Accept: text/xml" \
  -H "Content-Type: text/xml" \
  -d '<Scanner batch="1"/>' \
  "http://example.com:8000/users/scanner/"

/table/scanner/

PUT

To supply filters to the Scanner object or configure the Scanner in any other way, you can create a text file and add your filter to the file. For example, to return only rows for which keys start with <codeph>u123</codeph> and use a batch size of 100, the filter file would look like this:

[source,xml] ---- <Scanner batch="100"> <filter> { "type": "PrefixFilter", "value": "u123" } </filter> </Scanner> ----

Pass the file to the -d argument of the curl request.

curl -vi -X PUT \
  -H "Accept: text/xml" \
  -H "Content-Type:text/xml" \
  -d @filter.txt \
  "http://example.com:8000/users/scanner/"

/table/scanner/scanner-id

GET

Get the next batch from the scanner. Cell values are byte-encoded. If the scanner has been exhausted, HTTP status 204 is returned.

curl -vi -X GET \
  -H "Accept: text/xml" \
  "http://example.com:8000/users/scanner/145869072824375522207"

table/scanner/scanner-id

DELETE

Deletes the scanner and frees the resources it used.

curl -vi -X DELETE \
  -H "Accept: text/xml" \
  "http://example.com:8000/users/scanner/145869072824375522207"
Table 16. Endpoints for Put Operations
Endpoint HTTP Verb Description Example

/table/row_key

PUT

Write a row to a table. The row, column qualifier, and value must each be Base-64 encoded. To encode a string, use the base64 command-line utility. To decode the string, use base64 -d. The payload is in the --dataargument, and the /users/fakerow value is a placeholder. Insert multiple rows by adding them to the <CellSet> element. You can also save the data to be inserted to a file and pass it to the -dparameter with syntax like -d @filename.txt.

curl -vi -X PUT \
  -H "Accept: text/xml" \
  -H "Content-Type: text/xml" \
  -d '<?xml version="1.0" encoding="UTF-8" standalone="yes"?><CellSet><Row key="cm93NQo="><Cell column="Y2Y6ZQo=">dmFsdWU1Cg==</Cell></Row></CellSet>' \
  "http://example.com:8000/users/fakerow"

curl -vi -X PUT \
  -H "Accept: text/json" \
  -H "Content-Type: text/json" \
  -d '{"Row":[{"key":"cm93NQo=", "Cell": [{"column":"Y2Y6ZQo=", "$":"dmFsdWU1Cg=="}]}]}'' \
  "example.com:8000/users/fakerow"
rest api在生产上的使用必然是结合shell脚本的,此处就不详细说明了!
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值