一键安装KES-RWC读写分离集群

  • 一、KES-RWC读写分离集群介绍

金仓数据库读写分离集群软件在金仓数据守护集群软件的基础上增加了对应用透明的读写负载均衡能力。该类集群中所有备库均可对外提供查询能力,从而减轻了主库的读负载压力,可实现更高的事务吞吐率;该软件支持在多个备库间进行读负载均衡。

其成员可能包括主节点(primary node)、备节点(standby node)、辅助节点(witness node)、备份节点(repo node)。

主要特征 ¶

1)丰富的同步模式

集群可根据业务数据保护级别灵活支持多种数据复制模式。比如:实时(sync)模式、异步(async)模式、优选同步(quorum)模式。

2)高效切换

集群支持便捷高效的主备集群切换,切换过程仅需秒级完成。对计划内维护等切换需求提供了高效灵活的实施方法。

3)全面数据保护

集群内的任意一个备库均为一个完整的冗余数据库,且可以同时配置多个备库,为数据安全提供全方位的保护。

4)平衡资源负载

集群内的任意一个备库均可配置为读访问,支持用户访问备库,执行查询、报表统计分析、作为ETL数据源进行数据抽取,减轻主库的系统负载,提升资源利用率。

5)故障转移

当主库(计划外)发生故障时,集群支持自动切换,实现了库级和中心级的自动容灾功能。

6)强大的业务连续性保障机制

集群引入VIP设计,VIP将始终运行于主库服务器,当主库或主库所在服务器发生故障,VIP将自动随数据库切换而漂移(至新主库服务器)。极大地保障了业务系统的连续性。

7)多种自动恢复模式

集群可以配置不同的自动恢复模式来处理故障数据库,满足用户不同层次的需求,包括:关闭自动恢复功能,自动恢复备数据库,自动恢复主数据。

  • 二、环境规划
ip 操作系统 内存 CPU 网卡 硬盘
192.168.150.125

CentOS 7.9

6G 4c 1 150G
192.168.150126 CentOS 7.9 6G 4c 1 150G

安装目录

HOME目录:/Kingbase/ES/

DATA目录:/Kingbase/ES/V9/data

  • 三、安装前准备

两个节点都需要调整

1、关闭防火墙和selinux

systemctl stop firewalld.service

systemctl disable firewalld.service

setenforce 0

sed -i 's/^SELINUX=enforcing$/SELINUX=disabled/' /etc/selinux/config

2、修改hosts

host_ip=$(ip addr | grep inet | grep ens33 | awk '{print $2}' | awk -F/ '{print $1}')

echo "$host_ip `hostname`" >> /etc/hosts

3、配置内核参数sysctl.conf

直接计算输出到sysctl.conf

memTotal=$(grep MemTotal /proc/meminfo | awk '{print $2}')

totalMemory=$((memTotal / 2048))

shmall=$((memTotal / 4))

if [ $shmall -lt 2097152 ]; then

shmall=2097152

fi

shmmax=$((memTotal * 1024 - 1))

if [ "$shmmax" -lt 4294967295 ]; then

shmmax=4294967295

fi

cat <>/etc/sysctl.conf

fs.aio-max-nr = 1048576

fs.file-max = 6815744

kernel.shmall = $shmall

kernel.shmmax = $shmmax

kernel.shmmni = 4096

kernel.sem = 250 32000 100 128

net.ipv4.ip_local_port_range = 9000 65500

net.core.rmem_default = 262144

net.core.rmem_max = 4194304

net.core.wmem_default = 262144

net.core.wmem_max = 1048576

net.ipv4.conf.eth0.rp_filter = 1

net.ipv4.conf.eth1.rp_filter = 2

EOF

4、配置资源参数limits.conf

cat >>/etc/security/limits.conf < * soft nofile 65536
* hard nofile 65535
* soft nproc 65536
* hard nproc 65535
* soft core unlimited
* hard core unlimited
EOF

5、创建用户和目录

useradd -m kingbase

echo "king123" | passwd --stdin kingbase

mkdir -p /Kingbase/ES/V9/server

mkdir /Kingbase/ES/V9/data

chown -R kingbase:kingbase /Kingbase

mkdir /Kingbase/install

6、配置环境变量

cat >>.bash_profile< export PATH=/Kingbase/ES/V9/Server/bin:\$PATH
export KINGBASE_DATA=/Kingbase/ES/V9/data
EOF

7、通用机环境准备

在两台集群主机中主节点安装单机数据库,单机版安装不在赘述

可参考:https://bbs.kingbase.com.cn/blogDetail?postsId=3d659c893da7930d3ab002f1c193da67

重温金仓数据库安装-Kingbase v9-centos - 墨天轮

  • 四、实施安装

1、获取集群部署所需文件

安装成功后,在${install_dir}/ClientTools/guitools/DeployTools/zip/目录下获取如下文件,《如上步骤7》

db.zip #数据库服务器压缩包 

cluster_install.sh #部署脚本 

install.conf #部署配置文件 

trust_cluster.sh #配置SSH免密脚本

