首页  :: 新随笔  :: 管理

OceanBase集群缩容

Posted on 2023-05-09 10:28  高&玉  阅读(11)  评论(0编辑  收藏  举报

连接sys租户

使用root用户连接sys租户的oceanbase数据库

[admin]# mysql -h192.168.1.71 -P2883 -D oceanbase -uroot@sys -pOceanbase2881 -A

租户减少副本

查看租户信息,sys、my_tenat租户(sys是系统租户,my_tenant是我创建的测试租户)的LOCALITY值包括:zone1、zone2、zone3

mysql> select * from DBA_OB_TENANTS;
+-----------+-------------+-------------+----------------------------+----------------------------+--------------+---------------------------------------------+-------------------+--------------------+--------+---------------+--------+
| TENANT_ID | TENANT_NAME | TENANT_TYPE | CREATE_TIME                | MODIFY_TIME                | PRIMARY_ZONE | LOCALITY                                    | PREVIOUS_LOCALITY | COMPATIBILITY_MODE | STATUS | IN_RECYCLEBIN | LOCKED |
+-----------+-------------+-------------+----------------------------+----------------------------+--------------+---------------------------------------------+-------------------+--------------------+--------+---------------+--------+
|         1 | sys         | SYS         | 2023-04-24 18:33:06.821930 | 2023-05-08 18:23:29.612310 | RANDOM       | FULL{1}@zone1, FULL{1}@zone2, FULL{1}@zone3 | NULL              | MYSQL              | NORMAL | NO            | NO     |
|      1003 | META$1004   | META        | 2023-04-25 16:54:07.990306 | 2023-05-08 18:25:26.069907 | RANDOM       | FULL{1}@zone1, FULL{1}@zone2, FULL{1}@zone3 | NULL              | MYSQL              | NORMAL | NO            | NO     |
|      1004 | my_tenant   | USER        | 2023-04-25 16:54:07.991849 | 2023-05-08 18:25:26.069907 | RANDOM       | FULL{1}@zone1, FULL{1}@zone2, FULL{1}@zone3 | NULL              | MYSQL              | NORMAL | NO            | NO     |
+-----------+-------------+-------------+----------------------------+----------------------------+--------------+---------------------------------------------+-------------------+--------------------+--------+---------------+--------+

从租户中删除zone3

mysql> alter tenant sys LOCALITY='FULL{1}@zone1,FULL{1}@zone2';
Query OK, 0 rows affected (3.98 sec)

mysql> alter tenant my_tenant LOCALITY='FULL{1}@zone1,FULL{1}@zone2';
Query OK, 0 rows affected (2.93 sec)

查看租户信息,可以看到sys、my_tenant租户的LOCALITY值只包括:zone1、zone2

mysql> select * from DBA_OB_TENANTS;
+-----------+-------------+-------------+----------------------------+----------------------------+--------------+------------------------------+-------------------+--------------------+--------+---------------+--------+
| TENANT_ID | TENANT_NAME | TENANT_TYPE | CREATE_TIME                | MODIFY_TIME                | PRIMARY_ZONE | LOCALITY                     | PREVIOUS_LOCALITY | COMPATIBILITY_MODE | STATUS | IN_RECYCLEBIN | LOCKED |
+-----------+-------------+-------------+----------------------------+----------------------------+--------------+------------------------------+-------------------+--------------------+--------+---------------+--------+
|         1 | sys         | SYS         | 2023-04-24 18:33:06.821930 | 2023-05-09 09:28:07.989177 | RANDOM       | FULL{1}@zone1, FULL{1}@zone2 | NULL              | MYSQL              | NORMAL | NO            | NO     |
|      1003 | META$1004   | META        | 2023-04-25 16:54:07.990306 | 2023-05-09 09:28:31.056441 | RANDOM       | FULL{1}@zone1, FULL{1}@zone2 | NULL              | MYSQL              | NORMAL | NO            | NO     |
|      1004 | my_tenant   | USER        | 2023-04-25 16:54:07.991849 | 2023-05-09 09:28:31.056441 | RANDOM       | FULL{1}@zone1, FULL{1}@zone2 | NULL              | MYSQL              | NORMAL | NO            | NO     |
+-----------+-------------+-------------+----------------------------+----------------------------+--------------+------------------------------+-------------------+--------------------+--------+---------------+--------+

资源池删除zone3

查看资源池信息,sys_pool、my_pool资源池(sys_pool是系统资源池,my_pool是我创建的测试资源池)的ZONE_LIST包括:zone1、zone2、zone3

mysql> select * from DBA_OB_RESOURCE_POOLS;
+------------------+----------+-----------+----------------------------+----------------------------+------------+----------------+-------------------+--------------+
| RESOURCE_POOL_ID | NAME     | TENANT_ID | CREATE_TIME                | MODIFY_TIME                | UNIT_COUNT | UNIT_CONFIG_ID | ZONE_LIST         | REPLICA_TYPE |
+------------------+----------+-----------+----------------------------+----------------------------+------------+----------------+-------------------+--------------+
|                1 | sys_pool |         1 | 2023-04-24 18:33:06.599543 | 2023-05-08 18:13:57.287837 |          1 |              1 | zone1;zone2;zone3 | FULL         |
|             1007 | my_pool  |      1004 | 2023-04-25 15:43:45.381999 | 2023-05-08 18:14:21.769913 |          1 |           1003 | zone1;zone2;zone3 | FULL         |
+------------------+----------+-----------+----------------------------+----------------------------+------------+----------------+-------------------+--------------+

从资源池zone_list中删除zone3

mysql> alter resource pool sys_pool ZONE_LIST=('zone1','zone2');
Query OK, 0 rows affected (0.20 sec)

mysql> alter resource pool my_pool ZONE_LIST=('zone1','zone2');
Query OK, 0 rows affected (0.29 sec)

查看资源池信息,sys_pool、my_pool资源池(sys_pool是系统资源池,my_pool是我创建的测试资源池)的ZONE_LIST包括:zone1、zone2

mysql> select * from DBA_OB_RESOURCE_POOLS;
+------------------+----------+-----------+----------------------------+----------------------------+------------+----------------+-------------+--------------+
| RESOURCE_POOL_ID | NAME     | TENANT_ID | CREATE_TIME                | MODIFY_TIME                | UNIT_COUNT | UNIT_CONFIG_ID | ZONE_LIST   | REPLICA_TYPE |
+------------------+----------+-----------+----------------------------+----------------------------+------------+----------------+-------------+--------------+
|                1 | sys_pool |         1 | 2023-04-24 18:33:06.599543 | 2023-05-09 09:41:36.796368 |          1 |              1 | zone1;zone2 | FULL         |
|             1007 | my_pool  |      1004 | 2023-04-25 15:43:45.381999 | 2023-05-09 09:41:43.783302 |          1 |           1003 | zone1;zone2 | FULL         |
+------------------+----------+-----------+----------------------------+----------------------------+------------+----------------+-------------+--------------+

删除节点

查看节点信息

mysql> select * from DBA_OB_SERVERS;
+--------------+----------+----+-------+----------+-----------------+--------+----------------------------+-----------+-----------------------+----------------------------+----------------------------+-------------------------------------------------------------------------------------------+
| SVR_IP       | SVR_PORT | ID | ZONE  | SQL_PORT | WITH_ROOTSERVER | STATUS | START_SERVICE_TIME         | STOP_TIME | BLOCK_MIGRATE_IN_TIME | CREATE_TIME                | MODIFY_TIME                | BUILD_VERSION                                                                             |
+--------------+----------+----+-------+----------+-----------------+--------+----------------------------+-----------+-----------------------+----------------------------+----------------------------+-------------------------------------------------------------------------------------------+
| 192.168.1.71 |     2882 |  1 | zone1 |     2881 | YES             | ACTIVE | 2023-05-06 15:14:10.951435 | NULL      | NULL                  | 2023-04-24 18:32:52.606554 | 2023-05-09 05:01:04.983560 | 4.0.0.0_100000272022110114-6af7f9ae79cd0ecbafd4b1b88e2886ccdba0c3be(Nov  1 2022 14:57:18) |
| 192.168.1.72 |     2882 |  2 | zone2 |     2881 | NO              | ACTIVE | 2023-05-06 15:07:46.780470 | NULL      | NULL                  | 2023-04-24 18:32:52.245134 | 2023-05-09 05:01:05.072178 | 4.0.0.0_100000272022110114-6af7f9ae79cd0ecbafd4b1b88e2886ccdba0c3be(Nov  1 2022 14:57:18) |
| 192.168.1.73 |     2882 |  4 | zone3 |     2881 | NO              | ACTIVE | 2023-05-08 18:08:33.287859 | NULL      | NULL                  | 2023-05-08 18:08:26.713833 | 2023-05-09 05:01:05.686120 | 4.0.0.0_100000272022110114-6af7f9ae79cd0ecbafd4b1b88e2886ccdba0c3be(Nov  1 2022 14:57:18) |
+--------------+----------+----+-------+----------+-----------------+--------+----------------------------+-----------+-----------------------+----------------------------+----------------------------+-------------------------------------------------------------------------------------------+

隔离192.168.1.73节点

mysql> alter system stop server '192.168.1.73:2882';
Query OK, 0 rows affected (0.94 sec)

查看节点信息,192.168.1.73节点STOP_TIME值是隔离的时间点

mysql> select * from DBA_OB_SERVERS;
+--------------+----------+----+-------+----------+-----------------+--------+----------------------------+----------------------------+-----------------------+----------------------------+----------------------------+-------------------------------------------------------------------------------------------+
| SVR_IP       | SVR_PORT | ID | ZONE  | SQL_PORT | WITH_ROOTSERVER | STATUS | START_SERVICE_TIME         | STOP_TIME                  | BLOCK_MIGRATE_IN_TIME | CREATE_TIME                | MODIFY_TIME                | BUILD_VERSION                                                                             |
+--------------+----------+----+-------+----------+-----------------+--------+----------------------------+----------------------------+-----------------------+----------------------------+----------------------------+-------------------------------------------------------------------------------------------+
| 192.168.1.71 |     2882 |  1 | zone1 |     2881 | YES             | ACTIVE | 2023-05-06 15:14:10.951435 | NULL                       | NULL                  | 2023-04-24 18:32:52.606554 | 2023-05-09 05:01:04.983560 | 4.0.0.0_100000272022110114-6af7f9ae79cd0ecbafd4b1b88e2886ccdba0c3be(Nov  1 2022 14:57:18) |
| 192.168.1.72 |     2882 |  2 | zone2 |     2881 | NO              | ACTIVE | 2023-05-06 15:07:46.780470 | NULL                       | NULL                  | 2023-04-24 18:32:52.245134 | 2023-05-09 05:01:05.072178 | 4.0.0.0_100000272022110114-6af7f9ae79cd0ecbafd4b1b88e2886ccdba0c3be(Nov  1 2022 14:57:18) |
| 192.168.1.73 |     2882 |  4 | zone3 |     2881 | NO              | ACTIVE | 2023-05-08 18:08:33.287859 | 2023-05-09 09:46:20.363214 | NULL                  | 2023-05-08 18:08:26.713833 | 2023-05-09 09:46:20.391424 | 4.0.0.0_100000272022110114-6af7f9ae79cd0ecbafd4b1b88e2886ccdba0c3be(Nov  1 2022 14:57:18) |
+--------------+----------+----+-------+----------+-----------------+--------+----------------------------+----------------------------+-----------------------+----------------------------+----------------------------+-------------------------------------------------------------------------------------------+

到192.168.1.73节点上的observer服务

[root]# kill -9 `pidof observer`

 查看节点信息,192.168.1.73节点状态为INACTIVE

mysql> select * from DBA_OB_SERVERS;
+--------------+----------+----+-------+----------+-----------------+----------+----------------------------+----------------------------+-----------------------+----------------------------+----------------------------+-------------------------------------------------------------------------------------------+
| SVR_IP       | SVR_PORT | ID | ZONE  | SQL_PORT | WITH_ROOTSERVER | STATUS   | START_SERVICE_TIME         | STOP_TIME                  | BLOCK_MIGRATE_IN_TIME | CREATE_TIME                | MODIFY_TIME                | BUILD_VERSION                                                                             |
+--------------+----------+----+-------+----------+-----------------+----------+----------------------------+----------------------------+-----------------------+----------------------------+----------------------------+-------------------------------------------------------------------------------------------+
| 192.168.1.71 |     2882 |  1 | zone1 |     2881 | YES             | ACTIVE   | 2023-05-06 15:14:10.951435 | NULL                       | NULL                  | 2023-04-24 18:32:52.606554 | 2023-05-09 05:01:04.983560 | 4.0.0.0_100000272022110114-6af7f9ae79cd0ecbafd4b1b88e2886ccdba0c3be(Nov  1 2022 14:57:18) |
| 192.168.1.72 |     2882 |  2 | zone2 |     2881 | NO              | ACTIVE   | 2023-05-06 15:07:46.780470 | NULL                       | NULL                  | 2023-04-24 18:32:52.245134 | 2023-05-09 05:01:05.072178 | 4.0.0.0_100000272022110114-6af7f9ae79cd0ecbafd4b1b88e2886ccdba0c3be(Nov  1 2022 14:57:18) |
| 192.168.1.73 |     2882 |  4 | zone3 |     2881 | NO              | INACTIVE | NULL                       | 2023-05-09 09:46:20.363214 | NULL                  | 2023-05-08 18:08:26.713833 | 2023-05-09 09:47:02.583856 | 4.0.0.0_100000272022110114-6af7f9ae79cd0ecbafd4b1b88e2886ccdba0c3be(Nov  1 2022 14:57:18) |
+--------------+----------+----+-------+----------+-----------------+----------+----------------------------+----------------------------+-----------------------+----------------------------+----------------------------+-------------------------------------------------------------------------------------------+

删除192.168.1.73节点

mysql> alter system delete server '192.168.1.73:2882';
Query OK, 0 rows affected (0.23 sec)

 查看节点信息,此时已经看不到192.168.1.73节点的信息

mysql> select * from DBA_OB_SERVERS;
+--------------+----------+----+-------+----------+-----------------+--------+----------------------------+-----------+-----------------------+----------------------------+----------------------------+-------------------------------------------------------------------------------------------+
| SVR_IP       | SVR_PORT | ID | ZONE  | SQL_PORT | WITH_ROOTSERVER | STATUS | START_SERVICE_TIME         | STOP_TIME | BLOCK_MIGRATE_IN_TIME | CREATE_TIME                | MODIFY_TIME                | BUILD_VERSION                                                                             |
+--------------+----------+----+-------+----------+-----------------+--------+----------------------------+-----------+-----------------------+----------------------------+----------------------------+-------------------------------------------------------------------------------------------+
| 192.168.1.71 |     2882 |  1 | zone1 |     2881 | YES             | ACTIVE | 2023-05-06 15:14:10.951435 | NULL      | NULL                  | 2023-04-24 18:32:52.606554 | 2023-05-09 05:01:04.983560 | 4.0.0.0_100000272022110114-6af7f9ae79cd0ecbafd4b1b88e2886ccdba0c3be(Nov  1 2022 14:57:18) |
| 192.168.1.72 |     2882 |  2 | zone2 |     2881 | NO              | ACTIVE | 2023-05-06 15:07:46.780470 | NULL      | NULL                  | 2023-04-24 18:32:52.245134 | 2023-05-09 05:01:05.072178 | 4.0.0.0_100000272022110114-6af7f9ae79cd0ecbafd4b1b88e2886ccdba0c3be(Nov  1 2022 14:57:18) |
+--------------+----------+----+-------+----------+-----------------+--------+----------------------------+-----------+-----------------------+----------------------------+----------------------------+-------------------------------------------------------------------------------------------+

 删除zone3

 查看ZONE信息

mysql> select * from DBA_OB_ZONES;
+-------+----------------------------+----------------------------+--------+-----+----------------+-----------+
| ZONE  | CREATE_TIME                | MODIFY_TIME                | STATUS | IDC | REGION         | TYPE      |
+-------+----------------------------+----------------------------+--------+-----+----------------+-----------+
| zone1 | 2023-04-24 18:33:07.113435 | 2023-04-24 18:33:07.113435 | ACTIVE |     | default_region | ReadWrite |
| zone2 | 2023-04-24 18:33:07.113435 | 2023-04-24 18:33:07.113435 | ACTIVE |     | default_region | ReadWrite |
| zone3 | 2023-05-08 18:03:47.864105 | 2023-05-08 18:07:34.943350 | ACTIVE |     | default_region | ReadWrite |
+-------+----------------------------+----------------------------+--------+-----+----------------+-----------+

关闭zone3

mysql> alter system stop zone zone3;
Query OK, 0 rows affected (0.41 sec)

查看ZONE信息,此时zone3的状态为INACTIVE(待激活)

mysql> select * from DBA_OB_ZONES;
+-------+----------------------------+----------------------------+----------+-----+----------------+-----------+
| ZONE  | CREATE_TIME                | MODIFY_TIME                | STATUS   | IDC | REGION         | TYPE      |
+-------+----------------------------+----------------------------+----------+-----+----------------+-----------+
| zone1 | 2023-04-24 18:33:07.113435 | 2023-04-24 18:33:07.113435 | ACTIVE   |     | default_region | ReadWrite |
| zone2 | 2023-04-24 18:33:07.113435 | 2023-04-24 18:33:07.113435 | ACTIVE   |     | default_region | ReadWrite |
| zone3 | 2023-05-08 18:03:47.864105 | 2023-05-09 09:49:24.709821 | INACTIVE |     | default_region | ReadWrite |
+-------+----------------------------+----------------------------+----------+-----+----------------+-----------+

删除zone3

mysql> alter system delete zone zone3;
Query OK, 0 rows affected (0.13 sec)

查看ZONE信息,此时已经看不到zone3的信息

mysql> select * from DBA_OB_ZONES;
+-------+----------------------------+----------------------------+--------+-----+----------------+-----------+
| ZONE  | CREATE_TIME                | MODIFY_TIME                | STATUS | IDC | REGION         | TYPE      |
+-------+----------------------------+----------------------------+--------+-----+----------------+-----------+
| zone1 | 2023-04-24 18:33:07.113435 | 2023-04-24 18:33:07.113435 | ACTIVE |     | default_region | ReadWrite |
| zone2 | 2023-04-24 18:33:07.113435 | 2023-04-24 18:33:07.113435 | ACTIVE |     | default_region | ReadWrite |
+-------+----------------------------+----------------------------+--------+-----+----------------+-----------+

 

删除ZONE参考:https://www.oceanbase.com/docs/common-oceanbase-database-cn-10000000001687939
删除节点参考:https://www.oceanbase.com/docs/common-oceanbase-database-cn-10000000001692877