m6米乐安卓版下载-米乐app官网下载
2

mogdb/opengauss 数据库扩缩容的几种方式 -m6米乐安卓版下载

1471

随着业务的发展,业务系统对数据库的架构要求也在变化,比如需要读负载均衡、机房搬迁、服务器硬件替换等等,这需要在原数据库主备架构的基础上进行扩/缩容操作,目前mogdb数据库安装方式有三种,分别是手工安装(非om)、标准安装(om)和ptk安装。

  • 手工安装数据库集群扩缩容,适用mogdb/opengauss数据库集群,需要初始化新节点,修改参数文件,build添加备库或者直接删除备库节点即可
  • 标准安装数据库集群扩缩容,适用mogdb/opengauss数据库集群,需要修改xml配置文件,借助gs_expansion/gs_dropnode工具进行操作,不可直接添加/删除节点
  • ptk安装数据库集群扩缩容,仅支持mogdb数据库集群,ptk0.3版本开始支持,使用ptk cluster scale-out/scale-in -h 可以快速方便的完成扩缩容

工具介绍

ptk


gs_expansion

gs_expansion工具对数据库的备机进行扩容。支持从单机或者一主多备最多扩容到一主八备(包括级联备)。

注意事项

  • 扩容后不会自动更新synchronous_standby_names参数。如果需要为该参数增加扩容的机器,请在扩容完成后手动更新。
  • 扩容级联备之前要确保原集群中有处于同一az(available zone)且状态正常的备机,或扩容级联备的同时也扩容了处于同az的备机。

gs_dropnode

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

注意事项

  • 仅支持使用om方式安装的主备数据库实例中移除备机,不支持使用编译方式安装组建的主备数据库。
  • 从主备数据库实例中移除当前仍可连通的备机时,会自动停止目标备机上正在运行的数据库服务,并删除备机上的grpc证书(证书位置:$gausshome/share/sslcert/grpc/),但是不会删除备机上的应用。
  • 如果目标备机在执行操作前处于不可连通的状态,需要用户在目标备机恢复后手动停止或删除目标备机的数据库服务,并删除备机上的grpc证书。
  • 如果删除后数据库实例中只剩下一个主机时,会提示建议重启当前主机,此时建议用户根据当前业务运行环境重启主机。
  • 当移除的备机处于同步复制模式时,如果执行删除命令的同时主机上存在事务操作,事务提交时会出现短暂卡顿,删除完成后事务处理可继续。
  • 当目标备机被移除后,如果需要以备机方式使用目标备机,请参考gs_expansion命令重新将目标备机添加到集群中。
  • 当目标备机被移除后,如果不再需要目标备机,请在目标备机上使用gs_uninstall -delete-data -l命令单点卸载,请注意务必添加-l选项
  • 当目标备机被移除后,如果暂时不确定是否需要目标备机,可以选择如下方法拒绝从目标备机的远程ssh连接,避免在目标备机上的误操作。
    • 方式一:在当前主机上使用root用户修改/etc/ssh/sshd_config文件,添加如下记录(如果已存在denyusers记录,请在后面追加)denyusers omm@10.11.12.13,修改后需要重启ssh服务使其生效,修改后限制从目标备机不能使用omm用户远程到该主机。
    • 方式二:在当前主机上将目标备机加入到/etc/hosts.deny文件中(例如:sshd:10.11.12.13:deny),拒绝从目标备机的远程ssh连接(对所有用户生效),此方法需要系统sshd服务绑定到libwrap库。
  • 当目标备机被移除后,如果需要以单机方式使用目标备机且无需保留原数据,请先执行gs_uninstall -delete-data -l命令卸载后重新安装。如果保留原数据,请在目标备机上先执行gs_guc set -d /gaussdb/data/dbnode -c “replconninfox“ ,
    • /gaussdb/data/dbnode 表示数据目录,
    • replconninfox 表示主备集群中的除本节点外的其他节点,
      比如一主一备则需要配置 replconninfo1, 一主两备需要配置 replconninfo1 和 replconninfo2, 以此类推

示例

环境检查

集群状态

[omm@node1 ~]$ 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  node1 192.168.122.221 25000      6001 /data/mogdb   p primary normal
2  node2 192.168.122.157 25000      6002 /data/mogdb   s standby normal