[root@localhost zip]# pwd
/Kingbase/ES/V9/KESRealPro/V009R001C001B0030/ClientTools/guitools/DeployTools/zip
[root@localhost zip]# tree
.
|-- cluster_install.sh
|-- db.zip
|-- install.conf
|-- securecmdd.zip
`-- trust_cluster.sh

一键安装KES-RWC读写分离集群_第1张图片

2、拷贝文件到安装介质目录

[root@localhost zip]# cp * /Kingbase/install/
[root@localhost zip]# cd /Kingbase/install/
[root@localhost install]# tree
.
|-- cluster_install.sh
|-- db.zip
|-- install.conf
|-- securecmdd.zip
`-- trust_cluster.sh

0 directories, 5 files

3、配置 install.conf

主要修改如下

详细可参考官方文档:https://bbs.kingbase.com.cn/docHtml?recId=d3b047761988fde0084a665fc7151c47&url=aHR0cHM6Ly9iYnMua2luZ2Jhc2UuY29tLmNuL2tpbmdiYXNlLWRvYy92OC9hZG1pbi9yZWZlcmVuY2UvcmVmLWRhdGFiYXNlLXBhcmFtZXRlci9zdGF0aWMtZGF0YS1kaWN0aW9uYXJ5L2NvbXBhdGliaWxpdHktdmlldy1vdmVydmlldy5odG1sI3YtbWV0cmlj

all_ip=(192.168.150.125 192.168.150.126)

install_dir="/Kingbase/ES"

zip_package="/Kingbase/install//db.zip"

trusted_servers="192.168.150.127"

data_directory="/Kingbase/ES/V9/data"

trusted_servers="192.168.150.1"

4、SSH 免密配置

执行 sh trust_cluster.sh进行免密配置,需要用root去执行

[root@localhost install]# sh trust_cluster.sh
Generating public/private rsa key pair.
Created directory '/root/.ssh'.
Your identification has been saved in /root/.ssh/id_rsa.
Your public key has been saved in /root/.ssh/id_rsa.pub.
The key fingerprint is:
SHA256:9khbzX+P60L93o7+FsK7WZRYu52pnR2EfpANjBtUAGg [email protected]
The key's randomart image is:
+---[RSA 2048]----+
| ...oo. |
| E . o |
| . o o . |
| oo B o|
| S ..+* * |
| o = o+=.=|
| o .. .+O+|
| ..*+O|
| BBOB|
+----[SHA256]-----+
Warning: Permanently added '192.168.150.125' (ECDSA) to the list of known hosts.
[email protected]'s password:
id_rsa 100% 1675 1.6MB/s 00:00
id_rsa.pub 100% 408 18.1KB/s 00:00
authorized_keys 100% 408 404.1KB/s 00:00
known_hosts 100% 348 368.4KB/s 00:00
Warning: Permanently added '192.168.150.126' (ECDSA) to the list of known hosts.
[email protected]'s password:
id_rsa 100% 1675 1.8MB/s 00:00
id_rsa.pub 100% 408 593.7KB/s 00:00
authorized_keys 100% 408 819.6KB/s 00:00
known_hosts 100% 525 1.1MB/s 00:00

[root@localhost install]# sh trust_cluster.sh
Generating public/private rsa key pair.
Created directory '/root/.ssh'.
Your identification has been saved in /root/.ssh/id_rsa.
Your public key has been saved in /root/.ssh/id_rsa.pub.
The key fingerprint is:
SHA256:9khbzX+P60L93o7+FsK7WZRYu52pnR2EfpANjBtUAGg [email protected]
The key's randomart image is:
+---[RSA 2048]----+
| ...oo. |
| E . o |
| . o o . |
| oo B o|
| S ..+* * |
| o = o+=.=|
| o .. .+O+|
| ..*+O|
| BBOB|
+----[SHA256]-----+
Warning: Permanently added '192.168.150.125' (ECDSA) to the list of known hosts.
[email protected]'s password:
id_rsa 100% 1675 1.6MB/s 00:00
id_rsa.pub 100% 408 18.1KB/s 00:00
authorized_keys 100% 408 404.1KB/s 00:00
known_hosts 100% 348 368.4KB/s 00:00
Warning: Permanently added '192.168.150.126' (ECDSA) to the list of known hosts.
[email protected]'s password:
id_rsa 100% 1675 1.8MB/s 00:00
id_rsa.pub 100% 408 593.7KB/s 00:00
authorized_keys 100% 408 819.6KB/s 00:00

known_hosts 100% 525 1.1MB/s 00:00 

5、集群部署

执行sh cluster_install.sh 进行安装,用kingbase用户安装

