租户基本概念回顾

•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)

创建oracle租户

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查看租户信息

oceanbase怎么迁移(OceanBase学习记录八OB环境部署-创建租户)(1)

连接mysql_t1租户

[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)]>

连接oracle租户

[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中执行连接操作

oceanbase怎么迁移(OceanBase学习记录八OB环境部署-创建租户)(2)

输入sys的密码,连接成功后可以看到租户的密码等

oceanbase怎么迁移(OceanBase学习记录八OB环境部署-创建租户)(3)

点击租户,点击用户可以查看对应的登陆字符串。复制出来可以直接登陆。

oceanbase怎么迁移(OceanBase学习记录八OB环境部署-创建租户)(4)

,