openGauss5.0扩容、缩容

目录

一、概述

二、注意事项

扩容注意事项

扩容前提条件

缩容注意事项

缩容前提条件

三、规划

四、缩容

五、扩容


一、概述

gs_expansion工具对数据库的备机进行扩容,支持从单机或者一主多备最多扩容到一主八备。

gs_dropnode工具从一主多备的数据库中移除不需要的备机,最多可以删除到只剩下单机。

本文计划从一主两备先缩容到一主一备,再扩容回一主两备。

二、注意事项

扩容注意事项

  • 扩容后不会自动更新synchronous_standby_names参数。如果需要为该参数增加扩容的机器,请在扩容完成后手动更新。
  • 扩容级联备之前要确保原集群中有处于同一AZ(Available Zone)且状态正常的备机,或扩容级联备的同时也扩容了处于同AZ的备机。
  • 对数据库集群进行扩容前,需要关注主机及新扩容节点CPU、IO、网络等情况,不建议在硬件压力较大时执行扩容,否则可能导致扩容耗时较长甚至扩容失败。
  • 当原集群数据量较大时,在进行扩容操作前应当在主机上先执行checkpoint,否则可能导致扩容耗时较长甚至扩容失败。
  • 在单节点扩容时,如果节点hot_standby被关闭过,则需要在每个备节点上也按照如下流程修改
    • 备节点需要先修改wal_level大于等于hot_standby后重启
    • 然后再修改hot_standby为on重启,之后主机扩容才能成功。否则扩容时备机会启动失败

扩容前提条件

  • 数据库主机上存在镜像包,解压镜像包后,在script目录下执行./gs_expansion命令进行扩容。
  • 在新增的扩容备机上创建好与主机上相同的用户和用户组。
  • 已存在的数据库节点和新增的扩容节点之间需要建立好root用户互信以及数据库管理用户(如omm)的互信。
  • 正确配置xml文件,在已安装数据库配置文件的基础上,添加需要扩容的备机信息。
  • 只能使用root用户执行gs_expansion命令。
  • 不允许同时在主节点上执行gs_dropnode命令删除其他备机。
  • 执行扩容命令前需要通过source命令导入主机数据库的环境变量。如果当前数据库是分离环境变量方式安装,则source导入分离的环境变量。如果未进行分离,则需要source导入子用户的.bashrc配置文件。一般该文件路径为:/home/[user]/.bashrc。
  • 扩容备机的操作系统与主机保持一致。
  • 操作过程中不允许同时在其他备节点上执行主备倒换或者故障倒换的操作。
  • 不允许同时执行2次相同的gs_expansion命令。
  • 扩容备节点的操作只能在主节点上执行。

缩容注意事项

  • 从主备数据库实例中移除当前仍可连通的备机时,会自动停止目标备机上正在运行的数据库服务,并删除备机上的GRPC证书(证书位置:$GAUSSHOME/share/sslcert/grpc/),但是不会删除备机上的应用。
    如果删除后数据库实例中只剩下一个主机时,会提示建议重启当前主机,此时建议用户根据当前业务运行环境重启主机。

  • 如果目标备机在执行操作前处于不可连通的状态,需要用户在目标备机恢复后手动停止或删除目标备机的数据库服务,并删除备机上的GRPC证书(证书位置:$GAUSSHOME/share/sslcert/grpc/)。

  • 仅支持使用om方式安装的主备数据库实例中移除备机,不支持使用编译方式安装组建的主备数据库。

  • 当移除的备机处于同步复制模式时,如果执行删除命令的同时主机上存在事务操作,事务提交时会出现短暂卡顿,删除完成后事务处理可继续。

  • 当目标备机被移除后,如果暂时不确定是否需要目标备机,可以选择如下方法拒绝从目标备机的远程ssh连接,避免在目标备机上的误操作。

    • 方式一:在当前主机上使用root用户修改/etc/ssh/sshd_config文件,添加如下记录(如果已存在DenyUsers记录,请在后面追加)DenyUsers [email protected],修改后需要重启ssh服务使其生效,修改后限制从目标备机不能使用omm用户远程到该主机。

    • 方式二:在当前主机上将目标备机加入到/etc/hosts.deny文件中(例如:sshd:10.11.12.13:deny),拒绝从目标备机的远程ssh连接(对所有用户生效),此方法需要系统sshd服务绑定到libwrap库。

      • 当目标备机被移除后,如果不再需要目标备机,请在目标备机上使用gs_uninstall -delete-data -L命令单点卸载,请注意务必添加-L选项。
      • 当目标备机被移除后,如果需要以单机方式使用目标备机且保留原数据,请在目标备机上先执行gs_guc set -D /gaussdb/data/dbnode -c “replconninfoX”,其中/gaussdb/data/dbnode表示数据目录,replconninfoX表示主备集群中的除本节点外的其他节点,比如一主一备则需要配置replconninfo1, 一主两备需要配置replconninfo1和replconninfo2, 以此类推;如果无需保留原数据,请先执行gs_uninstall -delete-data -L命令卸载后重新安装。
  • 当目标备机被移除后,如果需要以备机方式使用目标备机,请参考gs_expansion命令重新将目标备机添加到集群中。

