一、节点扩容
192.168.43.111 node1 备节点,192.168.43.112 主节点,192.168.43.116 node3扩容节点
1、安装securecmdd服务并已启动(安装步骤省略)
systemctl status securecmdd.service
在要扩容的节点node3上准备软件:
2、trust_cluster.sh V8R6_cluster_install.sh install.conf license.dat db.zip
需要配置install.conf的expand模块信息
[expand]
expand_type="0" # The node type of standby/witness node, which would be add to cluster. 0:standby 1:witness
primary_ip="192.168.43.112" # The ip addr of cluster primary node, which need to expand a standby/witness node.
expand_ip="192.168.43.116" # The ip addr of standby/witness node, which would be add to cluster.
node_id="3" # The node_id of standby/witness node, which would be add to cluster. It does not the same with any one in cluster node
# for example: node_id="3"
Specific instructions ,see it under [install]
install_dir="/home/kingbase/cluster_v8r6" (数据库安装目录)
zip_package=""
net_device=() # if virtual_ip set,it must be set
net_device_ip=() # if virtual_ip set,it must be set
license_file=(license.dat)
deploy_by_sshd="0"
ssh_port="22"
scmd_port="8890"
3、将db.zip解压到到install_dir 目录下,license.dat 存放在install_dir目录下,即/home/kingbase/cluster_v8r6目录下
cd /home/kingbase/cluster_v8r6/ && unzip db.zip
cp /home/kingbase/install_path/license.dat /home/kingbase/cluster_v8r6/kingbase/bin/
4、执行节点扩展命令(在扩展节点的root账号执行扩展节点命令)
[root@node3 install_path]# bash V8R6_cluster_install.sh expand
5、检查集群状态
[kingbase@node2 ~]$ repmgr cluster show
ID | Name | Role | Status | Upstream | Location | Priority | Timeline | LSN_Lag | Connection string
----+-------+---------+-----------+----------+----------+----------+----------+---------+----------------------------------------------------------------------------------------------------------------------------------------------------
1 | node1 | standby | running | node2 | default | 100 | 8 | 0 bytes | host=192.168.43.111 user=esrep dbname=esrep port=54321 connect_timeout=10 keepalives=1 keepalives_idle=10 keepalives_interval=1 keepalives_count=3
2 | node2 | primary | * running | | default | 100 | 8 | | host=192.168.43.112 user=esrep dbname=esrep port=54321 connect_timeout=10 keepalives=1 keepalives_idle=10 keepalives_interval=1 keepalives_count=3
3 | node3 | standby | running | node2 | default | 100 | 8 | 0 bytes | host=192.168.43.116 user=esrep dbname=esrep port=54321 connect_timeout=10 keepalives=1 keepalives_idle=10 keepalives_interval=1 keepalives_count=3
二、集群主备切换
repmgr standby switchover 将备用数据库升级为主机,并将现有的主机降级为备用数据库
说明:将备用数据库升级为主机,并将现有的主机降级为备用数据库。此命令必须在备用数据库上运行才能升级,并且需要配置与当前主机的免密 SSH 连接。如果执行 repmgr standby switchover 时指定了选项--siblings-follow,则 repmgr 可以使其他备机跟随新的主节点。
node2是主节点,node1和node3是备节点,现将node1升为主节点,并将node2,和node3升为node1的备节点
1、在要升为主节点的服务器上node1上执行switchover操作
[kingbase@node1 ~]$ repmgr standby switchover --siblings-follow
2、查看集群状态
[kingbase@node1 ~]$ repmgr cluster show
ID | Name | Role | Status | Upstream | Location | Priority | Timeline | LSN_Lag | Connection string
----+-------+---------+-----------+----------+----------+----------+----------+---------+----------------------------------------------------------------------------------------------------------------------------------------------------
1 | node1 | primary | * running | | default | 100 | 9 | | host=192.168.43.111 user=esrep dbname=esrep port=54321 connect_timeout=10 keepalives=1 keepalives_idle=10 keepalives_interval=1 keepalives_count=3
2 | node2 | standby | running | node1 | default | 100 | 8 | 0 bytes | host=192.168.43.112 user=esrep dbname=esrep port=54321 connect_timeout=10 keepalives=1 keepalives_idle=10 keepalives_interval=1 keepalives_count=3
3 | node3 | standby | running | node1 | default | 100 | 8 | 0 bytes | host=192.168.43.116 user=esrep dbname=esrep port=54321 connect_timeout=10 keepalives=1 keepalives_idle=10 keepalives_interval=1 keepalives_count=3
3、以下是选项:--dry-run 检查先决条件,但实际上不执行切换。-F -force忽略警告,然后继续。具体而言,如果在关闭当前主数据库遇到问题时,使用-F /-force 将通过备用数据库升级为新的主数据库来使 repmgr 继续进行,并且如果指定了--siblings-follow,使任何其他备用数据库连接到新的主机。--force-rewind[=/path/to/sys_rewind] 强制使用 sys_rewind 使原主机加入集群(需满足使用 sys_rewind 的先决条件)。--siblings-follow 使连接到旧主节点的备机节点跟随新主节点。
三、节点重新加入集群
repmgr node rejoin --force-rewindrepmgr node rejoin —将休眠(已停止)节点重新加入集群
node1 (原主)数据库停机后,重新加入新的集群中,node2是主节点,node3是备节点
[kingbase@node3 ~]$ repmgr cluster show (因为node1重新启动后变成双主,一下集群信息是node1节点启动后有停止的情况)
ID | Name | Role | Status | Upstream | Location | Priority | Timeline | LSN_Lag | Connection string
----+-------+---------+-----------+----------+----------+----------+----------+---------+----------------------------------------------------------------------------------------------------------------------------------------------------
1 | node1 | primary | - failed | ? | default | 100 | | | host=192.168.43.111 user=esrep dbname=esrep port=54321 connect_timeout=10 keepalives=1 keepalives_idle=10 keepalives_interval=1 keepalives_count=3
2 | node2 | primary | * running | | default | 100 | 10 | | host=192.168.43.112 user=esrep dbname=esrep port=54321 connect_timeout=10 keepalives=1 keepalives_idle=10 keepalives_interval=1 keepalives_count=3
3 | node3 | standby | running | node2 | default | 100 | 10 | 0 bytes | host=192.168.43.116 user=esrep dbname=esrep port=54321 connect_timeout=10 keepalives=1 keepalives_idle=10 keepalives_interval=1 keepalives_count=3
WARNING: following issues were detected
- unable to connect to node "node1" (ID: 1)
HINT: execute with --verbose option to see connection error messag
1、[kingbase@node1 ~]$ repmgr node rejoin --force-rewind -h 192.168.43.112 -Uesrep -d esrep
2、查看集群状态
[kingbase@node2 ~]$ repmgr cluster show
ID | Name | Role | Status | Upstream | Location | Priority | Timeline | LSN_Lag | Connection string
----+-------+---------+-----------+----------+----------+----------+----------+---------+----------------------------------------------------------------------------------------------------------------------------------------------------
1 | node1 | standby | running | node2 | default | 100 | 9 | 0 bytes | host=192.168.43.111 user=esrep dbname=esrep port=54321 connect_timeout=10 keepalives=1 keepalives_idle=10 keepalives_interval=1 keepalives_count=3
2 | node2 | primary | * running | | default | 100 | 10 | | host=192.168.43.112 user=esrep dbname=esrep port=54321 connect_timeout=10 keepalives=1 keepalives_idle=10 keepalives_interval=1 keepalives_count=3
3 | node3 | standby | running | node2 | default | 100 | 10 | 0 bytes | host=192.168.43.116 user=esrep dbname=esrep port=54321 connect_timeout=10 keepalives=1 keepalives_idle=10 keepalives_interval=1 keepalives_count=3
3、以下是连接选项
:-h 主机或者作为上游节点的备机所在 OS 的 ip-U 连接使用的用户,只能使用 esrep-p 连接使用的端口-d 连接使用的数据库名称,只能使用 esrep--dry-run 检查先决条件,但实际上不执行重新加入。--force-rewind 执行 sys_rewind。