欢迎来到尧图网

客户服务 关于我们

您的位置:首页 > 新闻 > 国际 > LVS+Keepalived高可用群集配置案例

LVS+Keepalived高可用群集配置案例

2025/2/28 10:02:12 来源:https://blog.csdn.net/m0_38096339/article/details/145904172  浏览:    关键词:LVS+Keepalived高可用群集配置案例

以下是一个 LVS+Keepalived 高可用群集配置案例:

1、环境准备

  • LVS 主调度器(lvs1):IP 地址为 192.168.8.101,心跳 IP 为 192.168.4.101
  • LVS 备调度器(lvs2):IP 地址为 192.168.8.102,心跳 IP 为 192.168.4.102
  • 虚拟 IP(vip):192.168.8.100
  • Web 服务器 1(nginx1):IP 地址为 192.168.8.103
  • Web 服务器 2(nginx2):IP 地址为 192.168.8.104
  • 客户端:IP 地址为 192.168.8.1

2、配置步骤

2.1、为lvs1和lvs2配置ip地址

lvs1:配置IP地址

nmcli connection modify ens33 ipv4.method manual ipv4.addresses 192.168.8.101/24
nmcli connection modify ens36 ipv4.method manual ipv4.addresses 192.168.4.101/24
nmcli connection up ens33
nmcli connection up ens36

lvs2:配置IP地址

nmcli connection modify ens33 ipv4.method manual ipv4.addresses 192.168.8.102/24
nmcli connection modify ens36 ipv4.method manual ipv4.addresses 192.168.4.102/24
nmcli connection up ens33
nmcli connection up ens36

2.2、为lvs1和lvs2安装keepalived和ipvsadm并修改配置文件

  • 安装:
yum install -y keepalived ipvsadm
  • Ivs1的 keepalived 配置文件修改

!configuration file for keepalived
global_defs{router_id cluster1
}
vrrp_instance web{state masterinterface ens33virtual_router_id 51priority 255advert_int 1authentication{auth_type passauth_pass 1111}virtual_ipaddress{192.168.8.100/24}
}
virtual_server 192.168.8.100 80{delay_loop 6lb_algo rrlb_kind drpersistence_timeout 50protocol tcpreal_server 192.168.8.103 80{weight 1tcp_check{connect_timeout 3retry 3delay_before_retry 3}}real_server 192.168.8.104 80{weight 2tcp_check{connect_timeout 3retry 3delay_before_retry 3}}
}
  • Ivs2的 keepalived 配置文件修改

! configuration file for keepalived
global_defs{router_id cluster2
}
vrrp_instance web{state backupinterface ens33virtual_router_id 51priority 100advert_int 1authentication{auth_type passauth_pass 1111}virtual_ipaddress{192.168.8.100/24}
}
virtual_server 192.168.8.100 80{delay_loop 6lb_algo rrlb_kind drpersistence_timeout 50protocol tcpreal_server 192.168.8.103 80{weight 1tcp_check{connect_timeout 3retry 3delay_before_retry 3}}real_server 192.168.8.104 80{weight 2tcp_check{connect_timeout 3retry 3delay_before_retry 3}}
}
  • 重启服务:在两台lvs上输入

systemctl restart keepalived

3、为后端服务器安装 httpd

web1

安装:yum install -y httpd
写入信息:echo "hello,192.168.8.103" > /usr/share/nginx/html/index.html
启动服务:systemctl enable httpd.service --now

web2

安装:yum install -y httpd
写入信息:echo "hello,192.168.8.104" > /usr/share/nginx/html/index.html
启动服务:systemctl enable httpd.service --now

4、为后端服务器配置IP地址

web1

nmcli con mod ens33 ipv4.address 192.168.8.103/24 ipv4.gateway 192.168.8.2
nmcli con up ens33
增加虚拟接口并配置 vip:nmcli connection add type dummy ifname dummy2 ipv4.method manual ipv4.addresses 192.168.8.100/32
修改内核 arp 配置:cat >>/etc/sysctl.conf<< eof net.ipv4.conf.all.arp_ignore=1 net.ipv4.conf.all.arp_announce=2 eof
刷新配置:sysctl -p

web2

nmcli con mod ens33 ipv4.address 192.168.8.104/24 ipv4.gateway 192.168.8.2
nmcli con up ens33
增加虚拟接口并配置 vip:nmcli connection add type dummy ifname dummy2 ipv4.method manual ipv4.addresses 192.168.8.100/32
修改内核 arp 配置:cat >>/etc/sysctl.conf<< eof net.ipv4.conf.all.arp_ignore=1 net.ipv4.conf.all.arp_announce=2 eof
刷新配置:sysctl -p

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com

热搜词