一、环境概述

[kingbase@node2 bin]$ ./ksql -U system test
ksql (V8.0)
Type "help" for help. test=# select version();
version
----------------------------------------------------------------------------------------------------------
KingbaseES V008R006C003B0010 on x86_64-pc-linux-gnu, compiled by gcc (GCC) 4.1.2 20080704 (Red Hat 4.1.2-46), 64-bit
(1 row)

在kingbaseES R6集群已经部署了一主一备的架构下,现因业务需求,客户需要再构建一个只读的副本(流复制备库),此备库不需要纳入repmgr的管理。

集群架构:由于设备所限,新增的流复制与primary放在同一Server上

二、查看原集群节点状态和流复制状态

1、查看集群节点状态

[kingbase@node1 bin]$ ./repmgr cluster show
ID | Name | Role | Status | Upstream | Location | Priority | Timeline | Connection string
----+---------+---------+-----------+----------+----------+----------+----------+--------
1 | node248 | standby | running | node249 | default | 100 | 6 | host=192.168.7.248 user=esrep dbname=esrep port=54321 connect_timeout=10 keepalives=1 keepalives_idle=10 keepalives_interval=1 keepalives_count=3
2 | node249 | primary | * running | | default | 100 | 6 | host=192.168.7.249 user=esrep dbname=esrep port=54321 connect_timeout=10 keepalives=1 keepalives_idle=10 keepalives_interval=1 keepalives_count=3

2、查看流复制状态

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
-------+----------+---------+------------------+---------------+-----------------+-------------+-
32701 | 16384 | esrep | node248 | 192.168.7.248 | | 40835 | 2021-03-01 14:14:46.302306+08 | | streaming | 2/21000060 | 2/21000060 | 2/21000060 | 2/21000060 | | | | 1 | quorum | 2021-03-01 17:35:03.927948+08
(1 row)

三、在主库生成检查点

[kingbase@node2 bin]$ ./ksql -U system test
ksql (V8.0)
Type "help" for help. test=# checkpoint;
CHECKPOINT

四、创建新的流复制备库(sys_basebackup)

在249主机上:

[kingbase@node2 kingbase]$ pwd
/home/kingbase/cluster/R6HA/KHA/kingbase [kingbase@node2 kingbase]$ mkdir data1 [kingbase@node2 bin]$ ./sys_basebackup -h 127.0.0.1 -D /home/kingbase/cluster/R6HA/KHA/kingbase/data1 -F p -X stream -v -P -U system -p 54321
sys_basebackup: initiating base backup, waiting for checkpoint to complete
sys_basebackup: checkpoint completed
sys_basebackup: write-ahead log start point: 2/20000028 on timeline 6
sys_basebackup: starting background WAL receiver
sys_basebackup: created temporary replication slot "sys_basebackup_11798"
540366/540366 kB (100%), 1/1 tablespace
sys_basebackup: write-ahead log end point: 2/20000138
sys_basebackup: waiting for background process to finish streaming ...
sys_basebackup: syncing data to disk ...
sys_basebackup: base backup completed [kingbase@node2 kingbase]$ chmod 700 data1

五、在新备库data下生成standby.signal文件

注意:此文件标识此节点是备库,一定在启动备库数据库服务前创建;否则数据库服务启动,默认为主库,将无法再加入流复制集群。此文件可以用vi创建,也可以从原备库拷贝。

[kingbase@node1 data]$ scp standby.signal node2:/home/kingbase/cluster/R6HA/KHA/kingbase/data1
standby.signal [kingbase@node2 data1]$ ls -lh standby.signal
-rw------- 1 kingbase kingbase 20 Mar 1 17:45 standby.signal [kingbase@node2 data1]$ cat standby.signal
# created by repmgr

六、编辑kingbase.auto.conf连接主库

[kingbase@node2 data1]$ cat kingbase.auto.conf
# Do not edit this file manually!
# It will be overwritten by the ALTER SYSTEM command.
primary_conninfo = 'user=esrep connect_timeout=10 host=192.168.7.249 port=54321 keepalives=1 keepalives_idle=10 keepalives_interval=1 keepalives_count=3'
recovery_target_timeline = 'latest'
primary_slot_name = 'repmgr_slot_3'
wal_retrieve_retry_interval = '5000'
synchronous_standby_names = 'ANY 1(*)'

注意:此处填写主库的ip信息,对应的复制槽要在主库创建。

七、创建复制槽和启动备库数据库服务

1、查看已有的复制槽信息

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_1 | | physical | | | f | t | 32701 | | | 2/21000060 |
(1 row)

2、创建复制槽

test=# select sys_create_physical_replication_slot('repmgr_slot_3');
sys_create_physical_replication_slot
--------------------------------------
(repmgr_slot_3,)
(1 row) 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_1 | | physical | | | f | t | 32701 | | | 2/21000148 |
repmgr_slot_3 | | physical | | | f | f | | | |
|
(2 rows)

3、修改服务端口号(因为此备库和主库在同一个主机,所以需要修改服务端口号,同时启动两个实例)

