A.3. 安装和配置 keepalived
在两个 HAProxy 节点上执行以下步骤:
- 安装 keepalived。
#
yum install -y keepalived
- 配置 keepalived。
#
vim /etc/keepalived/keepalived.conf
在以下配置中,有一个用于检查 HAProxy 进程的脚本。实例使用eth0
作为网络接口,并将haproxy
配置为主服务器,并将haproxy2
配置为备份服务器。它还分配虚拟 IP 地址 192.168.0.100。vrrp_script chk_haproxy { script "killall -0 haproxy" # check the haproxy process interval 2 # every 2 seconds weight 2 # add 2 points if OK } vrrp_instance VI_1 { interface eth0 # interface to monitor state MASTER # MASTER on haproxy, BACKUP on haproxy2 virtual_router_id 51 priority 101 # 101 on haproxy, 100 on haproxy2 virtual_ipaddress { 192.168.0.100 # virtual ip address } track_script { chk_haproxy } }
- 启用并开始 keepalived。
#
systemctl enable keepalived
#systemctl start keepalived