#CN扩缩容
YashanDB支持通过yasboot工具对分布式部署中的CN节点进行扩/缩容。
建议在对CN节点扩容/缩容操作前先备份数据库,以防操作失败时无新的备份集用于恢复。
# 注意事项
扩/缩容不能与降备(Switchover)操作并发。
扩容期间数据库集群无法正常使用,请合理安排操作时间。扩/缩容期间会阻塞DDL以及拦截下列yasboot命令:
$ yasboot cluster restart $ yasboot group restart $ yasboot node restart $ yasboot group add/remove $ yasboot node add/remove $ yasboot dataspace redistribute
在扩/缩容过程中请不要通过yasboot对当前数据库集群中的所有节点进行强制重启/停止,否则可能会造成扩/缩容失败后无法执行node remove --clean命令。如不可避免,可以尝试通过对扩容失败/缩容失败的节点进行强制操作(例如yasboot node stop -f)后,再通过node remove --node-ids的方式删除失败的CN节点。
需确保所有OUTLINE的依赖表均存在。可通过查询DBA_OUTLINES视图确认所有OUTLINE对应的SQL语句,然后进一步确认语句中涉及的表是否存在。若某个OUTLINE的依赖表不存在则需先删除该OUTLINE再执行扩容操作,否则会报错。
# 新增分布式CN节点
以安装用户登录当前数据库集群中yasboot工具所在服务器。
结合实际场景执行相应命令,生成配置文件。
场景1:向数据库集群新增服务器并增加CN节点
$ yasboot config node gen -c yashandb -u yashan -p password --ip ip1,ip2...ipn --port 22 --install-path /data/yashan/yasdb_home -g 2 --node 2
执行成功后,会生成hosts_add.toml和yashandb_add.toml两个配置文件。
场景2:在数据库集群中现有服务器上增加CN节点
$ yasboot config node gen -c yashandb --host-id host0001,host0002 -g 2 --node 2
执行成功后,会生成yashandb_add.toml配置文件。
配置文件的详细示例请查阅yashandb_add.toml以及hosts_add.toml。
部署新服务器。
如果是在数据库集群中现有服务器上增加CN节点,则跳过本步骤。
) 请先参照安装前准备检查并确保新服务器系统的各项环境已满足要求。
) 执行相应命令,部署新服务器。
$ yasboot host add -c yashandb -t hosts_add.toml type | uuid | name | hostid | index | status | return_code | progress | cost ------------------------------------------------------------------------------------------------- task | b5328fe3dbf4a2be | HostAdd | - | yashandb | SUCCESS | 0 | 100 | 9 ------+------------------+---------+--------+----------+---------+-------------+----------+------ task completed, status: SUCCESS
) (可选)若现有环境已开启monit,新服务器需开启monit功能,可参考守护进程完成相关配置。
执行如下命令,增加CN节点。
$ yasboot node add -c yashandb -t yashandb_add.toml -p password type | uuid | name | hostid | index | status | return_code | progress | cost ------------------------------------------------------------------------------------------------- task | faac17066f99af00 | NodeAdd | - | yashandb | SUCCESS | 0 | 100 | 3 ------+------------------+---------+--------+----------+---------+-------------+----------+------ task completed, status: SUCCESS
任务显示成功并不表示扩容任务已全部成功,可能仍有部分后台任务在完成数据的同步等操作。可以通过
task list
命令查看扩容相关的任务是否都成功。$ yasboot task list -c yashandb --search type=NodeAdd uuid | name | type | index | hostid | status | ret_code | progress | created_at | cost --------------------------------------------------------------------------------------------------------------------------- ddb43ad43a9ee01e | AddCNAlterHA | NodeAdd | yashandb.cng1 | - | SUCCESS | 0 | 0 | 2023-08-17 10:20:33 | - ------------------+--------------+---------+---------+--------+---------+----------+----------+---------------------+------ faac17066f99af00 | NodeAdd | NodeAdd | yashandb.cng1 | - | SUCCESS | 0 | 100 | 2023-08-17 10:20:33 | 10
(可选)若现有环境已开启资源管理功能,新增的服务器中需要创建cgroup目录,可参考yasboot相关命令。
$ yasboot host cgroup create -c yashan --sudo-username root --sudo-password ****** --host-id host004
(可选)备份数据库。
建议对数据库进行备份,确保扩容后有可用于恢复的基线备份集。
# 删除分布式CN节点
若某个CN节点发生故障无法启用,可通过在线缩容删除该故障节点。
以安装用户登录当前数据库集群中yasboot工具所在服务器。
执行如下命令,删除CN节点。
$ yasboot node remove -c yashandb -n 2-2 --purge
(可选)备份数据库。
建议对数据库进行备份,确保缩容后有可用于恢复的基线备份集。