You can create a tenant for a cluster by using obshell in two ways:
Call the API
Use obshell commands
This topic describes how to create a tenant by using obshell for a three-node OceanBase cluster.
Prerequisites
obshell has managed the OceanBase cluster. For more information about how to determine whether obshell is managing a cluster and how to take over a cluster, see Take over a non-obshell-deployed cluster.
All OceanBase servers in the OceanBase cluster and obshell are running.
Deployment mode
The following table describes the roles of the three servers (obshell uses the default port 2886):
| Role | IP address | Description |
|---|---|---|
| OBServer node | 10.10.10.1 | Zone 1 of OceanBase Database |
| OBServer node | 10.10.10.2 | Zone 2 of OceanBase Database |
| OBServer node | 10.10.10.3 | Zone 3 of OceanBase Database |
Create a tenant by using the API
Note
obshell will perform security verification on the called API. Therefore, you must encrypt the request before you call the API and configure the encrypted request header (${request_headers}) and request body (${request_body}) in the curl command. For more information, see API hybrid encryption.
Step 1: Create a resource specification
You can call the POST /api/v1/unit/config API of any obshell to create a resource specification.
For more information about how to call the API in the CLI, see Create a resource specification.
[admin@test001 ~]$ curl -H "Content-Type: application/json" -H 'X-OCS-Header:${request_headers}' -X POST -d '${request_body}' http://10.10.10.1:2886/api/v1/unit/config
The request body before encryption is as follows:
{
"name":"unit_1",
"memory_size": "5GB",
"max_cpu": 3,
}
For more information about how to request the API by using obshell-sdk-python, see Create a resource specification.
...
client = ClientSet("10.10.10.1", 2886, PassswordAuth("****"))
client.v1.create_resource_unit_config("unit_1", memory_size="5G", max_cpu=8)
...
For more information about how to request the API by using obshell-sdk-go, see Create a resource specification.
...
client, err := services.NewClientWithPassword("10.10.10.1", 2886, "********")
if err != nil {
fmt.Print(err)
return
}
if err := client.V1().CreateResourceUnitConfig("unit_1", "5G", 8); err != nil {
fmt.Print(err)
return
}
...
Step 2: Create a tenant
You can call the POST /api/v1/tenant API of any obshell to create a tenant based on the specified resource specification.
For more information about how to call the API in the CLI, see Create a tenant. This API creates an asynchronous O&M task. For more information about how to query the task progress, see Get task details. Wait for the task to complete, and then the tenant is created.
[admin@test001 ~]$ curl -H "Content-Type: application/json" -H 'X-OCS-Header:${request_headers}' -X POST -d '${request_body}' http://10.10.10.1:2886/api/v1/tenant
The request body before encryption is as follows:
{
"name": "tenant_1",
"zone_list": [
{
"name": "zone1",
"unit_config_name": "unit_1",
"unit_num": 1
},
{
"name": "zone2",
"unit_config_name": "unit_1",
"unit_num": 1
},
{
"name": "zone3",
"unit_config_name": "unit_1",
"unit_num": 1
}
],
}
For more information about how to request the API by using obshell-sdk-python, see Create a tenant.
...
client = ClientSet("10.10.10.1", 2886, PassswordAuth("****"))
client.v1.create_tenant_sync("tenant_1", [ZoneParam("zone1", 'unit_1', 1),
ZoneParam("zone2", 'unit_1', 1),
ZoneParam("zone3", 'unit_1', 1)])
...
For more information about how to request the API by using obshell-sdk-go, see Create a tenant.
...
req := client.V1().NewCreateTenantRequest("tenant_1", []v1.ZoneParam{
{
Name: "zone1",
ReplicaType: "FULL",
UnitConfigName: "unit_1",
UnitNum: 1,
},
{
Name: "zone2",
ReplicaType: "FULL",
UnitConfigName: "unit_1",
UnitNum: 1,
},
{
Name: "zone3",
ReplicaType: "FULL",
UnitConfigName: "unit_1",
UnitNum: 1,
},
})
if _, err = client.V1().CreateTenantSyncWithRequest(req); err != nil {
fmt.Print(err)
}
...
Step 3: View tenant information
You can call the GET /api/v1/tenant/:name API of any obshell to view the information of a tenant.
For more information about how to call the API in the CLI, see Query tenant information.
[admin@test001 ~]$ curl -H "Content-Type: application/json" -H 'X-OCS-Header:${request_headers}' -X GET http://10.10.10.1:2886/api/v1/tenant/tenant_1
For more information about how to request the API by using obshell-sdk-python, see Query tenant information.
...
client = ClientSet("10.10.11", 2886, PasswordAuth("****"))
tenant_info = client.v1.get_tenant_info("tenant_1")
...
For more information about how to request the API by using obshell-sdk-go, see Query tenant information.
...
client, err := services.NewClientWithPassword("10.10.10.1", 2886, "****")
tenant, err := client.V1().GetTenantInfo("tenant_1")
...
Create a tenant by using obshell commands
Step 1: Create a resource specification
You can execute the following command on any node to create a resource specification. For more information about the command, see obshell unit commands and the obshell unit create section.
[admin@test001 ~]$ /home/admin/oceanbase/bin/obshell unit create unit_1 -m 5G -c 8
Step 2: Create a tenant
You can execute the following command on any node to create a tenant. For more information about the command, see obshell tenant commands and the obshell tenant create section.
[admin@test001 ~]$ /home/admin/oceanbase/bin/obshell tenant create tenant_1 -u unit_1
Step 3: Query tenant information
You can execute the following command on any node to query the information of a tenant. For more information about the command, see obshell tenant commands and the obshell tenant show section.
[admin@test001 ~]$ /home/admin/oceanbase/bin/obshell tenant show tenant_1