接着上篇:搭建Keepalived+Nginx 高可用实例操作:
1、搭建Keepalived+Nginx 高可用
(1)服务器环境准备
192.168.210.85 Nginx 主负载/Keepalived主服务器
192.168.210.177 Nginx 辅负载/Keepalived从服务器
192.168.210.176 后端服务1
192.168.210.195 后端服务2
(2)192.168.210.85服务器配置
[root@k8s-master1~]# vim /etc/keepalived/keepalived.conf
[root@k8s-master1~]# more /etc/keepalived/keepalived.conf
! Configuration File for keepalived
global_defs {
notification_email {
hahashen@126.com
}
}
vrrp_instance VI_1 {
state MASTER
interface ens33
virtual_router_id 51
priority 200
advert_int 1
authentication {
auth_type PASS
auth_pass 1111
}
virtual_ipaddress {
192.168.210.11
}
}
vrrp_instance VI_2 {
state BACKUP
interface ens33
virtual_router_id 52
priority 150
advert_int 1
authentication {
auth_type PASS
auth_pass 2222
}
virtual_ipaddress {
192.168.210.12
}
}
重启keepalived
root@k8s-master1 ~]# systemctl restart keepalived
查看IP,还在k8s-master1
(3)192.168.210.177服务器配置
[root@k8s-node1~]# vim /etc/keepalived/keepalived.conf
[root@k8s-node1~]# more /etc/keepalived/keepalived.conf
! Configuration File for keepalived
global_defs {
notification_email {
hahashen@126.com
}
}
vrrp_instance VI_1 {
state BACKUP
interface ens33
virtual_router_id 51
priority 150
advert_int 1
authentication {
auth_type PASS
auth_pass 1111
}
virtual_ipaddress {
192.168.210.11
}
}
vrrp_instance VI_2 {
state MASTER
interface ens33
virtual_router_id 52
priority 200
advert_int 1
authentication {
auth_type PASS
auth_pass 2222
}
virtual_ipaddress {
192.168.210.12
}
}
[root@k8s-node1 ~]# systemctl restart keepalive
查看k8s-node1上的vip是192.168.210.12
(4)测试
停止k8s-master1上的keepalived
[root@k8s-master1 ~]# systemctl stop keepalived
测试访问keepalived中配置的两个VIP都可以正常调度,当我们停止任意一台keepalived节点,同样还是正常访问。