缩容前提条件

  • 删除备节点的操作只能在主节点上执行。
  • 操作过程中不允许同时在其他备节点上执行主备倒换或者故障倒换的操作。
  • 不允许同时在主节点上执行gs_expansion命令进行扩容。
  • 不允许同时执行2次相同的gs_dropnode命令。
  • 执行删除操作前,需要确保主节点和备节点之间建立好omm用户(数据库管理用户)的互信。
  • 需要使用数据库管理用户(比如omm)执行该命令。
  • 执行命令前需要通过source命令导入主机数据库的环境变量。如果当前数据库是分离环境变量方式安装,则source导入分离的环境变量。如果未进行分离,则需要source导入子用户的.bashrc配置文件。一般该文件路径为:/home/[user]/.bashrc.

三、规划

当前为一主两备,计划以node6为例进行缩容、扩容

序号 节点 IP 节点
1 node4 192.168.5.7 Primary
2 node5 192.168.5.8 Standby
3 node6 192.168.5.9 Standby

四、缩容

1、当前节点状态查看

gs_om -t status --detail

openGauss5.0扩容、缩容_第1张图片

 2、执行缩容

主节点执行

 gs_dropnode -U omm -G dbgrp -h 192.168.5.9
[omm@node4 dn]$ gs_dropnode -U omm -G dbgrp -h 192.168.5.9
The target node to be dropped is (['node6']) 
Do you want to continue to drop the target node (yes/no)?yes
Drop node start with CM node.
Drop node with CM node is running.
[gs_dropnode]Start to drop nodes of the cluster.
[gs_dropnode]Start to stop the target node node6.
[gs_dropnode]End of stop the target node node6.
[gs_dropnode]Start to backup parameter config file on node4.
[gs_dropnode]End to backup parameter config file on node4.
[gs_dropnode]The backup file of node4 is /opt/opengauss/tmp/gs_dropnode_backup20230518232958/parameter_node4.tar
[gs_dropnode]Start to parse parameter config file on node4.
Command for Checking VIP mode: cm_ctl res --list | awk -F "|" '{print $2}' | grep -w *** 
The current cluster does not support VIP.
[gs_dropnode]End to parse parameter config file on node4.
[gs_dropnode]Start to parse backup parameter config file on node4.
[gs_dropnode]End to parse backup parameter config file node4.
[gs_dropnode]Start to set openGauss config file on node4.
[gs_dropnode]End of set openGauss config file on node4.
[gs_dropnode]Start to backup parameter config file on node5.
[gs_dropnode]End to backup parameter config file on node5.
[gs_dropnode]The backup file of node5 is /opt/opengauss/tmp/gs_dropnode_backup20230518232959/parameter_node5.tar
[gs_dropnode]Start to parse parameter config file on node5.
Command for Checking VIP mode: cm_ctl res --list | awk -F "|" '{print $2}' | grep -w *** 
The current cluster does not support VIP.
[gs_dropnode]End to parse parameter config file on node5.
[gs_dropnode]Start to parse backup parameter config file on node5.
[gs_dropnode]End to parse backup parameter config file node5.
[gs_dropnode]Start to set openGauss config file on node5.
[gs_dropnode]End of set openGauss config file on node5.
[gs_dropnode]Start of set pg_hba config file on node4.
[gs_dropnode]End of set pg_hba config file on node4.
[gs_dropnode]Start of set pg_hba config file on node5.
[gs_dropnode]End of set pg_hba config file on node5.
[gs_dropnode]Start to set repl slot on node4.
[gs_dropnode]Start to get repl slot on node4.
[gs_dropnode]End of set repl slot on node4.
Command for Checking VIP mode: cm_ctl res --list | awk -F "|" '{print $2}' | grep -w *** 
The current cluster does not support VIP.
Stopping node.
=========================================
Successfully stopped node.
=========================================
End stop node.
Generate drop flag file on drop node node6 successfully.
[gs_dropnode]Start to modify the cluster static conf.
[gs_dropnode]End of modify the cluster static conf.
Restarting cm_server cluster ...
Remove dynamic_config_file and CM metadata directory on all nodes.
[gs_dropnode] Success to drop the target nodes.

