跳到主要内容
版本:1.0.14

Halo_Shield的配置

物理复制环境规划和搭建

Halo Shield 可以在已有的物理复制环境之上进行配置。建议根据第10章手动搭建物理复制环境。

Halo Shield 依赖于 etcd 分布式键值数据库。如果主从数据库超过3台服务器,建议在其中3台上配置并运行etcd服务。

ETCD 配置

确保 HALO_BASE 环境变量已设置,在所有需要运行 etcd 服务的服务器上用 halo用户执行 etcd_config.sh,输入etcd 将要运行的所有服务器 IP 地址。

vi /home/halo/.bash_profile
export HALO_BASE=/u01/app/halo
$HALO_BASE/product/shield/etcd/v3.5.2/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

Please input IP list where etcd cluster will be running
e.g. 192.168.1.1,192.168.1.2,192.168.1.3
10.16.16.155,10.16.16.156,10.16.16.157

10.16.16.155 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.2/conf/etcd.service /usr/lib/systemd/system/etcd.service**

根据输出信息,在所有运行 etcd 服务的服务器上用 root 用户创建自启动服务连接

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

Patroni 配置

确保 HALO_BASE、HALO_HOME、PGDATA 环境变量已设置,在所有主备服务器上用halo用户执行 patroni_config.sh,输入etcd 将要运行的所有服务器 IP 地址、输入当前服务器名和VIP信息。

$HALO_BASE/product/shield/patroni/conf/patroni_config.sh
Starting to run patroni configuration setup
Please set HALO_BASE, HALO_HOME, PGDATA environment variables before proceed
Press y/Y to continue, any other key to cancel
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
10.16.16.155,10.16.16.156,10.16.16.157

Input current node name
Default: **node1**
Input VIP for the HA cluster

**10.16.16.199**
10.16.16.199 will be used as VIP
Input network interface to bind the VIP
Default: **eth0**
eth0 will be used as network interface
Input VIP netmask

Default: 255.255.255.0
255.255.255.0 will be used as VIP netmask
Input VIP broadcast address
Default: 10.16.16.255
10.16.16.255 will be used as VIP broadcast address
Initialize python ...
Python initializing done.
Initializing done.
Following steps to be done manually.

1. Add the following line into the end of .bash_profile of user halo
export PATH=/u01/app/halo/product/shield/patroni/python/bin:$PATH
export PATRONICTL_CONFIG_FILE=/u01/app/halo/product/shield/patroni/conf/patroni_halo.yml

2. Run following commands as root
ln -s /u01/app/halo/product/shield/patroni/conf/patroni.service /usr/lib/systemd/system/patroni.service

3. Add the following line to** **/etc/sudoers
halo ALL=(ALL) NOPASSWD: /usr/sbin/ip, /usr/bin/arping, /usr/sbin/iptables

根据输出信息,在所有主备服务器上执行以下步骤:

  1. 在 halo 用户的 .bash_profile 中加入
export PATH=/u01/app/halo/product/shield/patroni/python/bin:\$PATH

export PATRONICTL_CONFIG_FILE=/u01/app/halo/product/shield/patroni/conf/patroni_halo.yml
  1. 用 root 用户创建自启动服务连接
ln -s /u01/app/halo/product/shield/patroni/conf/patroni.service /usr/lib/systemd/system/patroni.service

3.用 root 用户在 /etc/sudoers 中加入以下行

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

创建数据库管理用户

在主库上创建以下用户

psql
create user patroni SUPERUSER password 'patroni';

创建watchdog服务(可选)

使用 root 执行以下命令

yum install -y watchdog
modprobe softdog
chown halo /dev/watchdog
systemctl start watchdog
systemctl enable watchdog

如需服务器重启后自动加载softdog模块,可以将以下命令添加到/etc/rc.local文件中

/usr/sbin/modprobe softdog soft_margin=60
/usr/bin/chown halo /dev/watchdog

测试watchdog,执行以下命令,观察服务器是否自动重启

echo a > /dev/watchdog