跳到主要内容

部署 etcd 与 Clustermgr

部署 etcd 与 Clustermgr(业务连续性手工部署)​

业务连续性(Halo Shield)方案由 etcd、Clustermgr、Halo 三部分组件组成:

  • etcd:分布式键值数据库,至少需要三台节点且为奇数,用于 leader 选举,可以与 Halo 数据库部署在同一台机器。节点数少的 etcd 集群会不可用,从而避免脑裂。
  • Clustermgr:针对 Halo 数据库进行流复制创建、管理、监控和自动故障转移。它通过 etcd 集群存储、检测 Halo 主从节点的状态与配置信息:当某个节点无法工作时,Clustermgr 自动侦测故障并通过 etcd 更新节点信息、通知其他节点;若故障节点是主节点,Clustermgr 还会自动切换并重新绑定 VIP 到新的主节点。Clustermgr 通过连接 etcd 对其他节点做心跳检测,当主节点无法更新 etcd 中的 leader key 时,Clustermgr 会终止当前节点的 Halo 数据库从而避免脑裂。

下面演示 Halo 数据库在 Linux 环境下 3 节点高可用集群的部署和启动。建议 Linux 操作系统版本为 RHEL 7 以上。

系统环境准备​

  1. 准备一主二备环境,物理复制必须搭建完成(见搭建物理流复制):
IP地址角色
192.168.221.136主库
192.168.221.137备库
192.168.221.138备库
  1. 用户环境变量设置(三个节点的 halo 用户都要添加)

编辑 halo 用户环境变量:

vi /home/halo/.bash_profile

添加

export HALO_BASE=/u01/app/halo

执行生效

source /home/halo/.bash_profile

etcd配置​

etcd集群作为Clustermgr的DCS(分布式配置存储),保存集群成员元数据信息及状态信息。

  1. 开始配置 etcd(halo 用户下执行配置脚本):
[halo@node1 ~]$ /u01/app/halo/product/shield/etcd/v3.5.10/conf/etcd_config.sh
Starting to run etcd configuration setup
Please set HALO_BASE environment variables before proceed
Press y/Y to continue, any other key to cancel
y (手工输入 y)
Please input IP list where etcd cluster will be running
e.g. 192.168.1.1,192.168.1.2,192.168.1.3
192.168.221.136,192.168.221.137,192.168.221.138 (手工输入三节点 IP)
192.168.221.136 will be used as node IP
Initializing done.
Following steps to be done manually.
Run following commands as root
ln -s /u01/app/halo/product/shield/etcd/v3.5.10/conf/etcd.service /usr/lib/systemd/system/etcd.service
  1. 根据配置完成提示,切换root用户创建etcd服务软链接
ln -s /u01/app/halo/product/shield/etcd/v3.5.10/conf/etcd.service /usr/lib/systemd/system/etcd.service

注意:以上 1.-2. 步骤还要在集群另外两台备机(node2、node3)上执行

Clustermgr配置​

  1. 开始配置 Clustermgr(halo 用户下执行配置脚本):
[halo@node1 ~]$ /u01/app/halo/product/shield/clustermgr/conf/clustermgr_config.sh
Starting to run clustermgr configuration setup
Please set HALO_BASE, HALO_HOME, PGDATA environment variables before proceed
Press y/Y to continue, any other key to cancel
y (手工输入 y)
Please input IP list where etcd cluster will be running
e.g. 192.168.1.1,192.168.1.2,192.168.1.3
192.168.221.136,192.168.221.137,192.168.221.138 (手工输入三节点 IP)
Input current node name
Default: node1
node1
node1 will be used as node name
Input VIP for the HA cluster
192.168.221.140 (手工输入 VIP,勿与节点 IP 相同)
192.168.221.140 will be used as VIP
Input network interface to bind the VIP
Default: ens33
ens33 (回车用默认值)
ens33 will be used as network interface
Input VIP netmask
Default: 255.255.255.0
255.255.255.0 (回车用默认值)
255.255.255.0 will be used as VIP netmask
Input VIP broadcast address
Default: 192.168.221.255
192.168.221.255 (可选VIP的广播地址,回车配置为默认值)
192.168.221.255 will be used as VIP broadcast address
Initialize python ...
Python initializing done.
Initializing done.
Following steps to be done manually.

提示 1:在 halo 用户的 .bash_profile 末尾追加:

export PATH=/u01/app/halo/product/shield/clustermgr/bin:$PATH
export CLUMGRCTL_CONFIG_FILE=/u01/app/halo/product/shield/clustermgr/conf/clustermgr_halo.yml

提示 2:以 root 用户执行:

ln -s /u01/app/halo/product/shield/clustermgr/conf/clustermgr.service /usr/lib/systemd/system/clustermgr.service

提示 3:在 /etc/sudoers 中追加:

halo ALL=(ALL) NOPASSWD: /usr/sbin/ip, /usr/sbin/arping, /usr/sbin/iptables, /usr/sbin/modprobe, /usr/bin/chown

注意:

  • 若 node name 配置错误,修改 /u01/app/halo/product/shield/clustermgr/conf/clustermgr_halo.yml;
  • 若 VIP 设置错误,修改 /u01/app/halo/product/shield/clustermgr/scripts/clustermgr_callback.sh。
  1. 配置完成后,执行提供的语句

(1)halo 用户环境变量修改(三个节点都要添加)——编辑 .bash_profile:

vi /home/halo/.bash_profile

添加:

export CLUMGRCTL_CONFIG_FILE=/u01/app/halo/product/shield/clustermgr/conf/clustermgr_halo.yml
export PATH=$HALO_HOME/bin:/u01/app/halo/product/shield/clustermgr/bin:/u01/app/halo/product/shield/etcd/v3.5.10:$PATH

执行生效

source /home/halo/.bash_profile

(2)切换成 root 用户,创建 clustermgr 服务软链接:

ln -s /u01/app/halo/product/shield/clustermgr/conf/clustermgr.service /usr/lib/systemd/system/clustermgr.service

(3)使用 root 用户执行下面的语句,配置 halo 用户执行命令的权限:

echo 'halo ALL=(ALL) NOPASSWD: /usr/sbin/ip, /usr/sbin/arping, /usr/sbin/iptables, /usr/sbin/modprobe, /usr/bin/chown'\>\> /etc/sudoers

注意:以上 1.-2. 步骤需在三台节点上全部执行

  1. 在主库创建 clustermgr 用户(halo 用户下):
psql -c "create user clustermgr SUPERUSER password 'clustermgr';"

校验安装​

  1. 启动 etcd(三台机器都需要执行,root 用户)
systemctl start etcd

如需开机自启:

systemctl enable etcd
  1. 启动 Clustermgr(三台机器都需要执行,root 用户)
systemctl start clustermgr

如需开机自启:

systemctl enable clustermgr
  1. 检查集群
clumgrctl list
+ Cluster: halo-cluster (7342687114432203676) ----+----+-----------

| Member | Host | Role | State | TL | Lag in MB |
+--------+------------------------+---------+-----------+----+-----------+

| node1 | 192.168.221.136:1921 | Leader | running | 7 | |
| node2 | 192.168.221.137:1921 | Replica | streaming | 7 | 0 |
| node3 | 192.168.221.138:1921 | Replica | streaming | 7 | 0 |
+--------+------------------------+---------+-----------+----+-----------+
  1. 停止命令(三台机器都需要停止)
systemctl stop etcd
systemctl stop clustermgr