我配置了一个故障转移负载均衡器,这样当我的主服务器发生故障时,它就可以充当备份。因此,我设置了 Keepalived,当它无法找到在其他机器上运行的服务 HAProxy 时,它会将浮动虚拟 IP 地址切换到另一台机器。conf 文件中提到的 IP 地址存在于我的 eth1 接口上。
在我的主负载均衡器我正进入(状态
systemctl 状态 keepalived
● keepalived.service - Keepalive Daemon (LVS and VRRP)
Loaded: loaded (/lib/systemd/system/keepalived.service; enabled; vendor preset: enabled)
Active: active (running) since Sun 2022-05-15 18:06:32 UTC; 21min ago
Main PID: 659 (keepalived)
Tasks: 2 (limit: 1131)
Memory: 4.7M
CGroup: /system.slice/keepalived.service
├─659 /usr/sbin/keepalived --dont-fork
└─711 /usr/sbin/keepalived --dont-fork
May 15 18:27:57 ubuntu-s-1vcpu-1gb-blr1-01 killall5[2250]: only one argument, a signal number, allowed
May 15 18:28:01 ubuntu-s-1vcpu-1gb-blr1-01 killall5[2252]: only one argument, a signal number, allowed
May 15 18:28:03 ubuntu-s-1vcpu-1gb-blr1-01 killall5[2253]: only one argument, a signal number, allowed
May 15 18:28:05 ubuntu-s-1vcpu-1gb-blr1-01 killall5[2256]: only one argument, a signal number, allowed
May 15 18:28:07 ubuntu-s-1vcpu-1gb-blr1-01 killall5[2259]: only one argument, a signal number, allowed
May 15 18:28:09 ubuntu-s-1vcpu-1gb-blr1-01 killall5[2260]: only one argument, a signal number, allowed
May 15 18:28:11 ubuntu-s-1vcpu-1gb-blr1-01 killall5[2261]: only one argument, a signal number, allowed
May 15 18:28:13 ubuntu-s-1vcpu-1gb-blr1-01 killall5[2262]: only one argument, a signal number, allowed
May 15 18:28:15 ubuntu-s-1vcpu-1gb-blr1-01 killall5[2263]: only one argument, a signal number, allowed
May 15 18:28:17 ubuntu-s-1vcpu-1gb-blr1-01 killall5[2264]: only one argument, a signal number, allowed
sudo nano /etc/keepalived/keepalived.conf
vrrp_script chk_haproxy {
script "pidof haproxy"
interval 2
}
vrrp_instance VI_1 {
interface eth1
state MASTER
priority 200
virtual_router_id 33
unicast_src_ip 10.122.0.2
unicast_peer {
10.122.0.3
}
authentication {
auth_type PASS
auth_pass password
}
track_script {
chk_haproxy
}
notify_master /etc/keepalived/master.sh
}
在我的辅助负载均衡器
systemctl 状态 keepalived
● keepalived.service - Keepalive Daemon (LVS and VRRP)
Loaded: loaded (/lib/systemd/system/keepalived.service; enabled; vendor preset: enabled)
Active: active (running) since Sun 2022-05-15 17:57:16 UTC; 36min ago
Main PID: 329993 (keepalived)
Tasks: 2 (limit: 4677)
Memory: 1.9M
CGroup: /system.slice/keepalived.service
├─329993 /usr/sbin/keepalived --dont-fork
└─330005 /usr/sbin/keepalived --dont-fork
May 15 17:57:16 ubuntu-s-2vcpu-4gb-blr1-01 Keepalived_vrrp[330005]: Script `chk_haproxy` now returning 1
May 15 17:57:16 ubuntu-s-2vcpu-4gb-blr1-01 Keepalived_vrrp[330005]: VRRP_Script(chk_haproxy) failed (exited with status 1)
May 15 17:57:16 ubuntu-s-2vcpu-4gb-blr1-01 Keepalived_vrrp[330005]: (VI_1) Entering FAULT STATE
May 15 18:05:21 ubuntu-s-2vcpu-4gb-blr1-01 killall5[330439]: only one argument, a signal number, allowed
May 15 18:10:13 ubuntu-s-2vcpu-4gb-blr1-01 killall5[330679]: only one argument, a signal number, allowed
May 15 18:11:37 ubuntu-s-2vcpu-4gb-blr1-01 killall5[330750]: only one argument, a signal number, allowed
May 15 18:17:53 ubuntu-s-2vcpu-4gb-blr1-01 killall5[331070]: only one argument, a signal number, allowed
May 15 18:24:21 ubuntu-s-2vcpu-4gb-blr1-01 killall5[331386]: only one argument, a signal number, allowed
May 15 18:28:11 ubuntu-s-2vcpu-4gb-blr1-01 killall5[331552]: only one argument, a signal number, allowed
May 15 18:30:31 ubuntu-s-2vcpu-4gb-blr1-01 killall5[331649]: only one argument, a signal number, allowed
sudo nano /etc/keepalived/keepalived.conf
vrrp_script chk_haproxy {
script "pidof haproxy"
interval 2
}
vrrp_instance VI_1 {
interface eth1
state BACKUP
priority 100
virtual_router_id 33
unicast_src_ip 10.122.0.3
unicast_peer {
10.122.0.2
}
authentication {
auth_type PASS
auth_pass password
}
track_script {
chk_haproxy
}
notify_master /etc/keepalived/master.sh
}
pidof 的输出pidof haproxy
基本的
root@ubuntu-s-1vcpu-1gb-blr1-01:~# pidof haproxy
726 719
次要
root@ubuntu-s-2vcpu-4gb-blr1-01:~# pidof haproxy
328842 328841
笔记 :我手动运行了 /etc/keepalived/master.sh 脚本并且它成功运行。
编辑1:即使我使用也不起作用pidof -s haproxy
答案1
重新安装 KeepAlived 包解决了我的问题。
要删除 keepalived:
sudo apt-get remove -y keepalived
sudo apt-get remove --auto-remove -y keepalived
安装 KEEPALIVED
sudo apt-get update
sudo apt-get install -y keepalived