一、概述
背景信息
gs_expansion工具對數據庫的備機進行擴容,支持從單機或者一主多備最多擴容到一主八備,本文從一主一備擴容到一主兩備。
gs_dropnode工具從一主多備的數據庫中移除不需要的備機,最多可以刪除到只剩下單機,本文從一主兩備縮容到一主一備。
擴容注意事項
- 擴容后不會自動更新synchronous_standby_names參數。如果需要為該參數增加擴容的機器,請在擴容完成后手動更新。
- 擴容級聯備之前要確保原集群中有處于同一AZ(Available Zone)且狀態正常的備機,或擴容級聯備的同時也擴容了處于同AZ的備機。
- 對數據庫集群進行擴容前,需要關注主機及新擴容節點CPU、IO、網絡等情況,不建議在硬件壓力較大時執行擴容,否則可能導致擴容耗時較長甚至擴容失敗。
- 當原集群數據量較大時,在進行擴容操作前應當在主機上先執行checkpoint,否則可能導致擴容耗時較長甚至擴容失敗。
- 在單節點擴容時,如果節點hot_standby被關閉過,則需要在每個備節點上也按照如下流程修改
- 備節點需要先修改wal_level大于等于hot_standby后重啟
- 然后再修改hot_standby為on重啟,之后主機擴容才能成功。否則擴容時備機會啟動失敗
擴容前提條件
- 數據庫主機上存在MogDB鏡像包,解壓鏡像包后,在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 omm@xx.xx.xx.xx,修改后需要重啟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.
在新節點進行相關配置
二、關閉防火墻selinux
[root@test3 ~]# setenforce 0
[root@test3 ~]# sed -i '/^SELINUX=/c'SELINUX=disabled /etc/selinux/config
[root@test3 ~]# systemctl disable firewalld.service
[root@test3 ~]# systemctl stop firewalld.service
三、創建用戶和組
[root@test3 ~]# groupadd -g 1001 dbgrp
[root@test3 ~]# useradd -g dbgrp omm
[root@test3 ~]# passwd omm
四、配置三個節點的互信
[root@test3 ~]# ssh-keygen
[root@test3 ~]# ssh-copy-id xx.xxx.xx.xx
[root@test3 ~]# ssh-copy-id xx.xxx.xx.xx
其余兩機器一樣
五、安裝Python3及依賴包
[root@test3 ~]# yum install -y libaio-devel gcc gcc-c++ zlib-devel expect
[root@test3 ~]# mkdir -p /usr/local/python3
[root@test3 ~]# tar -zxvf Python-3.6.5.tgz
[root@test3 ~]# cd Python-3.6.5
[root@test3 ~]# ./configure --prefix=/usr/local/python3 --enable-shared CFLAGS=-fPIC && make && make install
[root@test3 ~]# ln -s /usr/local/python3/bin/python3 /usr/bin/python3
[root@test3 ~]# ln -s /usr/local/python3/bin/pip3 /usr/bin/pip3
[root@test3 ~]# cp /usr/local/python3/lib/libpython3.6m.so.1.0 /lib64/
在主庫進行相關配置
六、編寫clusterconfig.xml
- 添加新節點信息
[omm@test1 script]$ cat clusterconfig.xml
<?xml version="1.0" encoding="UTF-8"?>
<ROOT>
<!-- MogDB整體信息 -->
<CLUSTER>
<!-- 數據庫名稱 -->
<PARAM name="clusterName" value="test" />
<!-- 數據庫節點名稱(hostname) -->
<PARAM name="nodeNames" value="test1,test2,test3" />
<!-- 數據庫安裝目錄-->
<PARAM name="gaussdbAppPath" value="/dbdata/app/mogdb" />
<!-- 日志目錄-->
<PARAM name="gaussdbLogPath" value="/dbdata/log" />
<!-- 臨時文件目錄-->
<PARAM name="tmpMppdbPath" value="/dbdata/mogdb/tmp"/>
<!-- 數據庫工具目錄-->
<PARAM name="gaussdbToolPath" value="/dbdata/mogdb/om" />
<!-- 數據庫core文件目錄-->
<PARAM name="corePath" value="/dbdata/mogdb/corefile"/>
<!-- 節點IP,與數據庫節點名稱列表一一對應 -->
<PARAM name="backIp1s" value="xx.xxx.xx.xx,xx.xxx.xx.xx,xx.xxx.xx.xx"/>
</CLUSTER>
<!-- 每臺服務器上的節點部署信息 -->
<DEVICELIST>
<!-- 節點1上的部署信息 -->
<DEVICE sn="test1">
<!-- 節點1的主機名稱 -->
<PARAM name="name" value="test1"/>
<!-- 節點1所在的AZ及AZ優先級 -->
<PARAM name="azName" value="AZ1"/>
<PARAM name="azPriority" value="1"/>
<!-- 節點1的IP,如果服務器只有一個網卡可用,將backIP1和sshIP1配置成同一個IP -->
<PARAM name="backIp1" value="xx.xxx.xx.xx"/>
<PARAM name="sshIp1" value="xx.xxx.xx.xx"/>
<!--dn-->
<PARAM name="dataNum" value="1"/>
<PARAM name="dataPortBase" value="26000"/>
<PARAM name="dataNode1" value="/dbdata/data,test2,/dbdata/data/,test3,/dbdata/data/"/>
<!--數據庫主節點上的xlog目錄,及備機xlog目錄-->
<PARAM name="dataNodeXlogPath1" value="/dbdata/xlog,/dbdata/xlog,/dbdata/xlog "/>
<PARAM name="dataNode1_syncNum" value="0"/>
</DEVICE>
<!-- 節點2上的節點部署信息,其中“name”的值配置為主機名稱 -->
<DEVICE sn="test2">
<!-- 節點2的主機名稱 -->
<PARAM name="name" value="test2"/>
<!-- 節點2所在的AZ及AZ優先級 -->
<PARAM name="azName" value="AZ1"/>
<PARAM name="azPriority" value="1"/>
<!-- 節點2的IP,如果服務器只有一個網卡可用,將backIP1和sshIP1配置成同一個IP -->
<PARAM name="backIp1" value="xx.xxx.xx.xx"/>
<PARAM name="sshIp1" value="xx.xxx.xx.xx"/>
</DEVICE>
<!-- 節點3上的節點部署信息,其中“name”的值配置為主機名稱 -->
<DEVICE sn="test3">
<!-- 節點3的主機名稱 -->
<PARAM name="name" value="test3"/>
<!-- 節點3所在的AZ及AZ優先級 -->
<PARAM name="azName" value="AZ1"/>
<PARAM name="azPriority" value="1"/>
<!-- 節點2的IP,如果服務器只有一個網卡可用,將backIP1和sshIP1配置成同一個IP -->
<PARAM name="backIp1" value="xx.xxx.xx.xx"/>
<PARAM name="sshIp1" value="xx.xxx.xx.xx"/>
</DEVICE>
</DEVICELIST>
</ROOT>
七、擴容
[root@test1 script]# ./gs_expansion -U omm -G dbgrp -X clusterconfig.xml -h xx.xxx.xx.xx
Start expansion without cluster manager component.
Start to preinstall database on new nodes.
Start to send soft to each standby nodes.
End to send soft to each standby nodes.
Start to preinstall database step.
Preinstall xx.xxx.xx.xx success
End to preinstall database step.
End to preinstall database on new nodes.
Start to install database on new nodes.
Installing database on node xx.xxx.xx.xx:
Parsing the configuration file.
Check preinstall on every node.
Successfully checked preinstall on every node.
Creating the backup directory.
Successfully created the backup directory.
begin deploy..
Installing the cluster.
begin prepare Install Cluster..
Checking the installation environment on all nodes.
begin install Cluster..
Installing applications on all nodes.
Successfully installed APP.
begin init Instance..
encrypt cipher and rand files for database.
Please enter password for database:
Please repeat for database:
begin to create CA cert files
The sslcert will be generated in /dbdata/app/mogdb/share/sslcert/om
NO cm_server instance, no need to create CA for CM.
Cluster installation is completed.
Configuring.
Deleting instances from all nodes.
Successfully deleted instances from all nodes.
Checking node configuration on all nodes.
Initializing instances on all nodes.
Updating instance configuration on all nodes.
Check consistence of memCheck and coresCheck on database nodes.
Configuring pg_hba on all nodes.
Configuration is completed.
Successfully started cluster.
Successfully installed application.
end deploy..
xx.xxx.xx.xx install success.
Finish to install database on all nodes.
Database on standby nodes installed finished.
Checking mogdb and gs_om version.
End to check mogdb and gs_om version.
Start to establish the relationship.
Start to build standby xx.xxx.xx.xx.
Build standby xx.xxx.xx.xx success.
Start to generate and send cluster static file.
End to generate and send cluster static file.
Expansion results:
xx.xxx.xx.xx: Success
Expansion Finish.
[omm@test1 ~]$ gs_om -t status --detail
[ Cluster State ]
cluster_state : Normal
redistributing : No
current_az : AZ_ALL
[ Datanode State ]
node node_ip port instance state
--------------------------------------------------------------------------------------
1 test1 xx.xxx.xx.xx 26000 6001 /dbdata/data P Primary Normal
2 test2 xx.xxx.xx.xx 26000 6002 /dbdata/data S Standby Normal
3 test3 xx.xxx.xx.xx 26000 6003 /dbdata/data S Standby Normal
八、縮容
[omm@test1 ~]$ gs_dropnode -U omm -G dbgrp -h xx.xxx.xx.xx
The target node to be dropped is (['sticmesdbtest3'])
Do you want to continue to drop the target node (yes/no)?yes
Drop node start without CM node.
[gs_dropnode]Start to drop nodes of the cluster.
[gs_dropnode]Start to stop the target node sticmesdbtest3.
[gs_dropnode]End of stop the target node sticmesdbtest3.
[gs_dropnode]Start to backup parameter config file on test1.
[gs_dropnode]End to backup parameter config file on test1.
[gs_dropnode]The backup file of test1 is /dbdata/mogdb/tmp/gs_dropnode_backup20220804104024/parameter_test1.tar
[gs_dropnode]Start to parse parameter config file on test1.
[gs_dropnode]End to parse parameter config file on test1.
[gs_dropnode]Start to parse backup parameter config file on test1.
[gs_dropnode]End to parse backup parameter config file test1.
[gs_dropnode]Start to set openGauss config file on test1.
[gs_dropnode]End of set openGauss config file on test1.
[gs_dropnode]Start to backup parameter config file on test2.
[gs_dropnode]End to backup parameter config file on test2.
[gs_dropnode]The backup file of test2 is /dbdata/mogdb/tmp/gs_dropnode_backup20220804104026/parameter_test2.tar
[gs_dropnode]Start to parse parameter config file on test2.
[gs_dropnode]End to parse parameter config file on test2.
[gs_dropnode]Start to parse backup parameter config file on test2.
[gs_dropnode]End to parse backup parameter config file test2.
[gs_dropnode]Start to set openGauss config file on test2.
[gs_dropnode]End of set openGauss config file on test2.
[gs_dropnode]Start of set pg_hba config file on test1.
[gs_dropnode]End of set pg_hba config file on test1.
[gs_dropnode]Start of set pg_hba config file on test2.
[gs_dropnode]End of set pg_hba config file on test2.
[gs_dropnode]Start to set repl slot on test1.
[gs_dropnode]Start to get repl slot on test1.
[gs_dropnode]End of set repl slot on test1.
[gs_dropnode]Start to modify the cluster static conf.
[gs_dropnode]End of modify the cluster static conf.
[gs_dropnode]Success to drop the target nodes.
[omm@test1 ~]$ gs_om -t status --detail
[ Cluster State ]
cluster_state : Normal
redistributing : No
current_az : AZ_ALL
[ Datanode State ]
node node_ip port instance state
--------------------------------------------------------------------------------------
1 test1 xx.xxx.xx.xx 26000 6001 /dbdata/data P Primary Normal
2 test2 xx.xxx.xx.xx 26000 6002 /dbdata/data S Standby Normal




