实现 Master/Master 的 Keepalived 双主架构
master/slave的单主架构,同一时间只有一个Keepalived对外提供服务,此主机繁忙,而另一台主机却 很空闲,利用率低下,可以使用master/master的双主架构,解决此问题.
Master/Master 的双主架构: 即将两个或以上VIP分别运行在不同的keepalived服务器,以实现服务器并行提供web访问的目的,提高 服务器资源利用率
增加一个新的业务配置如下(所有节点ka1、ka2)
[root@ka1 conf.d]#cp www.meng.org.conf www.meng.com.conf
[root@ka1 conf.d]#ls
www.meng.com.conf www.meng.org.conf #两个业务
对于第一个业务www.meng.com.conf,ka1是主、ka2是备,则第二个业务com可改为第一个为备,第二个为主
ka1设置如下
[root@ka1 conf.d]#vim www.meng.com.conf
vrrp_instance VI_2 {
state BACKUP
interface eth1
virtual_router_id 88
priority 80
advert_int 1
#nopreempt
authentication {
auth_type PASS
auth_pass 654321
}
virtual_ipaddress {
10.0.0.200/24 dev eth0 label eth0:1
}
unicast_src_ip 192.168.10.100
unicast_peer{
192.168.10.101
}
notify_master "/etc/keepalived/notify.sh master"
notify_backup "/etc/keepalived/notify.sh backup"
notify_fault "/etc/keepalived/notify.sh fault"
}
[root@ka1 conf.d]#systemctl restart keepalived
ka2设置如下
[root@ka2 conf.d]#vim www.meng.com.conf
vrrp_instance VI_2 {
state MASTER
interface eth1
virtual_router_id 88
priority 100
advert_int 1
#nopreempt
authentication {
auth_type PASS
auth_pass 654321
}
virtual_ipaddress {
10.0.0.200/24 dev eth0 label eth0:1
}
unicast_src_ip 192.168.10.101
unicast_peer{
192.168.10.100
}
notify_master "/etc/keepalived/notify.sh master"
notify_backup "/etc/keepalived/notify.sh backup"
notify_fault "/etc/keepalived/notify.sh fault"
}
[root@ka2 conf.d]#systemctl restart keepalived
查看节点VIP情况
[root@ka1 conf.d]#hostname -I
10.0.0.101 10.0.0.100 192.168.10.100
[root@ka2 conf.d]#hostname -I
10.0.0.102 10.0.0.200 192.168.10.101
如果其中一个节点坏了,另一节点将承担两个业务,负担加重(平时要做压力测试,平时每个节点不能超50%)
[root@ka2 conf.d]#hostname -I
10.0.0.102 10.0.0.200 10.0.0.100 192.168.10.101