[kingbase@rwc01 install]# sh cluster_install.sh
[CONFIG_CHECK] will deploy the cluster of DG
[CONFIG_CHECK] file format is correct ... OK
[CONFIG_CHECK] encoding: UTF8 OK
[CONFIG_CHECK] locale: zh_CN.UTF-8 OK
[CONFIG_CHECK] the number of license_num matches the length of all_ip or the number of license_num is 1 ... OK
[RUNNING] check if the host can be reached ...
[RUNNING] success connect to the target "192.168.150.125" ..... OK
[RUNNING] success connect to the target "192.168.150.126" ..... OK
[RUNNING] check the db is running or not...
[RUNNING] the db is not running on "192.168.150.125:54321" ..... OK
[RUNNING] the db is not running on "192.168.150.126:54321" ..... OK
[RUNNING] check the sys_securecmdd is running or not...
[RUNNING] the sys_securecmdd is not running on "192.168.150.125:8890" ..... OK
[RUNNING] the sys_securecmdd is not running on "192.168.150.126:8890" ..... OK
[RUNNING] check if the install dir is already exist ...
[RUNNING] the install dir is not exist on "192.168.150.125" ..... OK
[RUNNING] the install dir is not exist on "192.168.150.126" ..... OK
[RUNNING] check if the data directory is empty or not exist ...
[RUNNING] when use_exist_data=0, the data directory is empty or not exist on "192.168.150.125" ..... OK
[RUNNING] when use_exist_data=0, the data directory is empty or not exist on "192.168.150.126" ..... OK
2025-01-06 23:10:22 [INFO] start to check system parameters on 192.168.150.125 ...
2025-01-06 23:10:22 [WARNING] [GSSAPIAuthentication] yes (should be: no) on 192.168.150.125
2025-01-06 23:10:23 [INFO] [UseDNS] is null on 192.168.150.125
2025-01-06 23:10:23 [INFO] [UsePAM] yes on 192.168.150.125
2025-01-06 23:10:23 [ERROR] [ulimit.open files] 1024 (no less than: 65535) on 192.168.150.125
2025-01-06 23:10:23 [INFO] the value of [ulimit.open files] is wrong, now will change it on 192.168.150.125 ...
2025-01-06 23:10:23 [INFO] change ulimit.open files on 192.168.150.125 ...
2025-01-06 23:10:24 [INFO] change ulimit.open files on 192.168.150.125 ... Done
2025-01-06 23:10:24 [INFO] [ulimit.open files] 655360 on 192.168.150.125
2025-01-06 23:10:25 [ERROR] [ulimit.open proc] 23053 (no less than: 65535) on 192.168.150.125
2025-01-06 23:10:25 [INFO] the value of [ulimit.open proc] is wrong, now will change it on 192.168.150.125 ...
2025-01-06 23:10:25 [INFO] change ulimit.open proc on 192.168.150.125 ...
2025-01-06 23:10:25 [INFO] change ulimit.open proc on 192.168.150.125 ... Done
2025-01-06 23:10:26 [INFO] [ulimit.open proc] 655360 on 192.168.150.125
2025-01-06 23:10:26 [INFO] [ulimit.core size] 0 (no unlimited) on 192.168.150.125
2025-01-06 23:10:26 [INFO] the value of [ulimit.core size] is wrong, now will change it on 192.168.150.125 ...
2025-01-06 23:10:26 [INFO] change ulimit.core size on 192.168.150.125 ...
2025-01-06 23:10:27 [INFO] change ulimit.core size on 192.168.150.125 ... Done
2025-01-06 23:10:27 [INFO] [ulimit.core size] unlimited on 192.168.150.125
2025-01-06 23:10:27 [INFO] [ulimit.mem lock] 64 (less than 50000000) on 192.168.150.125
2025-01-06 23:10:27 [INFO] the value of [ulimit.mem lock] is wrong, now will change it on 192.168.150.125 ...
2025-01-06 23:10:28 [INFO] change ulimit.mem lock on 192.168.150.125 ...
2025-01-06 23:10:28 [INFO] change ulimit.mem lock on 192.168.150.125 ... Done
2025-01-06 23:10:28 [INFO] [ulimit.mem lock] 50000000 on 192.168.150.125
2025-01-06 23:10:29 [ERROR] [kernel.sem] 250 32000 32 128 (no less than: 5010 641280 5010 256) on 192.168.150.125
2025-01-06 23:10:29 [INFO] the value of [kernel.sem] is wrong, now will change it on 192.168.150.125 ...
2025-01-06 23:10:30 [INFO] change kernel.sem on 192.168.150.125 ...
2025-01-06 23:10:30 [INFO] change kernel.sem on 192.168.150.125 ... Done
2025-01-06 23:10:31 [INFO] [kernel.sem] 5010 641280 5010 256 on 192.168.150.125
2025-01-06 23:10:32 [WARNING] [RemoveIPC] is null on 192.168.150.125
2025-01-06 23:10:32 [INFO] the value of [RemoveIPC] is wrong, now will change it on 192.168.150.125 ...
2025-01-06 23:10:32 [INFO] change RemoveIPC on 192.168.150.125 ...
2025-01-06 23:10:33 [INFO] change RemoveIPC on 192.168.150.125 ... Done
2025-01-06 23:10:34 [INFO] [RemoveIPC] no on 192.168.150.125
2025-01-06 23:10:34 [INFO] [DefaultTasksAccounting] is null on 192.168.150.125
2025-01-06 23:10:35 [WARNING] [SELINUX] enforcing (should be: disabled or permissive) on 192.168.150.125
2025-01-06 23:10:36 [INFO] [firewall] down on 192.168.150.125
2025-01-06 23:10:36 [INFO] [The memory] OK on 192.168.150.125
2025-01-06 23:10:36 [INFO] [The hard disk] OK on 192.168.150.125
2025-01-06 23:10:37 [INFO] [ping command path] OK on 192.168.150.125
2025-01-06 23:10:37 [INFO] [/bin/cp --version] on 192.168.150.125 OK
2025-01-06 23:10:37 [INFO] [Virtual IP] Not configured on 192.168.150.125
2025-01-06 23:10:37 [INFO] start to check system parameters on 192.168.150.126 ...
2025-01-06 23:10:37 [WARNING] [GSSAPIAuthentication] yes (should be: no) on 192.168.150.126
2025-01-06 23:10:38 [INFO] [UseDNS] is null on 192.168.150.126
2025-01-06 23:10:38 [INFO] [UsePAM] yes on 192.168.150.126
2025-01-06 23:10:38 [ERROR] [ulimit.open files] 1024 (no less than: 65535) on 192.168.150.126
2025-01-06 23:10:38 [INFO] the value of [ulimit.open files] is wrong, now will change it on 192.168.150.126 ...
2025-01-06 23:10:38 [INFO] change ulimit.open files on 192.168.150.126 ...
2025-01-06 23:10:39 [INFO] change ulimit.open files on 192.168.150.126 ... Done
2025-01-06 23:10:39 [INFO] [ulimit.open files] 655360 on 192.168.150.126
2025-01-06 23:10:40 [ERROR] [ulimit.open proc] 23053 (no less than: 65535) on 192.168.150.126
2025-01-06 23:10:40 [INFO] the value of [ulimit.open proc] is wrong, now will change it on 192.168.150.126 ...
2025-01-06 23:10:40 [INFO] change ulimit.open proc on 192.168.150.126 ...
2025-01-06 23:10:40 [INFO] change ulimit.open proc on 192.168.150.126 ... Done
2025-01-06 23:10:41 [INFO] [ulimit.open proc] 655360 on 192.168.150.126
2025-01-06 23:10:41 [INFO] [ulimit.core size] 0 (no unlimited) on 192.168.150.126
2025-01-06 23:10:41 [INFO] the value of [ulimit.core size] is wrong, now will change it on 192.168.150.126 ...
2025-01-06 23:10:41 [INFO] change ulimit.core size on 192.168.150.126 ...
2025-01-06 23:10:42 [INFO] change ulimit.core size on 192.168.150.126 ... Done
2025-01-06 23:10:42 [INFO] [ulimit.core size] unlimited on 192.168.150.126
2025-01-06 23:10:42 [INFO] [ulimit.mem lock] 64 (less than 50000000) on 192.168.150.126
2025-01-06 23:10:42 [INFO] the value of [ulimit.mem lock] is wrong, now will change it on 192.168.150.126 ...
2025-01-06 23:10:43 [INFO] change ulimit.mem lock on 192.168.150.126 ...
2025-01-06 23:10:43 [INFO] change ulimit.mem lock on 192.168.150.126 ... Done
2025-01-06 23:10:43 [INFO] [ulimit.mem lock] 50000000 on 192.168.150.126
2025-01-06 23:10:45 [ERROR] [kernel.sem] 250 32000 32 128 (no less than: 5010 641280 5010 256) on 192.168.150.126
2025-01-06 23:10:45 [INFO] the value of [kernel.sem] is wrong, now will change it on 192.168.150.126 ...
2025-01-06 23:10:45 [INFO] change kernel.sem on 192.168.150.126 ...
2025-01-06 23:10:45 [INFO] change kernel.sem on 192.168.150.126 ... Done
2025-01-06 23:10:47 [INFO] [kernel.sem] 5010 641280 5010 256 on 192.168.150.126
2025-01-06 23:10:47 [WARNING] [RemoveIPC] is null on 192.168.150.126
2025-01-06 23:10:47 [INFO] the value of [RemoveIPC] is wrong, now will change it on 192.168.150.126 ...
2025-01-06 23:10:47 [INFO] change RemoveIPC on 192.168.150.126 ...
2025-01-06 23:10:48 [INFO] change RemoveIPC on 192.168.150.126 ... Done
2025-01-06 23:10:49 [INFO] [RemoveIPC] no on 192.168.150.126
2025-01-06 23:10:49 [INFO] [DefaultTasksAccounting] is null on 192.168.150.126
2025-01-06 23:10:50 [WARNING] [SELINUX] enforcing (should be: disabled or permissive) on 192.168.150.126
2025-01-06 23:10:51 [INFO] [firewall] down on 192.168.150.126
2025-01-06 23:10:52 [INFO] [The memory] OK on 192.168.150.126
2025-01-06 23:10:52 [INFO] [The hard disk] OK on 192.168.150.126
2025-01-06 23:10:52 [INFO] [ping command path] OK on 192.168.150.126
2025-01-06 23:10:53 [INFO] [/bin/cp --version] on 192.168.150.126 OK
2025-01-06 23:10:53 [INFO] [Virtual IP] Not configured on 192.168.150.126
[INSTALL] create the install dir "/Kingbase/ES/kingbase" on every host ...
[INSTALL] success to create the install dir "/Kingbase/ES/kingbase" on "192.168.150.125" ..... OK
[INSTALL] success to create the install dir "/Kingbase/ES/kingbase" on "192.168.150.126" ..... OK
[INSTALL] success to access the zip_package "/Kingbase/install//db.zip" on "192.168.150.125" ..... OK
[INSTALL] decompress the "/Kingbase/install//db.zip" to "/Kingbase/ES/kingbase/__tmp_decompress__"
[INSTALL] success to recreate the tmp dir "/Kingbase/ES/kingbase/__tmp_decompress__" on "192.168.150.125" ..... OK
[INSTALL] success to decompress the "/Kingbase/install//db.zip" to "/Kingbase/ES/kingbase/__tmp_decompress__" on "192.168.150.125"..... OK
[INSTALL] scp the dir "/Kingbase/ES/kingbase/__tmp_decompress__" to "/Kingbase/ES/kingbase" on all host
[INSTALL] try to copy the install dir "/Kingbase/ES/kingbase" to "192.168.150.125" .....
[INSTALL] success to scp the install dir "/Kingbase/ES/kingbase" to "192.168.150.125" ..... OK
[INSTALL] try to copy the install dir "/Kingbase/ES/kingbase" to "192.168.150.126" .....
[INSTALL] success to scp the install dir "/Kingbase/ES/kingbase" to "192.168.150.126" ..... OK
[INSTALL] remove the dir "/Kingbase/ES/kingbase/__tmp_decompress__"
[INSTALL] change the auth of bin directory on 192.168.150.125 ...
[INSTALL] change the auth of bin directory on 192.168.150.126 ...
[INSTALL] check license_file ...
[INSTALL] success to access license_file on 192.168.150.125: /Kingbase/ES/kingbase/bin/license.dat
[INSTALL] check license_file ...
[INSTALL] success to access license_file on 192.168.150.126: /Kingbase/ES/kingbase/bin/license.dat
[INSTALL] create the dir "/Kingbase/ES/kingbase/etc" on all host
[RUNNING] config sys_securecmdd and start it ...
[RUNNING] config the sys_securecmdd port to 8890 ...
[RUNNING] success to config the sys_securecmdd port on 192.168.150.125 ... OK
successfully initialized the sys_securecmdd, please use "/Kingbase/ES/kingbase/bin/sys_HAscmdd.sh start" to start the sys_securecmdd
[RUNNING] success to config sys_securecmdd on 192.168.150.125 ... OK
Created symlink from /etc/systemd/system/multi-user.target.wants/securecmdd.service to /etc/systemd/system/securecmdd.service.
[RUNNING] success to start sys_securecmdd on 192.168.150.125 ... OK
[RUNNING] config sys_securecmdd and start it ...
[RUNNING] config the sys_securecmdd port to 8890 ...
[RUNNING] success to config the sys_securecmdd port on 192.168.150.126 ... OK
successfully initialized the sys_securecmdd, please use "/Kingbase/ES/kingbase/bin/sys_HAscmdd.sh start" to start the sys_securecmdd
[RUNNING] success to config sys_securecmdd on 192.168.150.126 ... OK
Created symlink from /etc/systemd/system/multi-user.target.wants/securecmdd.service to /etc/systemd/system/securecmdd.service.
[RUNNING] success to start sys_securecmdd on 192.168.150.126 ... OK
[RUNNING] check if the host can be reached between all nodes ...
[RUNNING] success connect to "192.168.150.125" from current node by 'ssh' ..... OK
[RUNNING] success connect to "192.168.150.125" from "192.168.150.125" by '/Kingbase/ES/kingbase/bin/sys_securecmd' ..... OK
[RUNNING] success connect to "192.168.150.126" from "192.168.150.125" by '/Kingbase/ES/kingbase/bin/sys_securecmd' ..... OK
[RUNNING] success connect to "192.168.150.126" from current node by 'ssh' ..... OK
[RUNNING] success connect to "192.168.150.125" from "192.168.150.126" by '/Kingbase/ES/kingbase/bin/sys_securecmd' ..... OK
[RUNNING] success connect to "192.168.150.126" from "192.168.150.126" by '/Kingbase/ES/kingbase/bin/sys_securecmd' ..... OK
[INSTALL] begin to init the database on "192.168.150.125" ...
The database cluster will be initialized with locales
COLLATE: zh_CN.UTF-8
CTYPE: zh_CN.UTF-8
MESSAGES: C
MONETARY: zh_CN.UTF-8
NUMERIC: zh_CN.UTF-8
TIME: zh_CN.UTF-8
The files belonging to this database system will be owned by user "kingbase".
This user must also own the server process.

