HBase篇---Shell命令行和Rest API
HBase Shell部分
命令名称 | 功能描述 | 命令样例 |
help ‘命名名’ | 查看命令的使用描述 help | help ‘status’ |
whoami | 显示当前用户与组 | whoami |
version | 返回hbase版本信息 | version |
create | 创建新表 | create ‘表名’, ‘列族名1’, ‘列族名2’, ‘列族名N’; 删除列族:alter ‘表名’, {NAME=> ‘列族名’, METHOD=> ‘delete’} |
alter | 修改列族 | 添加一个列族:alter ‘表名’, ‘列族名’ |
describe | 显示表相关的详细信息 | describe ‘表名’ desc ‘表名’ |
list | 列出hbase中存在的所有表 | list |
exists | 测试表是否存在 | exists ‘表名’ |
put | 添加或修改的表的值 put | put ‘表名’, ‘行键’, ‘列族名:列名’, ‘列值 |
scan | 通过对表的扫描来获取对用的值 | scan ‘表名’ |
get | 获取行或单元(cell)的值 | get ‘表名’, ‘行键’, ‘列族名’ |
incr | 增加指定表行或列的值 | incr ‘表名’, ‘行键’, ‘列族:列名’, 步长值 |
delete | 删除指定对象的值(可以为表,行,列对应的值,另外也可以指定时间戳的值) | delete ‘表名’, ‘行键’, ‘列族名:列名’ |
deleteall | 删除指定行的所有元素值 | deleteall ‘表名’, ‘行键’ |
enable | 使表有效 | enable ‘表名’ |
truncate | 重新创建指定表 | truncate ‘表名’ |
is_enabled | 是否启用 | is_enabled ‘表名’ |
disable | 使表无效 | disable ‘表名’ |
is_disabled | 是否无效 | is_disabled ‘表名’ |
drop | 删除表 | drop的表必须是disable的 |
shutdown | 关闭hbase集群(与exit不同) | |
tools | 列出hbase所支持的工具 | |
exit | 退出hbase shell |
Rest API部分
Hbase集群能够提供Rest的方式, 允许应用程序通过Web访问。首先可以通过bin/hbase rest start -pXXXX #端口自己指定即可,启动RESTServer进程,通过jps方式检查集群节点是否启动RESTServer进程。
查询软件版本
使用方法:GET /version
Curl命令:curl -vi -X GET \
-H "Accept: text/xml" \
http://IP:port/version/cluster
其中IP是启动了RESTServer进程集群节点IP,port为自定义端口,下同。
返回软件版本。针对文本输出,设置Accept头为text/plain;针对XML应答,设置Accept头为text/xml;针对JSON应答,设置Accept头为application/json;针对protobufs,设置Accept头为application/x-protobuf。
如果不成功,返回相应的HTTP错误状态码;如果成功,返回软件版本。
查询存储集群版本
使用方法:GET /version/cluster
Curl命令:curl -vi -X GET \
-H "Accept: text/xml" \
"http://IP:port/status/cluster"
返回HBase集群的版本信息。
关于Table DDL相关的Rest API
Endpoint | HTTP Verb | Description | Example |
/table/schema | GET | Describe the schema of the specified table. | curl -vi -X GET -H "Accept:text/xml" "http://IP:port/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://IP:port/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://IP:port/users/schema" |
/table/schema | DELETE | Delete the table. You must use the / table /schema endpoint, not just / table / . |
curl -vi -X DELETE \ -H "Accept: text/xml" \ "http://IP:port/users/schema" |
/table/schema | GET | List the table regions | curl -vi -X GET \ -H "Accept: text/xml" \ "http://IP:port/users/regions |
关于Table DML相关的Rest API
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://IP:port/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://IP:port/users/row1/cf:a/klle18" |
/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://IP:port/users/row1/cf:a" curl -vi -X GET \ -H "Accept: text/xml" \ "http://IP:port/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/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://IP:port/users/fakerow" |
关于Scan
相关的Rest API
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 |
curl -vi -X PUT \ -H "Accept: text/xml" \ -H "Content-Type: text/xml" \ -d '<Scanner batch="1"/>' \ "http://IP:port/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://IP:port/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://IP:port/users/scanner/ScannerID" |
/table/scanner/scanner-id | DELETE | Deletes the scanner and frees the resources it used. | curl -vi -X DELETE \ -H "Accept: text/xml" \ "http://IP:port/users/scanner/ScannerID" |
- 点赞
- 收藏
- 关注作者
评论(0)