1、添加zone(副本)
(1)新增zone
按照https://blog.csdn.net/du18020126395/article/details/115431125-【所有主机初始化】
添加挂载nfs备份目录:
mkdir /obbackup
mount -o soft 172.16.80.56:/obbackup /obbackup
ocp界面执行:
【添加主机】(可以与原来的zone不同或相同机房,机房也称为idc)
选择集群【新增zone】任务主要执行如下步骤(安装ob rpm包,添加启动observer,同步配置信息等)
新增的zone是空的,并不是一个全部副本,需要新增租户级别的副本
查看资源剩余:
(2)新增副本
如果要对现有的租户增加副本,可以选择相应的租户【新增副本】
副本类型可以选择三种(通常选择全功能型副本)
全能型副本:目前支持的普通复本,拥有事务日志、MemTable 和 SSTable 等全部完整的数据和功能。它可以随时快速切换为 Leader 以对外提供服务。
日志型副本:只包含日志的副本,没有 MemTable 和 SSTable。它参与日志投票并对外提供日志服务,可以参与其他复本的恢复,但自己不能变为主提供数据库服务。
只读型副本:包含完整的日志、MemTable 和 SSTable 等。但是它的日志比较特殊,它不作为 Paxos 成员参与日志的投票,而是作为一个观察者实时追赶 Paxos 成员的日志,并在本地回放。这种副本可以在业务对读取数据的一致性要求不高的时候提供只读服务。因其不加入 Paxos 成员组,又不会造成投票成员增加导致事务提交延时的增加。
主要执行以下步骤:
(3)查看副本新增后的情况
租户的zone的优先级会被更新
修改zone4为高优先级
配置文件observer.config.bin更新为
all_server_list=172.16.80.57:2882,172.16.80.58:2882,172.16.80.59:2882,10.10.176.18:2882
但是rootservice_list=172.16.80.58:2882:2881;172.16.80.57:2882:2881;172.16.80.59:2882:2881没更新,需要手动修改:(经与ob确认,这个无需修改)
alter system set rootservice_list='172.16.80.58:2882:2881;172.16.80.57:2882:2881;172.16.80.59:2882:2881,10.10.176.18:2882:2881';
租户分布查看
select t1.name resource_pool_name, t2.`name` unit_config_name, t2.max_cpu, t2.min_cpu, round(t2.max_memory/1024/1024/1024) max_mem_gb, round(t2.min_memory/1024/1024/1024) min_mem_gb, t2.max_disk_size/1024/1024/1024 ,t2.max_session_num,t3.unit_id, t3.zone, concat(t3.svr_ip,':',t3.`svr_port`) observer,t4.tenant_id, t4.tenant_name from __all_resource_pool t1 join __all_unit_config t2 on (t1.unit_config_id=t2.unit_config_id) join __all_unit t3 on (t1.`resource_pool_id` = t3.`resource_pool_id`) left join __all_tenant t4 on (t1.tenant_id=t4.tenant_id) where t4.tenant_name='oracle_test' order by t1.`resource_pool_id`, t2.`unit_config_id`, t3.unit_id;
resource unit是新建的,与原来的不一致,可以修改:
alter resource unit config_oracle_test_zone4_oracle_unit_config_cek max_session_num=1000000;
租户中的普通表分布改变:
从REPLICA_NUM = 3变为REPLICA_NUM = 4
租户中的分区表重分布(分区层面多了一个副本):
SELECT t.tenant_id, a.tenant_name, t.table_name, d.database_name, tg.tablegroup_name , t.part_num , t2.partition_id, t2.ZONE, concat(t2.svr_ip,':',t2.svr_port) , a.primary_zone , IF(t.locality = '' OR t.locality IS NULL, a.locality, t.locality) AS locality FROM oceanbase.__all_tenant AS a JOIN oceanbase.__all_virtual_database AS d ON ( a.tenant_id = d.tenant_id ) JOIN oceanbase.__all_virtual_table AS t ON (t.tenant_id = d.tenant_id AND t.database_id = d.database_id) JOIN oceanbase.__all_virtual_meta_table t2 ON (t.tenant_id = t2.tenant_id AND (t.table_id=t2.table_id OR t.tablegroup_id=t2.table_id) AND t2.ROLE IN (1) ) LEFT JOIN oceanbase.__all_virtual_tablegroup AS tg ON (t.tenant_id = tg.tenant_id and t.tablegroup_id = tg.tablegroup_id) WHERE t.table_type IN (3) and t.table_name='TEST_PARTITION3' ORDER BY t.tenant_id, tg.tablegroup_name, d.database_name, t.table_name, t2.partition_id;
普通表多了备副本(只读副本):
2、增加observer
增加observer可以基于zone增加(但是不太规范,最好保证所有zone的observer数相同),也可以基于集群对全部zone增加
(1)基于某个zone增加observer
要保证与此zone的其他observer在同一机房
增加之后如下图所示:
资源情况如下:
select a.zone,concat(a.svr_ip,':',a.svr_port) observer, cpu_total, (cpu_total-cpu_assigned) cpu_free,disk_total,(disk_total-disk_assigned) disk_free, round(mem_total/1024/1024/1024) mem_total_gb, round((mem_total-mem_assigned)/1024/1024/1024) mem_free_gb, usec_to_time(b.last_offline_time) last_offline_time, usec_to_time(b.start_service_time) start_service_time
from __all_virtual_server_stat a join __all_server b on (a.svr_ip=b.svr_ip and a.svr_port=b.svr_port) order by a.zone, a.svr_ip;
且ob内部会自动调整租户的分布情况(此zone有多个observer的话,在zone内自动重分布租户在此zone内的副本)
select t1.name resource_pool_name, t2.`name` unit_config_name, t2.max_cpu, t2.min_cpu, round(t2.max_memory/1024/1024/1024) max_mem_gb, round(t2.min_memory/1024/1024/1024) min_mem_gb, t2.max_disk_size/1024/1024/1024 ,t2.max_session_num,t3.unit_id, t3.zone, concat(t3.svr_ip,':',t3.`svr_port`) observer,t4.tenant_id, t4.tenant_name
from __all_resource_pool t1 join __all_unit_config t2 on (t1.unit_config_id=t2.unit_config_id) join __all_unit t3 on (t1.`resource_pool_id` = t3.`resource_pool_id`)
left join __all_tenant t4 on (t1.tenant_id=t4.tenant_id)
order by t1.`resource_pool_id`, t2.`unit_config_id`, t3.unit_id;
添加observer前租户mysql_test_restore的分布如下:
添加observer后租户mysql_test_restore的分布如下:
(2)集群所有zone增加observer
集群级别添加observer其实也是对每个zone开始添加observer的任务
先添加3台主机
机房是不可更改项,所以新增的observer跟同一zone内的其他observer要在同一机房
生成了三个任务:
资源情况如下:
select a.zone,concat(a.svr_ip,':',a.svr_port) observer, cpu_total, (cpu_total-cpu_assigned) cpu_free,disk_total,(disk_total-disk_assigned) disk_free, round(mem_total/1024/1024/1024) mem_total_gb, round((mem_total-mem_assigned)/1024/1024/1024) mem_free_gb, usec_to_time(b.last_offline_time) last_offline_time, usec_to_time(b.start_service_time) start_service_time
from __all_virtual_server_stat a join __all_server b on (a.svr_ip=b.svr_ip and a.svr_port=b.svr_port) order by a.zone, a.svr_ip;
且ob内部会自动调整租户的分布情况(此zone有多个observer的话,在zone内自动重分布租户在此zone内的副本)
select t1.name resource_pool_name, t2.`name` unit_config_name, t2.max_cpu, t2.min_cpu, round(t2.max_memory/1024/1024/1024) max_mem_gb, round(t2.min_memory/1024/1024/1024) min_mem_gb, t2.max_disk_size/1024/1024/1024 ,t2.max_session_num,t3.unit_id, t3.zone, concat(t3.svr_ip,':',t3.`svr_port`) observer,t4.tenant_id, t4.tenant_name
from __all_resource_pool t1 join __all_unit_config t2 on (t1.unit_config_id=t2.unit_config_id) join __all_unit t3 on (t1.`resource_pool_id` = t3.`resource_pool_id`)
left join __all_tenant t4 on (t1.tenant_id=t4.tenant_id)
order by t1.`resource_pool_id`, t2.`unit_config_id`, t3.unit_id;
select * from __all_resource_pool;
对租户扩容:
alter resource pool pool_oracle_test_zone1_vsz unit_num=2;
分区表被重分布:
SELECT t.tenant_id, a.tenant_name, t.table_name, d.database_name, tg.tablegroup_name , t.part_num , t2.partition_id, t2.ZONE, concat(t2.svr_ip,':',t2.svr_port)
, a.primary_zone , IF(t.locality = '' OR t.locality IS NULL, a.locality, t.locality) AS locality
FROM oceanbase.__all_tenant AS a
JOIN oceanbase.__all_virtual_database AS d ON ( a.tenant_id = d.tenant_id )
JOIN oceanbase.__all_virtual_table AS t ON (t.tenant_id = d.tenant_id AND t.database_id = d.database_id)
JOIN oceanbase.__all_virtual_meta_table t2 ON (t.tenant_id = t2.tenant_id AND (t.table_id=t2.table_id OR t.tablegroup_id=t2.table_id) AND t2.ROLE IN (1) )
LEFT JOIN oceanbase.__all_virtual_tablegroup AS tg ON (t.tenant_id = tg.tenant_id and t.tablegroup_id = tg.tablegroup_id)
WHERE t.table_type IN (3) and t.table_name='SUBS_UPP_INST' -- and t2.svr_ip='10.10.176.18'
ORDER BY t.tenant_id, tg.tablegroup_name, d.database_name, t.table_name, t2.partition_id
;
obclient> alter resource pool pool_oracle_test_zone2_afn unit_num=2;
obclient> alter resource pool pool_oracle_test_zone3_ova unit_num=2;
select t1.name resource_pool_name, t2.`name` unit_config_name, t2.max_cpu, t2.min_cpu, round(t2.max_memory/1024/1024/1024) max_mem_gb, round(t2.min_memory/1024/1024/1024) min_mem_gb, t2.max_disk_size/1024/1024/1024 ,t2.max_session_num,t3.unit_id, t3.zone, concat(t3.svr_ip,':',t3.`svr_port`) observer,t4.tenant_id, t4.tenant_name from __all_resource_pool t1 join __all_unit_config t2 on (t1.unit_config_id=t2.unit_config_id) join __all_unit t3 on (t1.`resource_pool_id` = t3.`resource_pool_id`) left join __all_tenant t4 on (t1.tenant_id=t4.tenant_id) order by t1.`resource_pool_id`, t2.`unit_config_id`, t3.unit_id;
3、删除observer
删除observer比较简单,删除后查询mysql_test_restore的分布
删除过程中,分区会重新分布,select count(*) from __all_virtual_rebalance_task_stat;
4、删除zone
直接在zone列表中删除zone4,会报错如下:
需要先将租户在zone4上的副本删除,再删除zone,删除副本的流程图:
副本删除后,租户的情况如下
再去zone列表删除zone4即可
删除zone4后,rootservice_list不会自动更新,需要手动调整
alter system set rootservice_list='172.16.80.58:2882:2881;172.16.80.57:2882:2881;172.16.80.59:2882:2881';
租户的分布情况
select t1.name resource_pool_name, t2.`name` unit_config_name, t2.max_cpu, t2.min_cpu, round(t2.max_memory/1024/1024/1024) max_mem_gb, round(t2.min_memory/1024/1024/1024) min_mem_gb, t2.max_disk_size/1024/1024/1024 ,t2.max_session_num,t3.unit_id, t3.zone, concat(t3.svr_ip,':',t3.`svr_port`) observer,t4.tenant_id, t4.tenant_name
from __all_resource_pool t1 join __all_unit_config t2 on (t1.unit_config_id=t2.unit_config_id) join __all_unit t3 on (t1.`resource_pool_id` = t3.`resource_pool_id`)
left join __all_tenant t4 on (t1.tenant_id=t4.tenant_id)
order by t1.`resource_pool_id`, t2.`unit_config_id`, t3.unit_id;
分区表分区被重新分布:
SELECT t.tenant_id, a.tenant_name, t.table_name, d.database_name, tg.tablegroup_name , t.part_num , t2.partition_id, t2.ZONE, concat(t2.svr_ip,':',t2.svr_port) , a.primary_zone , IF(t.locality = '' OR t.locality IS NULL, a.locality, t.locality) AS locality FROM oceanbase.__all_tenant AS a JOIN oceanbase.__all_virtual_database AS d ON ( a.tenant_id = d.tenant_id ) JOIN oceanbase.__all_virtual_table AS t ON (t.tenant_id = d.tenant_id AND t.database_id = d.database_id) JOIN oceanbase.__all_virtual_meta_table t2 ON (t.tenant_id = t2.tenant_id AND (t.table_id=t2.table_id OR t.tablegroup_id=t2.table_id) AND t2.ROLE IN (1) ) LEFT JOIN oceanbase.__all_virtual_tablegroup AS tg ON (t.tenant_id = tg.tenant_id and t.tablegroup_id = tg.tablegroup_id) WHERE t.table_type IN (3) and t.table_name='TEST_PARTITION3' ORDER BY t.tenant_id, tg.tablegroup_name, d.database_name, t.table_name, t2.partition_id;
表的副本数从REPLICA_NUM = 4变为REPLICA_NUM = 3
5、ocp升级ob集群版本
(1)升级前检查
集群升级不能跨版本升级
V2.2.50 --> V2.2.51 --> V2.2.52 --> V2.2.60 --> V2.2.70 --> V2.2.71
其中,每条升级路径的终点版本称为 binary 版本。
升级注意事项
在进行 OceanBase 数据库集群升级时,需要注意以下几点:
- 当前仅支持整集群升级,不支持单 Zone 升级。
- 当前不支持升级后回滚,也不支持从高版本回退到低版本。
- OceanBase 数据库版本升级时,会禁用合并、复制迁移、业务 DDL 语句、部分租户 DDL 。
- 如果升级失败,不要重试,请联系 OceanBase 售后支持。
检查当前版本select version();
或者select * from __all_server;
或者在ocp界面查看
(2)开始升级
上传版本包,进入集群开始升级
生成两个升级任务
Upgrade OB cluster 这个是主要任务,是一个zone一个zone循环的进行停zone、停observer、替换rpm包、起observer等
在某个zone升级的过程中,只有这个zone的status为inactive状态,其他两个为active状态保持ob集群的可用
且此时此zone中的所有observer被停掉,为inactive状态;
且observer进程也被停掉,并进行替换升级rpm包
rpm包替换成功之后
observer恢复,zone恢复,查看observer版本,升级成功
3个zone,每个zone有1个observer(即1-1-1架构)、整个集群升级时间大概为90分钟
如果有备集群,OCP 支持主备集群滚动升级,即一次升级任务中会同时升级主集群和备集群,升级顺序为先升级备集群,再升级主集群