•OceanBase集群内部的資源細分;每個租 戶有自己專屬的資源池(CPU、内存)和用戶名/密碼等。
•租戶之間的數據嚴格隔離;租戶内可創建專屬的數據庫、表,執行DML等操作。
•邏輯上類似傳統數據庫的實例,但物理形式上租戶并沒有自己的專屬進程。
•使用OceanBase集群資源的第一個步驟。
OCP也可以更方便的創建租戶,為了更詳細的講解創建過程,以命令行方式講解。
•步驟一、創建“資源單元規格”,create resource unit命令,指定資源單元的規格;
•步驟二、創建“資源池”,create resource pool命令,根據資源單元規格的定義創建資源單元,并賦給一個新的資源池;
步驟三、創建租戶,create tenant命令,将資源池賦給一個新的租戶
步驟1:創建unit_config
	MySQL [oceanbase]> select * from __all_unit_config\G
*************************** 1. row ***************************
     gmt_create: 2022-01-10 18:01:41.267795
   gmt_modified: 2022-01-10 18:01:41.267795
 unit_config_id: 1
           name: sys_unit_config
        max_cpu: 5
        min_cpu: 2.5
     max_memory: 17179869184
     min_memory: 12884901888
       max_iops: 10000
       min_iops: 5000
  max_disk_size: 179593805824
max_session_num: 9223372036854775807
1 row in set (0.007 sec)
MySQL [oceanbase]> create resource unit mini max_cpu=4, min_cpu=4, max_memory='8G', min_memory='8G', max_iops=10000, min_iops=1000, max_session_num=1000000, max_disk_size='20G';
Query OK, 0 rows affected (0.081 sec)
MySQL [oceanbase]> select * from __all_unit_config\G
*************************** 1. row ***************************
     gmt_create: 2022-01-10 18:01:41.267795
   gmt_modified: 2022-01-10 18:01:41.267795
 unit_config_id: 1
           name: sys_unit_config
        max_cpu: 5
        min_cpu: 2.5
     max_memory: 17179869184
     min_memory: 12884901888
       max_iops: 10000
       min_iops: 5000
  max_disk_size: 179593805824
max_session_num: 9223372036854775807
*************************** 2. row ***************************
     gmt_create: 2022-01-11 17:24:12.320207
   gmt_modified: 2022-01-11 17:24:12.320207
 unit_config_id: 1001
           name: mini
        max_cpu: 4
        min_cpu: 4
     max_memory: 8589934592
     min_memory: 8589934592
       max_iops: 10000
       min_iops: 1000
  max_disk_size: 21474836480
max_session_num: 1000000
2 rows in set (0.001 sec)
創建租戶之前,首先我們需要定義資源規格,也就是每台OB Server到底分配一個多大的資源給租戶使用。以上為例,我們定義的資源規格是4個CPU、8G内存,CPU和内存是最重要的參數,一定要定義準确。資源規格也需要指定其他參數,包括最大及最小的IOPS、最大session數量以及磁盤空間等。
創建資源池
	創建兩個資源池
CREATE RESOURCE POOL pool1
  UNIT = 'mini',
  UNIT_NUM = 1,
  ZONE_LIST = ('zone1', 'zone2')
;
CREATE RESOURCE POOL pool2
  UNIT = 'mini',
  UNIT_NUM = 1,
  ZONE_LIST = ('zone1', 'zone2')
執行過程:
MySQL [oceanbase]> CREATE RESOURCE POOL pool1
    ->   UNIT = 'mini',
    ->   UNIT_NUM = 1,
    ->   ZONE_LIST = ('zone1', 'zone2')
    -> ;
Query OK, 0 rows affected (0.234 sec)
MySQL [oceanbase]> CREATE RESOURCE POOL pool2
    ->   UNIT = 'mini',
    ->   UNIT_NUM = 1,
    ->   ZONE_LIST = ('zone1', 'zone2');
Query OK, 0 rows affected (0.193 sec)
MySQL [oceanbase]> select * from __all_resource_pool;
 ---------------------------- ---------------------------- ------------------ ---------- ------------ ---------------- ------------- ----------- -------------- -------------------- 
| gmt_create                 | gmt_modified               | resource_pool_id | name     | unit_count | unit_config_id | zone_list   | tenant_id | replica_type | is_tenant_sys_pool |
 ---------------------------- ---------------------------- ------------------ ---------- ------------ ---------------- ------------- ----------- -------------- -------------------- 
| 2022-01-10 18:01:41.310975 | 2022-01-10 18:01:41.532239 |                1 | sys_pool |          1 |              1 | zone1;zone2 |         1 |            0 |                  0 |
| 2022-01-11 17:30:10.951118 | 2022-01-11 17:30:10.951118 |             1001 | pool1    |          1 |           1001 | zone1;zone2 |        -1 |            0 |                  0 |
| 2022-01-11 17:30:53.681061 | 2022-01-11 17:30:53.681061 |             1002 | pool2    |          1 |           1001 | zone1;zone2 |        -1 |            0 |                  0 |
 ---------------------------- ---------------------------- ------------------ ---------- ------------ ---------------- ------------- ----------- -------------- -------------------- 