[kingbase@node2 data1]$ cat kingbase.conf |grep port
port = 54322 # (change requires restart)

4、启动数据库服务

[kingbase@node2 bin]$ ./sys_ctl start -D ../data1
waiting for server to start....2021-03-01 17:52:22.990 CST [16562] LOG: sepapower extension initialized
2021-03-01 17:52:22.991 CST [16562] LOG: starting KingbaseES V008R006C003B0010 on x86_64-pc-linux-gnu, compiled by gcc (GCC) 4.1.2 20080704 (Red Hat 4.1.2-46), 64-bit
2021-03-01 17:52:22.991 CST [16562] LOG: listening on IPv4 address "0.0.0.0", port 54322
2021-03-01 17:52:22.991 CST [16562] LOG: listening on IPv6 address "::", port 54322
2021-03-01 17:52:23.070 CST [16562] LOG: listening on Unix socket "/tmp/.s.KINGBASE.54322"
2021-03-01 17:52:23.212 CST [16562] LOG: redirecting log output to logging collector process
2021-03-01 17:52:23.212 CST [16562] HINT: Future log output will appear in directory "sys_log".
. done
server started [kingbase@node2 bin]$ ps -ef |grep kingbase
kingbase 539 32623 0 14:14 ? 00:00:08 kingbase: esrep esrep 192.168.7.248(40847) idle
kingbase 688 32623 0 14:14 ? 00:00:19 kingbase: esrep esrep 192.168.7.249(53332) idle
kingbase 691 1 0 14:14 ? 00:00:04 /home/kingbase/cluster/R6HA/KHA/kingbase/bin/repmgrd -d -v -f /home/kingbase/cluster/R6HA/KHA/kingbase/bin/../etc/repmgr.conf
kingbase 1073 1 0 14:15 ? 00:00:01 /home/kingbase/cluster/R6HA/KHA/kingbase/bin/kbha -A daemon -f /home/kingbase/cluster/R6HA/KHA/kingbase/bin/../etc/repmgr.conf
kingbase 1354 1 0 14:15 ? 00:00:00 /home/kingbase/cluster/R6HA/KHA/kingbase/bin/../share/node_exporter
kingbase 1355 1 0 14:15 ? 00:00:00 /home/kingbase/cluster/R6HA/KHA/kingbase/bin/../share/postgres_exporter
kingbase 1409 32623 0 14:15 ? 00:00:00 kingbase: system test ::1(61541) idle
kingbase 9680 27531 0 17:23 pts/1 00:00:00 ./ksql -U system test
kingbase 9681 32623 0 17:23 ? 00:00:00 kingbase: system test [local] idle
kingbase 16562 1 0 17:52 ? 00:00:00 /home/kingbase/cluster/R6HA/KHA/kingbase/bin/kingbase -D ../data1
kingbase 16563 16562 0 17:52 ? 00:00:00 kingbase: logger
kingbase 16564 16562 1 17:52 ? 00:00:00 kingbase: startup recovering 000000060000000200000023
kingbase 16567 16562 0 17:52 ? 00:00:00 kingbase: checkpointer
kingbase 16568 16562 0 17:52 ? 00:00:00 kingbase: background writer
kingbase 16569 16562 0 17:52 ? 00:00:00 kingbase: stats collector
kingbase 16570 16562 0 17:52 ? 00:00:00 kingbase: walreceiver streaming 2/23000060
kingbase 16571 32623 0 17:52 ? 00:00:00 kingbase: walsender esrep 192.168.7.249(59875) streaming 2/23000060

八、查看流复制状态

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
-------+----------+---------+------------------+---------------+-----------------+-------------+
32701 | 16384 | esrep | node248 | 192.168.7.248 | | 40835 | 2021-03-01 14:14:46.302306+08 | | streaming | 2/23000060 | 2/23000060 | 2/23000060 | 2/23000060 | | | | 1 | quorum | 2021-03-01 17:54:12.970131+08
16571 | 16384 | esrep | walreceiver | 192.168.7.249 | | 59875 | 2021-03-01 17:52:24.644390+08 | | streaming | 2/23000060 | 2/23000060 | 2/23000060 | 2/23000060 | | | | 1 | quorum | 2021-03-01 17:53:04.788830+08
(2 rows)

九、验证数据同步

