实验环境
本实验基于CentOS7.3 操作系统,总共5台设备,两台做后端web服务器,两台做lvs和keepalived,一台做客户机,实验以LVS(DR)+Keepalived和LVS(NAT)+Keepalived两种模式来做双机热备份,实验环境拓扑如下图所示:
上图为DR+keepalived模式拓扑,NAT+keepalived模式,在两台lvs调度器上分别新添加了一张网卡,拓扑与上图类似
DR+keepalived模式
(1)配置后端web服务器
Web_Server1
基本配置:
yum -y install epel-release //安装Nginx源
yum -y install nginx //安装Nginx
systemctl start nginx //启动Nginx服务
systemctl enable nginx //加入开机自启
mv /usr/share/nginx/html/index.html /usr/share/nginx/html/index.html_bak //备份原有默认页面
vi /usr/share/nginx/html/index.html //测试页面
This is Server 111111 //测试页面内容
为了便于实验验证,关闭防火墙和selinux
systemctl stop firewalld
setenforce 0
验证:
Web_Server2,配置同上,唯一不同的地方就是测试页面的内容,可以设置为“This is Server 222222”便于验证,配置完后的验证结果如下:
(2)配置LVS
LVS1
yum -y install keepalived* ipvsadm //安装keepalived和lvs管理工具
modprobe ip_vs //加载内核模块
mv /etc/keepalived/keepalived.conf /etc/keepalived/keepalived.conf_bak //备份配置文件
vi /etc/keepalived/keepalived.conf //配置kee