一、搭建备租户方式(基于备份的方式)
注意事项:要有一个源端OB集群和目标端OB集群。
1、新建主租户(如果原来有主租户可是省略)
#创建unit
create resource unit ut_2c2g max_cpu=2, memory_size='2G', max_iops=10000,log_disk_size='20G';
#创建资源池
create resource pool pl_2c2g unit=ut_2c2g, unit_num=1;
#创建mysql租户
CREATE TENANT IF NOT EXISTS test_tenant PRIMARY_ZONE='zone1', RESOURCE_POOL_LIST=('pl_2c2g'), CHARSET='utf8mb4' SET ob_tcp_invited_nodes TO '%';
2、开启主租户日志归档
#租户调整指定租户的日志归档并发度
ALTER SYSTEM SET log_archive_concurrency = 10 TENANT = test_tenant;
#设置归档目录
ALTER SYSTEM SET LOG_ARCHIVE_DEST='LOCATION=file:///data1/nfs/log' TENANT = test_tenant;
#开启归档
ALTER SYSTEM ARCHIVELOG TENANT = test_tenant;
#查看归档状态
SELECT DEST_ID, ROUND_ID, DEST_NO, STATUS, CHECKPOINT_SCN, CHECKPOINT_SCN_DISPLAY, PATH FROM oceanbase.CDB_OB_ARCHIVELOG;
3、开启物理备份
#设置备份目录
ALTER SYSTEM SET DATA_BACKUP_DEST= 'file:///data1/nfs/data' TENANT = test_tenant;
#设置权重
ALTER SYSTEM SET ha_low_thread_score = 4 TENANT = 'test_tenant';
#物理备份
ALTER SYSTEM BACKUP TENANT = test_tenant PLUS ARCHIVELOG;
#查看备份进度
SELECT * FROM oceanbase.CDB_OB_BACKUP_JOBS\G
#查看备份集
SELECT * FROM oceanbase.DBA_OB_BACKUP_JOB_HISTORY;
2、创建数据库用户
MySQL
-- obclient -h127.0.0.1 -P2881 -uroot@test_tenant -c -A oceanbase
CREATE USER repl IDENTIFIED BY '123456';
GRANT SELECT ON oceanbase.* TO repl;
Oracle
-- obclient -h127.0.0.1 -P2881 -usys@oraclet2 -c -A
CREATE USER css IDENTIFIED BY 123456;
-- V4.2.2 直接授予角色
GRANT STANDBY_REPLICATION TO css;
-- V4.2.1 的需要手动授予以下权限
GRANT CONNECT TO rep_user;
GRANT SELECT on SYS.GV$OB_LOG_STAT to rep_user;
GRANT SELECT on SYS.GV$OB_UNITS to rep_user;
GRANT SELECT on SYS.GV$OB_PARAMETERS to rep_user;
GRANT SELECT on SYS.DBA_OB_ACCESS_POINT to rep_user;
GRANT SELECT on SYS.DBA_OB_TENANTS to rep_user;
GRANT SELECT on SYS.DBA_OB_LS to rep_user;
获取访问主库信息
该步骤为下一步创建空备租户提前准备连接信息
sys租户获取所有租户的连接信息
SELECT * FROM oceanbase.CDB_OB_ACCESS_POINT;
+-----------+-------------+--------------+----------+
| TENANT_ID | TENANT_NAME | SVR_IP | SQL_PORT |
+-----------+-------------+--------------+----------+
| 1 | sys | 10.10.30.160 | 2881 |
| 1001 | META$1002 | 10.10.30.160 | 2881 |
| 1002 | mysqlt1 | 10.10.30.160 | 2881 |
| 1003 | META$1004 | 10.10.30.160 | 2881 |
| 1004 | oraclet2 | 10.10.30.160 | 2881 |
+-----------+-------------+--------------+----------+
MySQL
SELECT * FROM oceanbase.DBA_OB_ACCESS_POINT;
Oracle
SELECT * FROM SYS.DBA_OB_ACCESS_POINT;
创建备租户
#创建unit
create resource unit ut_2c2g max_cpu=2, memory_size='2G', max_iops=10000,log_disk_size='20G';
#创建资源池
create resource pool pl_2c2g unit=ut_2c2g, unit_num=1;
#恢复方式
ALTER SYSTEM RESTORE test_tenant FROM 'file:///data1/nfs/data,log' WITH 'pool_list=pl_2c2g&concurrency=50';
持续复制
ALTER SYSTEM RECOVER STANDBY TENANT = test_tenant UNTIL UNLIMITED;