KingbaseES R6 集群创建流复制只读副本库案例的更多相关文章

  1. KingbaseES R6 集群修改物理IP和VIP案例

    在用户的实际环境里,可能有时需要修改主机的IP,这就涉及到集群的配置修改.以下以例子的方式,介绍下KingbaseES R6集群如何修改IP. 一.案例测试环境 操作系统: [KINGBASE@nod ...

  2. KingbaseES R6 主备流复制集群创建级联复制案例

    案例环境: 数据库: test=# select version(); version -------------------------------------------------------- ...

  3. KingbaseES R6 集群 recovery 参数对切换的影响

    案例说明:在KingbaseES R6集群中,主库节点出现宕机(如重启或关机),会产生主备切换,但是当主库节点系统恢复正常后,如何对原主库节点进行处理,保证集群数据的一致性和安全,可以通过对repmg ...

  4. KingbaseES R6 集群修改data目录

    案例说明: 本案例是在部署完成KingbaseES R6集群后,由于业务的需求,集群需要修改data(数据存储)目录的测试.本案例分两种修改方式,第一种是离线修改data目录,即关闭整个集群后,修改数 ...

  5. KingbaseES R6 集群通过备库clone在线添加新节点

    案例说明: KingbaseES R6集群可以通过图形化方式在线添加新节点,但是在添加新节点clone环节时,是从主库copy数据到新的节点,这样在生产环境,如果数据量大,将会对主库的网络I/O造成压 ...

  6. KingbaseES R6 集群repmgr.conf参数'recovery'测试案例(一)

    KingbaseES R6集群repmgr.conf参数'recovery'测试案例(一) 案例说明: 在KingbaseES R6集群中,主库节点出现宕机(如重启或关机),会产生主备切换,但是当主库 ...

  7. KingbaseES R6 集群启动‘incorrect command permissions for the virtual ip’故障案例

    案例说明: KingbaseES R6集群启动时,出现"incorrect command permissions for the virtual ip"故障,本案例介绍了如何分析 ...

  8. KingbaseES R6 集群sys_monitor.sh change_password一键修改集群用户密码

    案例说明: kingbaseES R6集群用户密码修改,需要修改两处: 1)修改数据库用户密码(alter user): 2)修改.encpwd文件中用户密码: 可以通过sys_monitor.sh ...

  9. KingbaseES R6 集群物理copy方式手工添加新备库节点

    案例说明: 对于主库数据量比较大的环境,在添加新节点是可以采用在线clone方式创建新的备库节点,也可以在离线的状态下,直接拷贝其中一个备库的所有集群相关目录来创建新的备库节点.本案例介绍了通过离线物 ...

随机推荐

  1. VisionPro · C# · 图像保存

    根据客户要求,每次视觉取像运行完毕后,按需保存OK或NG图像,图像分两种: 1.带视觉工具运行结果图像: 2.相机取像原图,.bmp格式. 保存图像代码如下: using System; using ...

  2. Windows启动谷歌浏览器Chrome失败(应用程序无法启动,因为应用程序的并行配置不正确)解决方法

    目录 一.系统环境 二.问题描述 三.解决方法 一.系统环境 Windows版本 系统类型 浏览器Chrome版本 Windows 10 专业版 64 位操作系统, 基于 x64 的处理器 版本 10 ...

  3. 为什么新的5G标准将为技术栈带来更低的 TCO

    ​ 摘要 新5G标准和边缘计算对低延迟的要求,给那些试图将一堆不同组件组装成一个不会出现故障且仍具有低延迟的高成本效益应用程序公司带来了严峻的挑战.事实上,这个问题非常严重,以至于需要重新考虑架构. ...

  4. jQuery获取市、区县、乡镇、村

    效果图: 首先根据自己方法把地区树状结构json字符串拿到 html下拉框和js写法如下: <select class="form-control" style=" ...

  5. 使用dnSpy对无源码EXE或DLL进行反编译并且修改

    背景 总有一些特殊情况,我们没有源码,但是某个C#程序集dll或者可执行程序exe影响到我们代码的正常运行,我们希望得到源码,能改掉或者修改某些bug,但是苦于没有源码,这个时候可以用dnspy进行源 ...

  6. 经典的损失函数:交叉熵和MSE

    经典的损失函数: ①交叉熵(分类问题):判断一个输出向量和期望向量有多接近.交叉熵刻画了两个概率分布之间的距离,他是分类问题中使用比较广泛的一种损失函数.概率分布刻画了不同事件发生的概率. 熵的定义: ...

  7. 攻防世界MISC—进阶区21-30

    21.easycap 得到一个pcap文件,协议分级统计,发现都是TCP协议 直接追踪tcp流,得到FLAG 22.reverseMe 得到一张镜面翻转的flag,放入PS中,图像-图像旋转-水平翻转 ...

  8. HashSet底层HashMap源码分析

    在看HashSet源码的时候,意外发现底层HashMap保存的value居然不是null,而是保存一个Object作为Value.顿觉有悖常理,于是来分析一下: HashSet的add方法: publ ...

  9. 计算机二级Python(第一阶段)

    介绍   本篇文章主要针对于计算机二级考试的崽崽,当然想了解Python和学习Python的崽崽也是可以看本篇文章的:毕竟,手机和电脑都可以运行Python:本篇我文章虽然是笔记,但是也纯靠手打,希望 ...

  10. python3学习笔记之字符串

    字符串 1.一个个字符组成的有序的序列,是字符的集合: 2.使用单引号.双引号.三引号引住的字符序列 3.字符串是不可变对象 4.python3起,字符串就是Unicode类型: 字符串特殊举例: 不 ...