3、验证

gs_om -t status --detail

openGauss5.0扩容、缩容_第2张图片

 openGauss5.0扩容、缩容_第3张图片

 4、删除备机上的数据

gs_uninstall --delete-data -L

openGauss5.0扩容、缩容_第4张图片

五、扩容

扩容前需要将待扩容环境的配置及环境准备好,主节点需要修改好xml文件,由于本文中是直接缩容过来的,所以xml可以不用修改

1、xml配置文件

 
 
     
     
         
         
    
         
         
         
         
         
         
     
     
     
     
         
         
             
             
             
             
             
             
             
             
             
             
             
             
             
             
	     
             
	     
	     
             
         
 
         
         
             
             
             
             
             
             
             
             
             
	 
 
         
         
             
             
             
             
             
             
             
             
             
	 
     

2、执行扩容

root用户执行

cd /opt/software/openGauss
./script/gs_expansion -U omm -G dbgrp -X cluster_config.xml -h 192.168.5.9
[root@node4 openGauss]# ./script/gs_expansion -U omm -G dbgrp -X cluster_config.xml -h 192.168.5.9
Start expansion with cluster manager component.
Start to send soft to each standby nodes.
End to send soft to each standby nodes.
Success to send XML to new nodes
Start to perform perinstall on nodes: ['node6']
Preinstall command is: /tmp/gs_expansion_2023-05-18_23_47_48_445377/pkg/script/gs_preinstall -U omm -G dbgrp -X /opt/software/openGauss/cluster_config.xml -L  --non-interactive 2>&1
Success to perform perinstall on nodes ['node6']
Success to change user to [omm]
Installing applications on all new nodes.
Install on new node output: [SUCCESS] node6:
Using omm:dbgrp to install database.
Using installation program path : /opt/opengauss/app
Command for creating symbolic link: ln -snf /opt/opengauss/app_a07d57c3 /opt/opengauss/app.
Decompressing bin file.
Decompress CM package command: export LD_LIBRARY_PATH=$GPHOME/script/gspylib/clib:$LD_LIBRARY_PATH && tar -zxf "/opt/opengauss/om/script/os_platform/./../../openGauss-5.0.0-CentOS-64bit-cm.tar.gz" -C "/opt/opengauss/app"
Decompress CM package successfully.
Successfully decompressed bin file.
Modifying Alarm configuration.
Modifying user's environmental variable $GAUSS_ENV.
Successfully modified user's environmental variable $GAUSS_ENV.
Fixing file permission.
Set Cgroup config file to appPath.
Successfully Set Cgroup.

Successfully installed APP on nodes ['node6'].
success to send all CA file.
Success to change user to [omm]
Success to init instance on nodes ['node6']
Start to generate and send cluster static file.
End to generate and send cluster static file.

The current cluster does not support VIP.
Ready to perform command on node [node6]. Command is : source /home/omm/.bashrc;gs_guc set -D /opt/opengauss/data/dn -h 'host    all    omm    192.168.5.9/32    trust' -h 'host    all    all    192.168.5.9/32    sha256'
Successfully set hba on all nodes.
Success to change user to [omm]
Remove dynamic_config_file and CM metadata directory on all nodes.
Expansion results:
192.168.5.9:	Success

异常1:

[GAUSS-51802] : Failed to obtain the environment variable "GPHOME", please import environment variable.

因root用户没有配置环境变量,将omm用户~/.bashrc文件中openGauss相关的环境变量拷贝过来即可

3、验证

gs_om -t status --detail

openGauss5.0扩容、缩容_第5张图片

参考文章:MogDB/openGauss 3.0 扩容及缩容 - 墨天轮

你可能感兴趣的:(数据库)