xml配置文件



    
        
        
        
        
        
        
        
        
    
    
        
            
            
            
            
            
        
        
        
        
        
            
            
            
            
            
    
    

扩容

前提条件

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

扩容节点准备

扩容节点:192.168.122.68
参考

--创建omm用户及用户组
[root@node3 ~]# groupadd dbgrp
[root@node3 ~]# useradd -g dbgrp omm
[root@node3 ~]# passwd omm
--建立互信,第一次需要先相互登陆确认一下
[root@node2 ~]# scp -r .ssh root@192.168.122.68:/root
[omm@node2 ~]$ scp -r .ssh omm@192.168.122.68:/home/omm/
--python3 版本要保持一致,如果不一致需要重新安装

配置xml文件



    
        
        
        
        
        
        
        
        
    
    
        
            
            
            
            
            
        
        
        
        
        
            
            
            
            
            
    	
        
            
            
            
            
            
        
    

集群扩容

[root@node1 ~]# cd /opt/mogdb300
[root@node1 mogdb300]# source /home/omm/.bashrc
[root@node1 mogdb300]# ./script/gs_expansion -u omm -g dbgrp -x /opt/mogdb300/config.xml -h 192.168.122.68
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 192.168.122.68 success
end to preinstall database step.
end to preinstall database on new nodes.
start to install database on new nodes.
installing database on node 192.168.122.68:
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 /opt/mogdb/app/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..
192.168.122.68 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 192.168.122.68.
build standby 192.168.122.68 success.
start to generate and send cluster static file.
end to generate and send cluster static file.
expansion results:
192.168.122.68:	success
expansion finish.

扩容验证

--主节点查询
[root@node1 mogdb300]# su - omm
[omm@node1 ~]$ 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  node1 192.168.122.221 25000      6001 /data/mogdb   p primary normal
2  node2 192.168.122.157 25000      6002 /data/mogdb   s standby normal
3  node3 192.168.122.68  25000      6003 /data/mogdb   s standby normal
--扩容节点查询
[root@node3 ~]# su - omm
last login: fri aug  5 10:16:20 hkt 2022 from node1 on pts/1
[omm@node3 ~]$ gs_ctl query  -d /data/mogdb
[2022-08-05 10:24:17.047][17791][][gs_ctl]: gs_ctl query ,datadir is /data/mogdb
 ha state:
	local_role                     : standby
	static_connections             : 2
	db_state                       : normal
	detail_information             : normal
 senders info:
no information
 receiver info:
	receiver_pid                   : 6141
	local_role                     : standby
	peer_role                      : primary
	peer_state                     : normal
	state                          : normal
	sender_sent_location           : 0/6000808
	sender_write_location          : 0/6000808
	sender_flush_location          : 0/6000808
	sender_replay_location         : 0/6000808
	receiver_received_location     : 0/6000808
	receiver_write_location        : 0/6000808
	receiver_flush_location        : 0/6000808
	receiver_replay_location       : 0/6000808
	sync_percent                   : 100%
	channel                        : 192.168.122.68:44046<--192.168.122.221:25001
[omm@node3 ~]$

缩容

前提条件

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

集群缩容

将新扩容节点当目标备库再删除掉,为了防止误操作,需要删除目标备库与原集群内其他节点的ssh互信,操作方式参考注意事项