The default text search configuration will be set to "simple".

The comparision of strings is case-sensitive.
Data page checksums are enabled.

creating directory /Kingbase/ES/kingbase/data ... ok
creating subdirectories ... ok
selecting dynamic shared memory implementation ... initdb: could not find suitable text search configuration for locale "zh_CN.UTF-8"
posix
selecting default max_connections ... 100
selecting default shared_buffers ... 128MB
selecting default time zone ... Asia/Shanghai
creating configuration files ... ok
Begin setup encrypt device
initializing the encrypt device ... ok
running bootstrap script ... ok
performing post-bootstrap initialization ... ok
create security database ... ok
load security database ... ok
syncing data to disk ... ok

Success. You can now start the database server using:

/Kingbase/ES/kingbase/bin/sys_ctl -D /Kingbase/ES/kingbase/data -l logfile start

[INSTALL] end to init the database on "192.168.150.125" ... OK
[INSTALL] wirte the kingbase.conf on "192.168.150.125" ...
[INSTALL] wirte the kingbase.conf on "192.168.150.125" ... OK
[INSTALL] wirte the es_rep.conf on "192.168.150.125" ...
[INSTALL] wirte the es_rep.conf on "192.168.150.125" ... OK
[INSTALL] wirte the sys_hba.conf on "192.168.150.125" ...
[INSTALL] wirte the sys_hba.conf on "192.168.150.125" ... OK
[INSTALL] wirte the .encpwd on every host
[INSTALL] write the repmgr.conf on every host
[INSTALL] write the repmgr.conf on "192.168.150.125" ...
[INSTALL] write the repmgr.conf on "192.168.150.125" ... OK
[INSTALL] write the repmgr.conf on "192.168.150.126" ...
[INSTALL] write the repmgr.conf on "192.168.150.126" ... OK
[INSTALL] start up the database on "192.168.150.125" ...
[INSTALL] /Kingbase/ES/kingbase/bin/sys_ctl -w -t 60 -l /Kingbase/ES/kingbase/logfile -D /Kingbase/ES/kingbase/data start
waiting for server to start.... done
server started
[INSTALL] start up the database on "192.168.150.125" ... OK
[INSTALL] create the database "esrep" and user "esrep" for repmgr ...
CREATE DATABASE
CREATE ROLE
GRANT
GRANT ROLE
[INSTALL] create the database "esrep" and user "esrep" for repmgr ... OK
[INSTALL] register the primary on "192.168.150.125" ...
[INFO] connecting to primary database...
[NOTICE] attempting to install extension "repmgr"
[NOTICE] "repmgr" extension successfully installed
[NOTICE] primary node record (ID: 1) registered
[INSTALL] register the primary on "192.168.150.125" ... OK
[INSTALL] clone and start up the standby ...
clone the standby on "192.168.150.126" ...
/Kingbase/ES/kingbase/bin/repmgr -h 192.168.150.125 -U esrep -d esrep -p 54321 --fast-checkpoint --upstream-node-id 1 standby clone
[NOTICE] destination directory "/Kingbase/ES/kingbase/data" provided
[INFO] connecting to source node
[DETAIL] connection string is: host=192.168.150.125 user=esrep port=54321 dbname=esrep
[DETAIL] current installation size is 85 MB
[NOTICE] checking for available walsenders on the source node (2 required)
[NOTICE] checking replication connections can be made to the source server (2 required)
[INFO] creating directory "/Kingbase/ES/kingbase/data"...
[INFO] creating replication slot as user "esrep"
[NOTICE] starting backup (using sys_basebackup)...
[INFO] executing:
/Kingbase/ES/kingbase/bin/sys_basebackup -l "repmgr base backup" -D /Kingbase/ES/kingbase/data -h 192.168.150.125 -p 54321 -U esrep -c fast -X stream -S repmgr_slot_2
[NOTICE] standby clone (using sys_basebackup) complete
[NOTICE] you can now start your Kingbase server
[HINT] for example: sys_ctl -D /Kingbase/ES/kingbase/data start
[HINT] after starting the server, you need to register this standby with "repmgr standby register"
clone the standby on "192.168.150.126" ... OK
start up the standby on "192.168.150.126" ...
/Kingbase/ES/kingbase/bin/sys_ctl -w -t 60 -l /Kingbase/ES/kingbase/logfile -D /Kingbase/ES/kingbase/data start
waiting for server to start.... done
server started
start up the standby on "192.168.150.126" ... OK
register the standby on "192.168.150.126" ...
[INFO] connecting to local node "node2" (ID: 2)
[INFO] connecting to primary database
[INFO] standby registration complete
[NOTICE] standby node "node2" (ID: 2) successfully registered
[INSTALL] register the standby on "192.168.150.126" ... OK
[INSTALL] start up the whole cluster ...
2025-01-06 23:13:02 Ready to start all DB ...
2025-01-06 23:13:02 begin to start DB on "[192.168.150.125]".
2025-01-06 23:13:03 DB on "[192.168.150.125]" already started, connect to check it.
2025-01-06 23:13:04 DB on "[192.168.150.125]" start success.
2025-01-06 23:13:04 Try to ping trusted_servers on host 192.168.150.125 ...
2025-01-06 23:13:07 Try to ping trusted_servers on host 192.168.150.126 ...
2025-01-06 23:13:10 begin to start DB on "[192.168.150.126]".
2025-01-06 23:13:11 DB on "[192.168.150.126]" already started, connect to check it.
2025-01-06 23:13:12 DB on "[192.168.150.126]" start success.
ID | Name | Role | Status | Upstream | Location | Priority | Timeline | LSN_Lag | Connection string
----+-------+---------+-----------+----------+----------+----------+----------+---------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------
1 | node1 | primary | * running | | default | 100 | 1 | | host=192.168.150.125 user=esrep dbname=esrep port=54321 connect_timeout=10 keepalives=1 keepalives_idle=2 keepalives_interval=2 keepalives_count=3 tcp_user_timeout=9000
2 | node2 | standby | running | node1 | default | 100 | 1 | 0 bytes | host=192.168.150.126 user=esrep dbname=esrep port=54321 connect_timeout=10 keepalives=1 keepalives_idle=2 keepalives_interval=2 keepalives_count=3 tcp_user_timeout=9000
2025-01-06 23:13:12 The primary DB is started.
2025-01-06 23:13:12 begin to start repmgrd on "[192.168.150.125]".
[2025-01-06 23:13:13] [NOTICE] using provided configuration file "/Kingbase/ES/kingbase/bin/../etc/repmgr.conf"
[2025-01-06 23:13:13] [NOTICE] redirecting logging output to "/Kingbase/ES/kingbase/log/hamgr.log"

