返回顶部
首页 > 资讯 > 数据库 >kingbaseES R6集群创建流复制只读副本库案例
  • 633
分享到

kingbaseES R6集群创建流复制只读副本库案例

kingbaseESR6集群创建流复制只读副本库案例 2021-06-19 22:06:45 633人浏览 无得
摘要

案例环境: [kingbase@node2 bin]$ ./ksql -U system test ksql (V8.0) Type "help" for help. test=# select version();

kingbaseES R6集群创建流复制只读副本库案例

案例环境:


[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的管理。

集群架构:

部署步骤:


    1)查看源集群节点状态及流复制状态。
    2)在集群主库上执行checkpoint。
    3)在新增节点下执行sys_basebackup创建流复制备库。
    4)设置新备库data目录700权限。
    5)在新备库data目录下创建standby.signal文件(可以vi编辑或从集群备库拷贝)。
    6)修改新备库kingbase.auto.conf文件,连接集群主库。
    7)在集群主库创建新备库复制槽,启动新备库数据库服务(sys_ctl启动)。
    8)查看流复制状态。
    9)在集群主库做DML操作,验证数据同步。

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

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_s
tart         | backend_xmin |   state   |  sent_lsn  | write_lsn  | flush_lsn  | replay_lsn | write_lag | flush_la
g | 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)

[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

四、配置新备库data目录权限

[kingbase@node2 kingbase]$ chmod 700 data1
[kingbase@node2 kingbase]$ ls -lh data1
total 104K
-rw-------  1 kingbase kingbase  227 Mar  1 17:29 backup_label
-rw-------  1 kingbase kingbase  217 Mar  1 17:29 backup_label.old
drwx------ 10 kingbase kingbase   98 Mar  1 17:29 base
-rw-rw-r--  1 kingbase kingbase  27K Mar  1 17:29 conf.temp
-rw-------  1 kingbase kingbase   46 Mar  1 17:29 current_logfiles
-rw-r--r--  1 kingbase kingbase  624 Mar  1 17:29 es_rep.conf
drwx------  2 kingbase kingbase 4.0K Mar  1 17:29 global
-rw-------  1 kingbase kingbase  415 Mar  1 17:29 kingbase.auto.conf
-rw-------  1 kingbase kingbase  27K Mar  1 17:29 kingbase.conf
-rw-------  1 kingbase kingbase 8.0K Mar  1 17:29 rw_status_file_20210301141839
drwx------  2 kingbase kingbase    6 Mar  1 17:29 sys_bulkload
drwx------  2 kingbase kingbase    6 Mar  1 17:29 sys_commit_ts
drwx------  2 kingbase kingbase    6 Mar  1 17:29 sys_dynshmem
-rw-------  1 kingbase kingbase 4.8K Mar  1 17:29 sys_hba.conf
-rw-------  1 kingbase kingbase 1.6K Mar  1 17:29 sys_ident.conf
drwx------  2 kingbase kingbase    6 Mar  1 17:29 sys_log
drwx------  4 kingbase kingbase   65 Mar  1 17:29 sys_logical
drwx------  4 kingbase kingbase   34 Mar  1 17:29 sys_multixact
drwx------  2 kingbase kingbase    6 Mar  1 17:29 sys_notify
drwx------  2 kingbase kingbase    6 Mar  1 17:29 sys_replslot
drwx------  2 kingbase kingbase    6 Mar  1 17:29 sys_serial
drwx------  2 kingbase kingbase    6 Mar  1 17:29 sys_snapshots
drwx------  2 kingbase kingbase   30 Mar  1 17:29 sys_stat
drwx------  2 kingbase kingbase    6 Mar  1 17:29 sys_stat_tmp
drwx------  2 kingbase kingbase    6 Mar  1 17:29 sys_subtrans
drwx------  2 kingbase kingbase    6 Mar  1 17:29 sys_tblspc
drwx------  2 kingbase kingbase    6 Mar  1 17:29 sys_twophase
-rw-------  1 kingbase kingbase    3 Mar  1 17:29 SYS_VERSION
drwx------  3 kingbase kingbase   81 Mar  1 17:29 sys_wal
drwx------  2 kingbase kingbase   17 Mar  1 17:29 sys_xact

五、在新备库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_s
tart         | backend_xmin |   state   |  sent_lsn  | write_lsn  | flush_lsn  | replay_lsn | write_lag | flush_la
g | 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)

=== 从以上可以获知,新的备库已经加入到流复制中。===

九、测试数据同步

1)主库

prod=# d t2
                          Table "public.t2"
 Column |            Type            | Collation | Nullable | Default 
--------+----------------------------+-----------+----------+---------
 id     | integer                    |           |          | 
 name   | character varying(10 char) |           |          | 

prod=# select * from t2;
 id | name 
----+------
 10 | tom
(1 row)

prod=# insert into t2 values(20,"jerry"),(30,"rose");
INSERT 0 2
prod=# select * from t2;
 id | name  
----+-------
 10 | tom
 20 | jerry
 30 | rose
(3 rows)

2)备库

[kingbase@node1 bin]$ ./ksql -U system prod -c "select * from t2"
 id | name  
----+-------
 10 | tom
 20 | jerry
 30 | rose
(3 rows)

3)只读副本

[kingbase@node2 bin]$ ./ksql -U system prod -c "select * from t2" -p 54322
 id | name  
----+-------
 10 | tom
 20 | jerry
 30 | rose

=== 从以上获知,此只读的流复制备库创建成功!===

您可能感兴趣的文档:

--结束END--

本文标题: kingbaseES R6集群创建流复制只读副本库案例

本文链接: https://lsjlt.com/news/8571.html(转载时请注明来源链接)

有问题或投稿请发送至: 邮箱/279061341@qq.com    QQ/279061341

猜你喜欢
软考高级职称资格查询
编程网,编程工程师的家园,是目前国内优秀的开源技术社区之一,形成了由开源软件库、代码分享、资讯、协作翻译、讨论区和博客等几大频道内容,为IT开发者提供了一个发现、使用、并交流开源技术的平台。
  • 官方手机版

  • 微信公众号

  • 商务合作