项目需求
将现有一主一备集群(192.168.40.107 ,192.168.40.160)扩容为一主两备,192.168.40.161节点为复用节点(另以集群缩容拆解的节点)
扩容前准备
检查现有集群状态
在集群任意节点执行命令"repmgr service status",建议使用repmgr cluster show 查看集群状态,可以看到ip地址、端口等信息。
--查看集群节点信息
[kingbase@node1 ~]$ 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.40.107 user=esrep dbname=esrep port=25432 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.40.160 user=esrep dbname=esrep port=25432 connect_timeout=10 keepalives=1 keepalives_idle=2 keepalives_interval=2 keepalives_count=3 tcp_user_timeout=9000
--查看集群组件信息
[kingbase@node1 ~]$ repmgr service status
ID | Name | Role | Status | Upstream | repmgrd | PID | Paused? | Upstream last seen
----+-------+---------+-----------+----------+---------+-------+---------+--------------------
1 | node1 | primary | * running | | running | 22792 | no | n/a
2 | node2 | standby | running | node1 | running | 7300 | no | 1 second(s) ago检查现有集群基本信息
安装目录:/kdb/kingbase/cluster/kingbase
数据目录:/data/kingbase/db_platform
ssh端口:22
scmd端口:8890
--查看进程
[root@node1 ~]# ps -ef | grep '\-D' | grep -v 'grep'
root 1018 1 0 09:35 ? 00:00:00 /usr/sbin/sshd -D
kingbase 22233 1 0 10:12 ? 00:00:03 /kdb/kingbase/cluster/kingbase/kingbase/bin/kingbase -D /data/kingbase/db_platform
[root@node1 ~]# ps -ef | grep 'repmgr' | grep -v 'grep'
kingbase 22792 1 0 10:13 ? 00:00:08 /kdb/kingbase/cluster/kingbase/kingbase/bin/repmgrd -d -v -f /kdb/kingbase/cluster/kingbase/kingbase/bin/../etc/repmgr.conf
kingbase 22954 1 0 10:13 ? 00:00:06 /kdb/kingbase/cluster/kingbase/kingbase/bin/kbha -A daemon -f /kdb/kingbase/cluster/kingbase/kingbase/bin/../etc/repmgr.conf
[root@node1 ~]# cat /kdb/kingbase/cluster/kingbase/kingbase/bin/../etc/repmgr.conf | grep scmd
use_scmd=on
scmd_options='-q -o ConnectTimeout=10 -o StrictHostKeyChecking=no -p 8890 -o ServerAliveInterval=2 -o ServerAliveCountMax=3'
[root@node1 ~]# netstat -ntlp | grep ssh
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 1018/sshd
tcp6 0 0 :::22 :::* LISTEN 1018/sshd原缩容节点环境清理(可选)
本文档是利用先前已经成功缩容的数据节点上再次将该节点扩容到现有集群,所以需要先移除原有的 archive目录、log目录、data目录下的所有内容;如果是新服务器可跳过该步骤。
cd /kdb/kingbase
mv cluster cluster_bak260213
cd /data/kingbase/
mv db_platform db_platform_bak260213扩容节点
约束条件
- 待扩容节点需要配置互信
- 扩容节点需要与原集群节点具有相同的操作系统环境,并且数据库版本一致
- 在已经成功缩容集群后,如果需要在同一个节点再次扩容节点,同样请先移除原有的 archive目录、log目录、data目录下的所有内容;
- 扩容前,需保证集群状态正常。
基本信息收集
扩容节点软件包目录、安装目录、数据目录和现有数据节点尽量保持一致,方便后面运维。
参数信息 | 值 |
软件包目录 | /home/kingbase/software |
软件安装路径 | /kdb/kingbase/cluster/kingbase |
主节点IP | 192.168.40.107 |
备节点IP | 192.168.40.160 |
待扩容节点IP | 192.168.40.161 |
VIP | 192.168.40.155 |
集群安装用户 | kingbase |
操作系统管理员用户 | root |
安装前检查与配置(可选)
说明:待扩容的服务器如果是新服务器需要操作,如果非新服务器需要检查
检查CPU: lscpu
查看操作系统: cat /etc/os_release
检查磁盘: df -Th
检查操作系统时间date (主备节点都执行)
关闭防火墙(有时候不关闭防火墙,配置端口连接)
--查看防火墙状态
systemctl status firewalld.service
--关闭防火墙
systemctl stop firewalld.service
--禁用防火墙
systemctl disable firewalld.service 禁用selinux
vim /etc/selinux/config SELINUX=disabled修改系统参数
编辑/etc/security/limits.conf 文件,追加以下内容
[root@node1 ~]# vim /etc/security/limits.conf
root soft nofile 655360
root hard nofile 655360
root soft nproc 655360
root hard nproc 655360
root soft memlock 50000000
root hard memlock 50000000
root soft core unlimited
root hard core unlimited
kingbase soft nofile 655360
kingbase hard nofile 655360
kingbase soft nproc 655360
kingbase hard nproc 655360
kingbase soft memlock 50000000
kingbase hard memlock 50000000
kingbase soft core unlimited
kingbase hard core unlimited编辑/etc/sysctl.conf 文件,追加以下内容
[root@node1 ~]# vi /etc/sysctl.conf
kernel.sem = 50100 64128000 50100 1280
# 释放time_wait链接
net.ipv4.tcp_syncookies = 1
net.ipv4.tcp_tw_reuse = 1
#net.ipv4.tcp_tw_recycle = 1
net.ipv4.tcp_timestamps= 1
net.ipv4.tcp_fin_timeout = 30
# TCP端口使用范围
net.ipv4.tcp_keepalive_time = 1200
net.ipv4.tcp_keepalive_probes = 3
net.ipv4.tcp_keepalive_intvl = 30
net.ipv4.ip_local_port_range = 10000 65000
net.ipv4.tcp_max_tw_buckets = 6000
# 记录的那些尚未收到客户端确认信息的连接请求的最大值
net.ipv4.tcp_max_syn_backlog = 65536
# 每个网络接口接收数据包的速率比内核处理这些包的速率快时,允许送到队列的数据包的最大数目
net.core.netdev_max_backlog = 32768
net.core.wmem_default = 8388608
net.core.rmem_default = 8388608
net.core.rmem_max = 16777216
net.core.wmem_max = 16777216
net.ipv4.tcp_synack_retries = 2
net.ipv4.tcp_syn_retries = 2
net.ipv4.route.gc_timeout = 100
net.ipv4.tcp_wmem = 8192 436600 873200
net.ipv4.tcp_rmem = 32768 436600 873200
net.ipv4.tcp_mem = 94500000 91500000 92700000
net.ipv4.tcp_max_orphans = 3276800
vm.swappiness=1
fs.file-max=7672460
fs.aio-max-nr=1048576
net.core.somaxconn=4096
vm.min_free_kbytes=521000
vm.vfs_cache_pressure=200执行以下命令重新加载生效
[root@node1 ~]# sysctl -p 修改/etc/systemd/system.conf文件中的DefaultTasksAccounting参数
[root@node1 ~]# vim /etc/systemd/system.conf
DefaultTasksAccounting=no 注:所有服务不再有此限制执行以下命令生效
[root@node1 ~]# systemctl daemon-reload
[root@node1 ~]# systemctl daemon-reexec 执行以下命令观察是否生效(无Limit那一行),若无生效,重启。
[root@node1 ~]# service sshd status修改磁盘IO调度策略(deadline综合测试性能表现更稳定),并将此命令添加到/etc/rc.local
echo deadline > /sys/block/[磁盘名]/queue/scheduler修改/etc/systemd/logind.conf文件中RemoveIPC=no
[root@node1 ~]# vim /etc/systemd/logind.conf
RemoveIPC=no生效方式
[root@node1 ~]# systemctl daemon-reload
[root@node1 ~]# systemctl restart systemd-logind 创建安装用户
useradd kingbase
passwd kingbase配置yum并安装依赖包(必须)
#配置本地yum源
mount /dev/sr0 /mnt
cd /etc/yum.repos.d
mkdir bk
mv *.repo bk/
cat > /etc/yum.repos.d/centos79.repo << "EOF"
[local]
name=centos79
baseurl=file:///mnt
gpgcheck=0
enabled=1
EOF
yum install unzip zip net-tools做这个步骤是为了规避 zip、unzip命令不存在
配置环境变量
su - kingbase
cat >> ~/.bashrc >> EOF <<
export PATH=$PATH:/kdb/kingbase/cluster/kingbase/kingbase/bin
export KINGBASE_DATA=/data/kingbase/db_platform
export KINGBASE_PORT=25432
EOF获取集群安装包
获取集群部署文件,准备软件包如下所示:
特别说明:部署脚本、部署配置文件、配置SSH互相脚本、license.dat均在tar包解压后的bin目录下
软件包名 | 备注 |
db.zip | 数据库服务器压缩包 |
cluster_install.sh | 部署脚本 |
install.conf | 部署配置文件 |
trust_cluster.sh | 配置 SSH 互信脚本 |
license.dat | 可选项:默认使用安装包自带的临时授权文件;正式数据库授权文件,需要单独联系商务获取后进行替换 |
将软件包上传至新节点待扩容服务器的系统目录(/home/kingbase/software,也可以自定义),并修改目录和文件的权限:
--集群安装包上传至home用户家目录
scp kingbase-server-V008R020C010M002B0001-linux-x86_64.tar license.dat kingbase@192.168.40.161:/home/kingbase
--创建安装目录
mkdir -p /kdb/kingbase/cluster/install/kingbase/
chown -R kingbase:kingbase /kdb/kingbased
--解压
tar -xvf kingbase-server-V008R020C010M002B0001-linux-x86_64.tar -C /kdb/kingbase/cluster/install/kingbase/
--制作db.zip
cd /kdb/kingbase/cluster/install/kingbase/
zip -r db.zip bin include lib share配置互信
KingbaseES集群提供了trust_cluster.sh工具实现集群节点的互信配置。trust_cluster.sh脚本会读取install.conf中的IP参数用于配置互信,install_with_root参数可以控制着互信用户的范围。
install_with_root参数说明:
- install_with_root=1,配置root及普通用户间的互信;
- install_with_root=0,仅限于配置普通用户间的互信。
注意:trust_cluster.sh和install.conf脚本需放在同一设备的同一目录下。
--配置 install.conf
cd /kdb/kingbase/cluster/install/kingbase/bin
vi install.conf
install_with_root=1
all_ip=(192.168.40.107 192.168.40.160 192.168.40.161)
--配置互信
su - root
sh /kdb/kingbase/cluster/install/kingbase/bin/trust_cluster.sh扩展:配置互信后root用户和普通用户互信验证
--root用户
ssh root@192.168.40.107
ssh root@192.168.40.160
--普通用户
ssh kingbase@192.168.40.107
ssh kingbase@192.168.40.160集群通讯工具sys_securecmdd
集群部署过程中可以使用 SSH互信配置和通讯工具sys_securecmdd,本文档采用通讯工具sys_securecmdd工具。
注意更改install.conf配置文件中参数deploy_by_sshd=0 #控制扩容部署的方式。0:表示使用sys_securecmdd方式进行部署 1(默认):表示使用ssh方式进行部署
sys_securecmdd介绍
sys_securecmdd是集群中自带的工具,集群监控、管理集群时通过sys_securecmdd安全执行命令。其主要包含以下文件:
类型 | 文件名 | 作用 |
服务端 | sys_securecmdd | 默认监听8890端口,接受客户端连接。 |
sys_secureftp | 服务端调用,用于接收文件。 | |
sys_HAscmdd.sh | 脚本,管理服务端。 | |
客户端 | sys_securecmd | 客户端,用于连接服务端。 |
密钥文件 | accept_hosts | 免密文件 |
key_file | 私钥文件 | |
其他文件 | securecmdd_config | 服务端配置文件 |
securecmd_config | 客户端配置文件 | |
sys_HAscmdd.conf | 脚本配置文件 | |
securecmdd.service | 服务模板文件,服务端可以使用此文件注册为服务。 | |
依赖库文件 | libcrypto.so.10 | 依赖openssl编译,为了不同环境能够使用,需要带上编译使用的库文件。 |
sys_HAscmdd.conf配置文件说明
参数名称 | 描述 | 取值约束 |
start_method | 启动sys_securecmdd进程并保证进程高可用的方式。crontab,集群默认值,通过crond服务定时启动。systemd,默认通过service服务启动; | crontab或systemd,默认为crontab。 |
scmd_port | 进程sys_securecmdd的监听端口,修改后,需要使用 sys_HAscmdd.sh脚本初始化。 | INT,默认8890。 |
tcp_user_timeout | 网络层的TCP_USER_TIMEOUT参数未确认数据(没有ACK)保留时长,超时后强制关闭连接。 |
工具使用
初始化进程
sys_securecmdd工具支持使用普通用户或root用户进行初始化动作。建议sys_securecmdd工具的初始化和维护都由同一用户完成
cd /kdb/kingbase/cluster/install/kingbase/bin/
./sys_HAscmdd.sh init初始化操作主要工作:
- 初始化sys_securecmdd、sys_securecmd需要的配置文件和秘钥协商。
- 将securecmd_config、securecmdd_config修改后拷贝到
/opt/kes/etc/${username}目录下,如当前普通用户名为kingbase,则对应目录为/opt/kes/etc/kingbase。 - 将accept_hosts、 key_file拷贝到
/root/.es(仅root用户初始化时需要)和当前用户~/.es目录下。
启动进程
sys_securecmdd工具启动方式受start_method参数影响。
- root用户默认是通过注册操作系统securecmdd.service服务的方式进行启动;
- 普通用户默认是通过通过设置crontab指令设置sys_securecmdd定时任务的方式进行启动。
查看进程状态
sys_HAscmdd.sh status扩展1:关闭进程和进程高可用能力
sys_HAscmdd.sh stop扩展2:卸载sys_securecmdd
sys_HAscmdd.sh uninstall问题处理
[kingbase@node3 ~]$ sys_HAscmdd.sh init
ERROR: there are already processes running on port 8890 (in sys_HAscmdd.conf)
[kingbase@node3 ~]$ ps -ef | grep secure
root 6340 1 0 10:11 ? 00:00:00 sys_securecmdd: /kdb/kingbase/cluster/kingbase/kingbase/bin/sys_securecmdd -f /opt/kes/etc/securecmdd_config[listener] 0 of 128-256 startups
[root@node3 yum.repos.d]# cd /kdb/kingbase/cluster/kingbase/kingbase/bin/
[root@node3 bin]# ./sys_HAscmdd.sh stop
the ExecStart is [ExecStart=/kdb/kingbase/cluster/kingbase/kingbase/bin/sys_securecmdd -f /opt/kes/etc/kingbase/securecmdd_config]
the ExecStart in "/kdb/kingbase/cluster/kingbase/kingbase/share/securecmdd.service" is incorrect, please execute "./sys_HAscmdd.sh init" first
[root@node3 bin]# ps -ef | grep secure
root 6340 1 0 10:11 ? 00:00:00 sys_securecmdd: /kdb/kingbase/cluster/kingbase/kingbase/bin/sys_securecmdd -f /opt/kes/etc/securecmdd_config[listener] 0 of 128-256 startups配置文件修改
登录待扩容节点,修改install.conf参数文件。
su - kingbase
cd /kdb/kingbase/cluster/install/kingbase/bin/
cp install.conf install.confbak
vi install.confinstall.conf 配置文件 [expand] 标签下参数示例如下:
[expand]
expand_type='0' # The node type of standby/witness node, which would be add to cluster. 0:standby 1:witness
primary_ip='192.168.40.107'
expand_ip='192.168.40.161'
node_id='3'
sync_type=""
install_dir="/kdb/kingbase/cluster/kingbase" # the last layer of directory could not add '/'
zip_package="/kdb/kingbase/cluster/install/kingbase/db.zip"
net_device=(ens32) # if virtual_ip set,it must be set
net_device_ip=(192.168.40.155) # if virtual_ip set,it must be set
license_type='default'
license_file='license.dat'
lac_host=''
lac_port=11234
lac_type=''
activation_file=''
use_vcpu_limit=0
deploy_by_sshd=0 #控制扩容部署的方式。0:表示使用sys_securecmdd方式进行部署 1(默认):表示使用ssh方式进行部署
scmd_port="8890"
ssh_port="22"install.conf 配置文件 [expand] 标签下参数说明:
参数 | 备注 |
expand_type | 必须配置项,该参数控制扩容的数据库节点类型。 - 0:表示为 standby 节点, - 1:表示为 witness 节点。 |
primary_ip | 必须配置项,该参数表示扩容集群的主节点 IP。 |
expand_ip | 必须配置项,该参数表示待扩容的节点的 IP。 |
node_id | 必须配置项,该参数表示待扩容节点的节点编号, 不要与现有集群节点编号重复。 |
sync_type | 可选配置,表示扩容节点的同步类型。若 synchronous 参数为custom,且expand_type=0时,该选项为必须配置项。 |
install_dir | 必须配置项,该参数表示软件的安装路径,该路径需是一个不存在的目录,该安装目录需与原集群保持一致,字符串不能以 |
zip_package | 必须配置项,该参数表示压缩包的路径。 |
net_device | 可选配置项,该参数表示VIP所在网卡的网卡名称,若配置了 [virtual _ip],该参数必须配置项。 |
net_device_ip | 可选配置项,该参数表示VIP 所在网卡的物理 IP 地址,若配置了 [virtual _ip],该参数需要配置,仅需配置1个。 |
license_type | 必须配置项,说明授权方式,可选值为:('default' 'UKey' 'LAC')。 |
license_file | 可选配置项,该参数表示 license 文件的名字。不配置时,默认使用试用版license。 |
lac_host | license_type为'LAC'时为必须配置项,说明LAC服务端地址。 |
lac_port | license_type为'LAC'时为必须配置项,说明LAC服务端口号,默认为11234。 |
lac_type | license_type为'LAC'时为必须配置项,说明授权类型,可选值为('ENT' 'PRO' 'STD' 'DEV')。 |
activation_file | license_type为'LAC'时为可选配置项,指定要使用的LAC服务端的激活文件。 |
use_vcpu_limit | license_type为'LAC'时为必须配置项,说明授权控制方式。 |
deploy_by_sshd | 可选配置项,该参数控制扩容部署的方式。 |
ssh_port | 可选配置项,该参数表示sshd/ssh 连接端口,默认 22。 |
scmd_port | 可选配置项,该参数表示sys_securecmdd/sys_securecmd 连接 端口,默认为 8890。 |
扩容步骤
节点扩容
登录待扩容节点,使用kingbase用户执行节点扩容命令
cd /kdb/kingbase/cluster/install/kingbase/bin
sh cluster_install.sh expand问题处理
ksql: error: could not connect to server: FATAL: password authentication failed for user "system"
问题描述
cd /kdb/kingbase/cluster/install/kingbase/bin
sh cluster_install.sh expand
报错:
[CONFIG_CHECK] check database connection ...
ksql: error: could not connect to server: FATAL: password authentication failed for user "system"
[ERROR] param [primary_ip:192.168.40.107 db_name:esrep db_user:system db_password:****** db_port:25432] is error, please check these params解决办法
db_user="system" # the user name of database
db_password="kingbase" # the password of database.
db_port="25432"[ERROR] net_device_ip:[192.168.40.155] does not on host
问题描述
执行扩容命令报错
[CONFIG_CHECK] The net_device_ip:[192.168.40.155] exists on dev ens32 on [192.168.40.161].....
[ERROR] net_device_ip:[192.168.40.155] does not on host "192.168.40.161" on dev "ens32"
解决办法
net_device_ip必须是本机的物理网卡ip地址而不是vip
vi install.conf
#net_device_ip=(192.168.40.155) # if virtual_ip set,it must be set
更改为
net_device_ip=(192.168.40.161)bash: unzip: command not found
问题描述
执行扩容命令报错:bash: unzip: command not found,[ERROR] failed to decompress
[INSTALL] try to copy the zip package "/kdb/kingbase/cluster/install/kingbase/db.zip" to /kdb/kingbase/cluster/kingbase/kingbase of "192.168.40.161" .....
[INSTALL] success to scp the zip package "/kdb/kingbase/cluster/install/kingbase/db.zip" /kdb/kingbase/cluster/kingbase/kingbase of to "192.168.40.161" ..... OK
[INSTALL] decompress the "/kdb/kingbase/cluster/kingbase/kingbase" to "/kdb/kingbase/cluster/kingbase/kingbase" on 192.168.40.161
bash: unzip: command not found
[ERROR] failed to decompress the "/kdb/kingbase/cluster/kingbase/kingbase/db.zip" to "/kdb/kingbase/cluster/kingbase/kingbase" on "192.168.40.161".解决办法
--删除安装目录 不然再次扩容提示目录已存在
cd /kdb/kingbase/cluster/kingbase/
rm -rf kingbase
--再次执行
cd /kdb/kingbase/cluster/install/kingbase/bin
sh cluster_install.sh expand扩容后检查
扩容成功后,到主库或扩容的备库所在节点的集群目录下,执行命令repmgr cluster show,确认是否真正成功扩容集群。
[kingbase@node3 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.40.107 user=esrep dbname=esrep port=25432 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.40.160 user=esrep dbname=esrep port=25432 connect_timeout=10 keepalives=1 keepalives_idle=2 keepalives_interval=2 keepalives_count=3 tcp_user_timeout=9000
3 | node3 | standby | running | node1 | default | 100 | 1 | 0 bytes | host=192.168.40.161 user=esrep dbname=esrep port=25432 connect_timeout=10 keepalives=1 keepalives_idle=2 keepalives_interval=2 keepalives_count=3 tcp_user_timeout=9000说明:node3节点 status列显示为running,role列显示为standby,表明节点已经成功加入集群。