2025-01-06 23:13:15 repmgrd on "[192.168.150.125]" start success.
2025-01-06 23:13:15 begin to start repmgrd on "[192.168.150.126]".
[2025-01-06 23:13:15] [NOTICE] using provided configuration file "/Kingbase/ES/kingbase/bin/../etc/repmgr.conf"
[2025-01-06 23:13:15] [NOTICE] redirecting logging output to "/Kingbase/ES/kingbase/log/hamgr.log"

2025-01-06 23:13:17 repmgrd on "[192.168.150.126]" start success.
ID | Name | Role | Status | Upstream | repmgrd | PID | Paused? | Upstream last seen
----+-------+---------+-----------+----------+---------+------+---------+--------------------
1 | node1 | primary | * running | | running | 7078 | no | n/a
2 | node2 | standby | running | node1 | running | 3380 | no | 1 second(s) ago
[2025-01-06 23:13:19] [NOTICE] redirecting logging output to "/Kingbase/ES/kingbase/log/kbha.log"

[2025-01-06 23:13:22] [NOTICE] redirecting logging output to "/Kingbase/ES/kingbase/log/kbha.log"

2025-01-06 23:13:23 Done.
[INSTALL] start up the whole cluster ... OK

6、安装后检查

[kingbase@yac01 ~]$ /Kingbase/ES/kingbase/bin/repmgr cluster show
ID | Name | Role | Status | Upstream | Location | Priority | Timeline | LSN_Lag | Connection string
----+-------+---------+-----------+----------+----------+----------+----------+---------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------
1 | node1 | primary | * running | | default | 100 | 1 | | host=192.168.150.125 user=esrep dbname=esrep port=54321 connect_timeout=10 keepalives=1 keepalives_idle=2 keepalives_interval=2 keepalives_count=3 tcp_user_timeout=9000
2 | node2 | standby | running | node1 | default | 100 | 1 | 0 bytes | host=192.168.150.126 user=esrep dbname=esrep port=54321 connect_timeout=10 keepalives=1 keepalives_idle=2 keepalives_interval=2 keepalives_count=3 tcp_user_timeout=9000

