KingbaseES V8R6集群部署案例之---Windows环境配置主备流复制(异机复制)

案例说明:
目前KingbaseES V8R6的Windows版本不支持数据库sys_rman的物理备份,可以考虑通过建立主备流复制实现数据库的异机物理备份。本案例详细介绍了,在Windows环境下建立流复制的过程,备库的创建可以在同一节点完成,也可以异机创建流复制。

Tips:

异机构建主备流复制步骤和以上同一主机构建基本一致。
主机节点使用相同的操作系统版本和数据库版本。
检查主机之间的网络连通性,注意防火墙的配置。

适用版本:
Windows KingbaseES V8R6

系统环境:

节点信息:

一、主备库安装相同的数据库版本(尽量和主库的目录结构一致)

二、主库配置归档、流复制相关参数

# kingbase.conf配置

port=54321
archive_mode = on     
archive_command = 'copy "%p" "d:\\kes_arch\\%f"'      
wal_level = replica
max_wal_senders = 10
wal_keep_segments = 100	 

# kingbase.auto.conf 配置

# Do not edit this file manually!
# It will be overwritten by the ALTER SYSTEM command.
primary_conninfo = 'user=system password=123456 connect_timeout=10 host=192.168.1.2 
port=54321 keepalives=1 keepalives_idle=10 keepalives_interval=1 keepalives_count=3 
application_name=node01'
recovery_target_timeline = 'latest'
primary_slot_name = 'repmgr_slot_1'
wal_retrieve_retry_interval = '5000'

三、主库配置sys_hba.conf(用于异机的主备流复制)

# TYPE  DATABASE        USER            ADDRESS                 METHOD

# IPv4 local connections:
host    all             all             127.0.0.1/32            scram-sha-256
host    all             all             0.0.0.0/0               scram-sha-256
# IPv6 local connections:
host    all             all             ::1/128                 scram-sha-256
host    all             all             ::0/0                   scram-sha-256
# Allow replication connections from localhost, by a user with the
# replication privilege.
host    replication     all             127.0.0.1/32            scram-sha-256
host    replication     all             ::1/128                 scram-sha-256

host    replication     all             0.0.0.0/0            scram-sha-256

=如下所示:sys_hba.conf增加以下条目,用于异机复制。=

四、在备库通过sys_basebackup执行clone

Tips:
如果备库data目录已经存在,可以改名后,创建一个空的data目录。

D:\Program Files\Kingbase\ES\V8\Server\bin>sys_basebackup -h 192.168.1.1 -U system -W 
-C -S "repmgr_slot_2" -R -F p -X stream -v -P -D "D:\Program Files\Kingbase\ES\V8\data"

五、修改备库流复制配置

# kingbase.auto.conf 配置

# Do not edit this file manually!
# It will be overwritten by the ALTER SYSTEM command.
primary_conninfo = 'user=system password=123456 connect_timeout=10 host=192.168.1.1
 port=54321 keepalives=1 keepalives_idle=10 keepalives_interval=1 keepalives_count=3 
 application_name=node02'
recovery_target_timeline = 'latest'
primary_slot_name = 'repmgr_slot_2'
wal_retrieve_retry_interval = '5000

六、启动备库数据库服务
D:\Program Files\Kingbase\ES\V8\Server\bin>sys_ctl restart -D "D:\Program Files\Kingbase\ES\V8\data"

七、验证主备流复制
Tips:
如果主备流复制异常,可以查看备库的sys_log日志,获取相关的故障信息。

1、查看主备流复制状态

D:\Program Files\Kingbase\ES\V8\Server\bin>ksql -U system -W test
口令:
ksql (V8.0)
输入 "help" 来获取帮助信息.

test=#  select * from sys_stat_replication;
  pid  | usesysid | usename | application_name | client_addr | client_hostname | client_port |         backend_start         | backend_xmin |   state   | sent_lsn  | write_lsn | flush_lsn | replay_lsn | write_lag | flush_lag | replay_lag | sync_priority | sync_state |          reply_time
-------+----------+---------+------------------+-------------+-----------------+-------------+-------------------------------+--------------+-----------+-----------+-----------+-----------+------------+-----------+-----------+------------+---------------+------------+-------------------------------
 18324 |       10 | system  | node02           | 192.68.1.2   |                 |       54411 | 2022-08-16 14:57:31.810737+08 |              | streaming | 0/50001A8 | 0/50001A8 | 0/50001A8 | 0/50001A8  |           |           |            |             0 | sync      | 2022-08-16 14:57:42.327673+08
(1 行记录)

2、查看复制槽信息

D:\Program Files\Kingbase\ES\V8\Server\bin>ksql -U system -W test
口令:
ksql (V8.0)
输入 "help" 来获取帮助信息.

test=# select * from sys_replication_slots;
   slot_name   | plugin | slot_type | datoid | database | temporary | active | active_pid | xmin | catalog_xmin | restart_lsn | confirmed_flush_lsn
---------------+--------+-----------+--------+----------+-----------+--------+------------+------+--------------+-------------+---------------------
 repmgr_slot_2 |        | physical  |        |          | f         | t      |      18324 |      |              | 0/5019BE0   |
 repmgr_slot_1 |        | physical  |        |          | f         | f      |            |      |              |             |
(2 行记录)

八、总结
对于在KingbaseES V8R6的Windows环境,创建主备流复制与Linux环境基本相同,对于Windows环境不支持sys_rman的物理备份,可以考虑通过物理的流复制建立异机的备份。

posted @ 2022-08-19 18:06  KINGBASE研究院  阅读(199)  评论(0编辑  收藏  举报