--主库执行
[omm@node1 ~]$ 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  node1 192.168.122.221 25000      6001 /data/mogdb   p primary normal
2  node2 192.168.122.157 25000      6002 /data/mogdb   s standby normal
3  node3 192.168.122.68  25000      6003 /data/mogdb   s standby normal
[omm@node1 ~]$ gs_dropnode -u omm -g dbgrp -h 192.168.122.68
the target node to be dropped is (['node3'])
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 node3.
[gs_dropnode]end of stop the target node node3.
[gs_dropnode]start to backup parameter config file on node1.
[gs_dropnode]end to backup parameter config file on node1.
[gs_dropnode]the backup file of node1 is /opt/mogdb/tools/omm_mppdb/gs_dropnode_backup20220805102606/parameter_node1.tar
[gs_dropnode]start to parse parameter config file on node1.
[gs_dropnode]end to parse parameter config file on node1.
[gs_dropnode]start to parse backup parameter config file on node1.
[gs_dropnode]end to parse backup parameter config file node1.
[gs_dropnode]start to set opengauss config file on node1.
[gs_dropnode]end of set opengauss config file on node1.
[gs_dropnode]start to backup parameter config file on node2.
[gs_dropnode]end to backup parameter config file on node2.
[gs_dropnode]the backup file of node2 is /opt/mogdb/tools/omm_mppdb/gs_dropnode_backup20220805102607/parameter_node2.tar
[gs_dropnode]start to parse parameter config file on node2.
[gs_dropnode]end to parse parameter config file on node2.
[gs_dropnode]start to parse backup parameter config file on node2.
[gs_dropnode]end to parse backup parameter config file node2.
[gs_dropnode]start to set opengauss config file on node2.
[gs_dropnode]end of set opengauss config file on node2.
[gs_dropnode]start of set pg_hba config file on node1.
[gs_dropnode]end of set pg_hba config file on node1.
[gs_dropnode]start of set pg_hba config file on node2.
[gs_dropnode]end of set pg_hba config file on node2.
[gs_dropnode]start to set repl slot on node1.
[gs_dropnode]start to get repl slot on node1.
[gs_dropnode]end of set repl slot on node1.
[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@node1 ~]$ 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  node1 192.168.122.221 25000      6001 /data/mogdb   p primary normal
2  node2 192.168.122.157 25000      6002 /data/mogdb   s standby normal
[omm@node1 ~]$

目标备库单独服务(可选)

通过gs_dropnode工具已经将node3节点从集群内移除,并关闭了数据库实例,但是数据目录依然保留,而且数据库配置文件中replconninfo信息也没有清理。

--状态检查
[omm@node3 ~]$ gs_ctl query  -d /data/mogdb
[2022-08-05 10:27:53.100][24663][][gs_ctl]: gs_ctl query ,datadir is /data/mogdb
[2022-08-05 10:27:53.100][24663][][gs_ctl]:  pid file "/data/mogdb/postmaster.pid" does not exist
[2022-08-05 10:27:53.100][24663][][gs_ctl]: is server running?
[omm@node3 ~]$ cat /data/mogdb/postgresql.conf |grep -i replconninfo
replconninfo1 = 'localhost=192.168.122.68 localport=25001 localheartbeatport=25003 localservice=25004 remotehost=192.168.122.157 remoteport=25001 remoteheartbeatport=25003 remoteservice=25004'		
replconninfo2 = 'localhost=192.168.122.68 localport=25001 localheartbeatport=25003 localservice=25004 remotehost=192.168.122.221 remoteport=25001 remoteheartbeatport=25003 remoteservice=25004'
--注释复制信息
[omm@node3 ~]$ gs_guc set -d /data/mogdb/ -c "replconninfo1"
[omm@node3 ~]$ gs_guc set -d /data/mogdb/ -c "replconninfo2"
[omm@node3 ~]$ cat /data/mogdb/postgresql.conf |grep -i replconninfo
#replconninfo1 = 'localhost=192.168.122.68 localport=25001 localheartbeatport=25003 localservice=25004 remotehost=192.168.122.157 remoteport=25001 remoteheartbeatport=25003 remoteservice=25004'
#replconninfo2 = 'localhost=192.168.122.68 localport=25001 localheartbeatport=25003 localservice=25004 remotehost=192.168.122.221 remoteport=25001 remoteheartbeatport=25003 remoteservice=25004'
--启动数据库
[omm@node3 ~]$ gs_ctl -d /data/mogdb start
[omm@node3 ~]$ gsql -p 25000 postgres -r
gsql ((mogdb 3.0.0 build 62408a0f) compiled at 2022-06-30 14:21:11 commit 0 last mr  )
non-ssl connection (ssl connection is recommended when requiring high-security)
type "help" for help.
mogdb=# select pg_is_in_recovery();
 pg_is_in_recovery
-------------------
 f
(1 row)
mogdb=#

目标备库清理数据(可选)