7、设置环境变量

vi .bash_profile

#添加

export PATH=/Kingbase/ES/kingbase/bin:$PATH

一键安装KES-RWC读写分离集群_第2张图片

  • 五、集群常用命令

1、查用命令

特别提示:/Kingbase/ES/kingbase/bin/为集群安装目录,也可以进入目录./执行

#集群状态检查

/Kingbase/ES/kingbase/bin/repmgr cluster show

#一键集群启停

/Kingbase/ES/kingbase/bin/sys_monitor.sh stop

/Kingbase/ES/kingbase/bin/sys_monitor.sh start

#集群同步状态检查

select client_addr,write_lsn,flush_lsn,replay_lsn,sync_state,sync_priority from sys_stat_replication;

#集群角色检查

/Kingbase/ES/kingbase/bin/repmgr service status

#集群主备切换

/Kingbase/ES/kingbase/bin/repmgr standby switchover --siblings-follow

2、操作日志

附上操作日志可以对比自己环境

[kingbase@rwc01 ~]$ /Kingbase/ES/kingbase/bin/repmgr cluster show
ID | Name | Role | Status | Upstream | Location | Priority | Timeline | LSN_Lag | Connection string
----+-------+---------+-----------+----------+----------+----------+----------+---------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------
1 | node1 | primary | * running | | default | 100 | 1 | | host=192.168.150.125 user=esrep dbname=esrep port=54321 connect_timeout=10 keepalives=1 keepalives_idle=2 keepalives_interval=2 keepalives_count=3 tcp_user_timeout=9000
2 | node2 | standby | running | node1 | default | 100 | 1 | 0 bytes | host=192.168.150.126 user=esrep dbname=esrep port=54321 connect_timeout=10 keepalives=1 keepalives_idle=2 keepalives_interval=2 keepalives_count=3 tcp_user_timeout=9000
[kingbase@rwc01 ~]$ /Kingbase/ES/kingbase/bin/sys_monitor.sh stop
2025-01-06 23:24:57 Ready to stop all DB ...
2025-01-06 23:25:04 begin to stop repmgrd on "[192.168.150.125]".
2025-01-06 23:25:05 repmgrd on "[192.168.150.125]" stop success.
2025-01-06 23:25:05 begin to stop repmgrd on "[192.168.150.126]".
2025-01-06 23:25:07 repmgrd on "[192.168.150.126]" stop success.
2025-01-06 23:25:07 begin to stop DB on "[192.168.150.126]".
waiting for server to shut down.... done
server stopped
2025-01-06 23:25:07 DB on "[192.168.150.126]" stop success.
2025-01-06 23:25:07 begin to stop DB on "[192.168.150.125]".
waiting for server to shut down.... done
server stopped
2025-01-06 23:25:08 DB on "[192.168.150.125]" stop success.
2025-01-06 23:25:08 Done.
[kingbase@rwc01 ~]$ /Kingbase/ES/kingbase/bin/sys_monitor.sh start
2025-01-06 23:25:23 Ready to start all DB ...
2025-01-06 23:25:23 begin to start DB on "[192.168.150.125]".
waiting for server to start.... done
server started
2025-01-06 23:25:24 execute to start DB on "[192.168.150.125]" success, connect to check it.
2025-01-06 23:25:25 DB on "[192.168.150.125]" start success.
2025-01-06 23:25:25 Try to ping trusted_servers on host 192.168.150.125 ...
2025-01-06 23:25:28 Try to ping trusted_servers on host 192.168.150.126 ...
2025-01-06 23:25:31 begin to start DB on "[192.168.150.126]".
waiting for server to start.... done
server started
2025-01-06 23:25:32 execute to start DB on "[192.168.150.126]" success, connect to check it.
2025-01-06 23:25:33 DB on "[192.168.150.126]" start success.
ID | Name | Role | Status | Upstream | Location | Priority | Timeline | LSN_Lag | Connection string
----+-------+---------+-----------+----------+----------+----------+----------+---------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------
1 | node1 | primary | * running | | default | 100 | 1 | | host=192.168.150.125 user=esrep dbname=esrep port=54321 connect_timeout=10 keepalives=1 keepalives_idle=2 keepalives_interval=2 keepalives_count=3 tcp_user_timeout=9000
2 | node2 | standby | running | node1 | default | 100 | 1 | 0 bytes | host=192.168.150.126 user=esrep dbname=esrep port=54321 connect_timeout=10 keepalives=1 keepalives_idle=2 keepalives_interval=2 keepalives_count=3 tcp_user_timeout=9000
2025-01-06 23:25:33 The primary DB is started.
2025-01-06 23:25:33 begin to start repmgrd on "[192.168.150.125]".
[2025-01-06 23:25:34] [NOTICE] using provided configuration file "/Kingbase/ES/kingbase/bin/../etc/repmgr.conf"
[2025-01-06 23:25:34] [NOTICE] redirecting logging output to "/Kingbase/ES/kingbase/log/hamgr.log"

