集群行为分析_redis多级hash嵌套

集群行为分析_redis多级hash嵌套KINGBASE、repmgr、PostgreSQL

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

集群架构:

集群行为分析_redis多级hash嵌套

部署步骤:


    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

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

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。
转载请注明出处: https://daima100.com/6024.html

(0)
上一篇 2023-04-18
下一篇 2023-04-19

相关推荐

  • 如何搭建数据库自动化运维体系框架_大数据平台搭建与运维

    如何搭建数据库自动化运维体系框架_大数据平台搭建与运维
    需求背景: 随着业务的增长、对运维效率和质量的要求不断提高,对自动化运维体系的需求也不断增强。 目前笔者服务的很多中大型企业客户,运维其实还停留在“刀耕火种…

    2023-04-06
    165
  • Python Tuple: 简单有效的不可变序列

    Python Tuple: 简单有效的不可变序列Python中的Tuple(元组)是一种非常常见的数据类型,在Python中,可以将元组看作是不可变的列表。与列表不同的是,元组是不可变的,也就是说,一旦创建了元组,就不能修改其中的值。但是,元组的不可变性使得它们在编写代码时非常有用,因为它们不需要像列表那样进行修改,从而避免了一些执行时间上的消耗。

    2023-12-20
    126
  • php操作mysql数据库(增删改查)_docker搭建php开发环境

    php操作mysql数据库(增删改查)_docker搭建php开发环境【Mysqli面向对象方式操作数据库】 添加、修改、删除数据 $mysqli = new mysqli('localhost','root','123456&#

    2023-01-23
    146
  • 读MySQL5.7 官方文档11.3.2 The CHAR and VARCHAR Types章节的总结「建议收藏」

    读MySQL5.7 官方文档11.3.2 The CHAR and VARCHAR Types章节的总结「建议收藏」作者:魏新平,知数堂第5期MySQL实战班学员,第10期MySQL优化班学员,现任职助教。 varchar(n) 和char(n)的最大长度 相信作为dba,经常会被问到这个问题吧。那什么是最大长度…

    2023-02-05
    151
  • 转:Oracle认证考券延期声明

    转:Oracle认证考券延期声明致广大Oracle认证(中国区)的考生们: 由于近期受疫情的影响,Pearson VUE暂时关闭了中国大陆的考试中心,并暂停至 2020 年 3 月底。 在此特殊阶段,针对无法预约并即将过期的考试券…

    2023-02-03
    157
  • iGear 用了这个小魔法,模型训练速度提升 300%[通俗易懂]

    iGear 用了这个小魔法,模型训练速度提升 300%[通俗易懂]一个高精度AI模型离不开大量的优质数据集,这些数据集往往由标注结果文件和海量的图片组成。在数据量比较大的情况下,模型训练周期也会相应加长。那么有什么加快训练速度的好方法呢? 壕气的老板第一时间想到的通

    2023-05-05
    144
  • 使用Pycharm多行注释的快捷键

    使用Pycharm多行注释的快捷键Python是一种高级编程语言,其可读性和易于理解占据了开发者心中的一席之地。然而,在Python项目中,正确的注释是一个必不可少的部分。Pycharm是一种被广泛使用的IDE(集成开发环境),它提供了各种不同类型的注释。本文所介绍的是Pycharm多行注释的快捷键。我们将详细介绍如何在Pycharm中使用快捷键来在你的代码中添加多行注释。

    2024-06-22
    36
  • Python中将元组转换为列表的方法

    Python中将元组转换为列表的方法Python中元组(tuple)和列表(list)是两种具有不同性质的序列类型。在某些情况下,需要将元组转换为列表,因为列表在某些操作中具有更好的可变性和处理性能。本文将详细介绍Python中将元组转换为列表的方法,包括使用列表解析、使用typecasting、使用extend方法、使用list构造函数以及使用循环遍历等方法。

    2024-03-26
    89

发表回复

您的电子邮箱地址不会被公开。 必填项已用*标注