3 rows in set (0.004 sec)
每個resource pool在每個OB Server上隻能有一個resource unit;如果unit_num大于1,每個zone内都必須有和unit_num對應數目的機器。Zone List一般與zone個數保持一緻;如果在某個zone内找不到有足夠剩餘資源的機器來創建resource unit,資源池會創建失敗。
Zone List的數量可以少于總的Zone的數量。比如一個5副本的集群,一共有5個Zone,我們也可以指定資源池為裡面的3個Zone。
創建mysql租戶
	MySQL [oceanbase]> create tenant mysql_t1 charset='utf8mb4', zone_list=('zone1','zone2'), primary_zone='zone1,zone2', resource_pool_list=('pool1') set ob_tcp_invited_nodes='%';
Query OK, 0 rows affected (11.081 sec)
	MySQL [oceanbase]> create tenant oracle_t2 charset='utf8mb4', zone_list=('zone1','zone2'), primary_zone='zone1,zone2', resource_pool_list=('pool2') set ob_tcp_invited_nodes='%',ob_compatibility_mode='oracle';
Query OK, 0 rows affected (11.441 sec)
•Primary Zone:指定主副本分配到Zone内的優先級,逗号兩側優先級相同,分号左側優先級高于右側。比如zone1,zone2;zone3;
•需要指定租戶類型為MySQL還是Oracle,一旦指定無法修改,默認為mysql租戶;設置 字符集與編碼。對于 MySQL 模式,可選字符集有:utf8mb4、binary、gbk、gb18030。缺省為 utf8mb4。對于 Oracle 模式,可選字符集有:utf8mb4、gbk、gb18030。缺省為 utf8mb4。
通過ocp查看租戶信息
	
	[root@ocp obclient]# mysql -h1xxxx1 -P2883 -uroot@mysql_t1#obcluster01
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MySQL connection id is 3857
Server version: 5.6.25 OceanBase 3.1.2 (r20211230114204-432323fdc2f09d06250bef6ea90e4217fd555d3c) (Built Dec 30 2021 12:27:18)
Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
MySQL [(none)]> 
MySQL [(none)]>  set password=password('rootroot');    #配置root密碼
Query OK, 0 rows affected (0.175 sec)
[root@ocp obclient]# mysql -h1xxxxx1 -P2883 -uroot@mysql_t1#obcluster01 -p
Enter password: 
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MySQL connection id is 3921
Server version: 5.6.25 OceanBase 3.1.2 (r20211230114204-432323fdc2f09d06250bef6ea90e4217fd555d3c) (Built Dec 30 2021 12:27:18)
Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
MySQL [(none)]> show databases;
 -------------------- 
| Database           |
 -------------------- 
| oceanbase          |
| information_schema |
| mysql              |
| test               |
 -------------------- 
4 rows in set (0.005 sec)
直連observer的租戶
[root@ocp obclient]# mysql -h1xxx.11 -uroot@mysql_t1 -P2881 -prootroot -c
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MySQL connection id is 3221536583
Server version: 5.7.25 OceanBase 3.1.2 (r20211230114204-432323fdc2f09d06250bef6ea90e4217fd555d3c) (Built Dec 30 2021 12:27:18)
Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
MySQL [(none)]> 
	[root@ocp obclient]# obclient -h1xxxx1 -P2883 -usys@oracle_t2#obcluster01 -c --prompt "\u > "
Welcome to OceanBase.  Commands end with ; or \g.
Your OceanBase connection id is 4113
Server version: OceanBase 3.1.2 (r20211230114204-432323fdc2f09d06250bef6ea90e4217fd555d3c) (Built Dec 30 2021 12:27:18)
Copyright (c) 2000, 2020, OceanBase and/or its affiliates. All rights reserved.
Cannot read termcap database;
using dumb terminal settings.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
SYS > alter user sys identified by oracle;    #設置sys密碼
Query OK, 0 rows affected (0.19 sec)
SYS > 
再次連接使用sys密碼
[root@ocp obclient]#  obclient -h1xxxx11 -P2883 -usys@oracle_t2#obcluster01 -c --prompt "\u > " -poracle
obclient: [Warning] Using a password on the command line interface can be insecure.
Welcome to OceanBase.  Commands end with ; or \g.
Your OceanBase connection id is 4139
Server version: OceanBase 3.1.2 (r20211230114204-432323fdc2f09d06250bef6ea90e4217fd555d3c) (Built Dec 30 2021 12:27:18)
Copyright (c) 2000, 2020, OceanBase and/or its affiliates. All rights reserved.
Cannot read termcap database;
using dumb terminal settings.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
SYS > 
密碼初始化完畢後再ocp中執行連接操作
	
輸入sys的密碼,連接成功後可以看到租戶的密碼等
	
點擊租戶,點擊用戶可以查看對應的登陸字符串。複制出來可以直接登陸。
	
更多精彩资讯请关注tft每日頭條,我们将持续为您更新最新资讯!