2025-01-06 23:25:36 repmgrd on "[192.168.150.125]" start success.
2025-01-06 23:25:36 begin to start repmgrd on "[192.168.150.126]".
[2025-01-06 23:25:37] [NOTICE] using provided configuration file "/Kingbase/ES/kingbase/bin/../etc/repmgr.conf"
[2025-01-06 23:25:37] [NOTICE] redirecting logging output to "/Kingbase/ES/kingbase/log/hamgr.log"

2025-01-06 23:25:39 repmgrd on "[192.168.150.126]" start success.
ID | Name | Role | Status | Upstream | repmgrd | PID | Paused? | Upstream last seen
----+-------+---------+-----------+----------+---------+------+---------+--------------------
1 | node1 | primary | * running | | running | 9822 | no | n/a
2 | node2 | standby | running | node1 | running | 5108 | no | 1 second(s) ago
[2025-01-06 23:25:43] [NOTICE] redirecting logging output to "/Kingbase/ES/kingbase/log/kbha.log"

[2025-01-06 23:25:47] [NOTICE] redirecting logging output to "/Kingbase/ES/kingbase/log/kbha.log"

2025-01-06 23:25:48 Done.
[kingbase@rwc01 ~]$ /Kingbase/ES/kingbase/bin/repmgr service status
ID | Name | Role | Status | Upstream | repmgrd | PID | Paused? | Upstream last seen
----+-------+---------+-----------+----------+---------+------+---------+--------------------
1 | node1 | primary | * running | | running | 9822 | no | n/a
2 | node2 | standby | running | node1 | running | 5108 | no | 0 second(s) ago  

[kingbase@rwc01 data]$ ksql -U system -dtest
Type "help" for help.

test=#
test=# select client_addr,write_lsn,flush_lsn,replay_lsn,sync_state,sync_priority from sys_stat_replication;
client_addr | write_lsn | flush_lsn | replay_lsn | sync_state | sync_priority
-----------------+-----------+-----------+------------+------------+---------------
192.168.150.126 | 0/7000420 | 0/7000420 | 0/7000420 | quorum | 1
(1 row)

  • 六、总结

今天在自己虚拟机准备了一套KES-RWC读写分离集群,一键脚本部署,整体比较简单,一键脚本部署KES-RWC读写分离集群,不仅提高了部署效率,还降低了技术门槛,使得更多的用户能够轻松地搭建和管理自己的数据库集群

你可能感兴趣的:(kingbase,人大金仓)