[omm@node3 ~]$ ls /data/mogdb
backup_label.old      gaussdb.state       mot.conf      pg_hba.conf       pg_location   pg_serial     pg_version            postmaster.opts      server.key
base                  global              pg_clog       pg_hba.conf.bak   pg_logical    pg_snapshots  pg_xlog               postmaster.pid       server.key.cipher
build_completed.done  gs_build.pid        pg_csnlog     pg_hba.conf.lock  pg_multixact  pg_stat_tmp   postgresql.conf       postmaster.pid.lock  server.key.rand
cacert.pem            gs_gazelle.conf     pg_ctl.lock   pg_ident.conf     pg_notify     pg_tblspc     postgresql.conf.bak   rewind_lable         undo
full_backup_label     gswlm_userinfo.cfg  pg_errorinfo  pg_llog           pg_replslot   pg_twophase   postgresql.conf.lock  server.crt
--删除数据目录
[omm@node3 ~]$ gs_uninstall --delete-data -l
checking uninstallation.
successfully checked uninstallation.
stopping the cluster.
successfully stopped the cluster.
successfully deleted instances.
uninstalling application.
successfully uninstalled application.
uninstallation succeeded.
[omm@node3 ~]$ ls /data/mogdb
[omm@node3 ~]$

ptk 安装集群扩容

[root@node1 .ptk]# ptk cluster scale-out -h
scale out a mogdb cluster
usage:
  ptk cluster scale-out [flags]
examples:
ptk cluster -n cluster_name scale-out -c add.yaml [--force] [--skip-check-distro] [--skip-check-os] [--skip-create-user]
flags:
  -c, --config string       scale config path
      --default-guc         disable optimize guc config, use default value
      --force               if scale operation had failed or interruptted. you can use --force to scale again. it will clear the old dirty directory
      --gen-template        generate a scale add template config
  -h, --help                help for scale-out
  -n, --name string         cluster name
      --skip-check-distro   skip check distro
      --skip-check-os       skip check os
      --skip-create-user    skip create user
  -t, --timeout duration    opration timeout (default 10m0s)
global flags:
  -f, --file string         specify a configuration file of cluster
      --log-file string     specify a log output file
      --log-format string   specify the log message format. options: [text, json] (default "text")
      --log-level string    specify the log level. options: [debug, info, warning, error, panic] (default "info")
  -v, --version             print version of ptk

检查集群状态

[root@node1 ~]# ptk cluster -n m30 status
[   cluster state   ]
database_version			: mogdb-mogdb
cluster_name				: m30
cluster_state   			: normal
current_az      			: az_all
[  datanode state   ]
   id  |       ip        | port  | user | instance | db_role | state
------- ----------------- ------- ------ ---------- --------- ---------
  6001 | 192.168.122.221 | 25000 | omm  | dn_6001  | primary | normal
  6002 | 192.168.122.157 | 25000 | omm  | dn_6002  | standby | normal

生成扩容配置文件

[root@node1 .ptk]# ptk cluster -n m30 scale-out --gen-template > add.yaml
[root@node1 .ptk]# cat add.yaml
- host: 192.168.122.68
  db_port: 25000
  role: standby
  ssh_option:
    host: 192.168.122.68
    port: 22
    user: root
    password: "ptk6mdq2y2u0zde8qzxcpeu/re8ycy1uzfpez0xsmu9pqzrzmkpoy2jut0x2z05fbg9pzdlbmm5hzlfevzq="

集群扩容

[root@node1 .ptk]# ptk cluster -n m30 scale-out -c add.yaml
scale [stage=precheck]
info[2022-08-05t14:19:52.162] start check operating system
info[2022-08-05t14:19:52.633] prechecking dependent tools...
info[2022-08-05t14:19:52.932] platform: centos_7_64bit                      host=192.168.122.68
.
.
.
info[2022-08-05t14:20:25.432] reload 192.168.122.157 database by gs_ctl     host=192.168.122.157
info[2022-08-05t14:20:25.504] set 192.168.122.68 postgresql.conf            host=192.168.122.68
info[2022-08-05t14:20:25.582] generate static config to /opt/mogdb/app/bin/cluster_static_config  host=192.168.122.68
info[2022-08-05t14:20:25.612] change /opt/mogdb/app/bin/cluster_static_config owner to omm  host=192.168.122.68
info[2022-08-05t14:20:25.625] set 192.168.122.68 hba config                 host=192.168.122.68
info[2022-08-05t14:20:25.709] build 192.168.122.68 database by gs_ctl       host=192.168.122.68
scale success.
[root@node1 .ptk]# ptk cluster -n m30 status
[   cluster state   ]
database_version			: mogdb-mogdb
cluster_name				: m30
cluster_state   			: normal
current_az      			: az_all
[  datanode state   ]
   id  |       ip        | port  | user | instance | db_role | state
