KingbaseES R6 集群创建流复制只读副本库案例
阅读原文时间:2023年07月09日阅读:1

[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

在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

注意:此文件标识此节点是备库,一定在启动备库数据库服务前创建;否则数据库服务启动,默认为主库,将无法再加入流复制集群。此文件可以用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@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)

手机扫一扫

移动阅读更方便

阿里云服务器
腾讯云服务器
七牛云服务器

你可能感兴趣的文章