------- ----------------- ------- ------ ---------- --------- ---------
  6001 | 192.168.122.221 | 25000 | omm  | dn_6001  | primary | normal
  6002 | 192.168.122.157 | 25000 | omm  | dn_6002  | standby | normal
  6003 | 192.168.122.68  | 25000 | omm  | dn_6003  | standby | normal

ptk 集群缩容

[root@node1 .ptk]# ptk cluster scale-in -h
scale in a mogdb cluster
usage:
  ptk cluster scale-in [flags]
examples:
ptk cluster -n cluster_name scale-in  -h 10.0.0.1 [--stop-db] [--clear-user] [--clear-dir] [--clear-env] [-t 120]
flags:
      --clear-dir          clear relevant dir
      --clear-env          clear env value
      --clear-user         clear user in delete hosts
  -h, --help               help for scale-in
  -h, --host stringarray   scale delete hosts
  -n, --name string        cluster name
      --stop-db            stop the database
  -t, --timeout duration   opration timeout (default 5m0s)
global flags:
  -f, --file string         specify a configuration file of cluster
      --log-file string     specify a log output file
      --log-format string   specify the log message format. options: [text, json] (default "text")
      --log-level string    specify the log level. options: [debug, info, warning, error, panic] (default "info")
  -v, --version             print version of ptk

集群缩容

[root@node1 .ptk]# ptk cluster -n m30 scale-in -h 192.168.122.68 --stop-db
scale [stage=precheck]
scale [stage=exec]
modify the instance[192.168.122.68]:/data/mogdb/postgres.conf replconninfo value
info[2022-08-05t14:41:46.280] reload 192.168.122.68 database by gs_ctl      host=192.168.122.68
modify the instance[192.168.122.157]:/data/mogdb/postgres.conf replconninfo value
info[2022-08-05t14:41:46.385] reload 192.168.122.157 database by gs_ctl     host=192.168.122.157
modify the instance[192.168.122.221]:/data/mogdb/postgres.conf replconninfo value
info[2022-08-05t14:41:46.458] reload 192.168.122.221 database by gs_ctl     host=192.168.122.221
scale [stage=postexec]
would you want delete directory(appdir,datadir,tooldir,logdir)?[y|yes](default=n) y
would you want delete the user?[y|yes](default=n) y
would you want clear the env?[y|yes](default=n) y
info[2022-08-05t14:42:06.251] stop 192.168.122.68 database by gs_ctl        host=192.168.122.68
info[2022-08-05t14:42:06.321] remove files /opt/mogdb/app,/data/mogdb,/opt/mogdb/tool,/opt/mogdb/log  host=192.168.122.68
info[2022-08-05t14:42:06.587] remove user profiles                          host=192.168.122.68
info[2022-08-05t14:42:06.607] delete os user omm                            host=192.168.122.68
scale success.
[root@node1 .ptk]# ptk cluster -n m30 status
[   cluster state   ]
database_version			: mogdb-mogdb
cluster_name				: m30
cluster_state   			: normal
current_az      			: az_all
[  datanode state   ]
   id  |       ip        | port  | user | instance | db_role | state
------- ----------------- ------- ------ ---------- --------- ---------
  6001 | 192.168.122.221 | 25000 | omm  | dn_6001  | primary | normal
  6002 | 192.168.122.157 | 25000 | omm  | dn_6002  | standby | normal
[root@node1 .ptk]#
「喜欢文章,快来给作者赞赏墨值吧」
【米乐app官网下载的版权声明】本文为墨天轮用户原创内容,转载时必须标注文章的来源(墨天轮),文章链接,文章作者等基本信息,否则作者和墨天轮有权追究责任。如果您发现墨天轮中有涉嫌抄袭或者侵权的内容,欢迎发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。

文章被以下合辑收录

评论

网站地图