CentOS 7.3 部署LVS + Keepalived 高可用群集

本次实验需用到四台服务器,包括两台web服务器,两台调度服务器,一台访问测试的客户机
先将虚拟机网络适配器修改为NAT模式在线下载安装相关软件包,
调度服务器需要安装的软件包
CentOS 7.3 部署LVS + Keepalived 高可用群集
Web服务器若没有自带Apache,可使用yum进行安装
CentOS 7.3 部署LVS + Keepalived 高可用群集
之后更改网络适配器为仅主机模式,配置每台虚拟机IP地址进行实验
调度服务器主:192.168.100.21/24
调度服务器备:192.168.100.22/24
Web服务器1:192.168.100.23/24
Web服务器2:192.168.100.24/24
虚拟IP:192.168.100.31/24
客户机:192.168.100.30/24

1、Web服务器
关闭防火墙和安全功能,开启httpd服务
CentOS 7.3 部署LVS + Keepalived 高可用群集
新建首页文件
CentOS 7.3 部署LVS + Keepalived 高可用群集
用自身浏览器测试访问
CentOS 7.3 部署LVS + Keepalived 高可用群集
另外一台web服务器同样的配置
用自身浏览器测试访问
CentOS 7.3 部署LVS + Keepalived 高可用群集
2、调度服务器配置
开启路由转发,关闭重定向
CentOS 7.3 部署LVS + Keepalived 高可用群集
CentOS 7.3 部署LVS + Keepalived 高可用群集
CentOS 7.3 部署LVS + Keepalived 高可用群集
3、创建虚拟网卡
CentOS 7.3 部署LVS + Keepalived 高可用群集
删除原有内容输入如下内容
CentOS 7.3 部署LVS + Keepalived 高可用群集
开启虚拟网卡
CentOS 7.3 部署LVS + Keepalived 高可用群集
4、编辑ipvsadm启动脚本
CentOS 7.3 部署LVS + Keepalived 高可用群集
脚本内容如下
CentOS 7.3 部署LVS + Keepalived 高可用群集
给脚本添加权限,并开启服务
CentOS 7.3 部署LVS + Keepalived 高可用群集
5、web服务器
创建虚拟网卡,注意此处复制的是回环网卡的文件
CentOS 7.3 部署LVS + Keepalived 高可用群集
CentOS 7.3 部署LVS + Keepalived 高可用群集
若使用xshell或secureCRT等终端连接的服务器暂时先不要开启网卡,开启则终端立即中断
编写脚本
CentOS 7.3 部署LVS + Keepalived 高可用群集
脚本内容如下
CentOS 7.3 部署LVS + Keepalived 高可用群集
CentOS 7.3 部署LVS + Keepalived 高可用群集
此时开启网卡
CentOS 7.3 部署LVS + Keepalived 高可用群集
回虚拟机中自测网站服务
CentOS 7.3 部署LVS + Keepalived 高可用群集
此时建议再重新启动一下web.sh脚本
另外一台web服务器同样的配置此处省略
6、客户机访问测试lvs,注意为做双击热备,客户机网卡的网关需配置成虚拟网卡ip
CentOS 7.3 部署LVS + Keepalived 高可用群集
CentOS 7.3 部署LVS + Keepalived 高可用群集
清理缓存再次访问可看到是另一台web服务器提供服务
CentOS 7.3 部署LVS + Keepalived 高可用群集
此时lvs配置完成没有问题
7、双机热备,主调度服务器配置
CentOS 7.3 部署LVS + Keepalived 高可用群集
CentOS 7.3 部署LVS + Keepalived 高可用群集
CentOS 7.3 部署LVS + Keepalived 高可用群集
启用服务
CentOS 7.3 部署LVS + Keepalived 高可用群集
8、备份调度服务器与主调度服务器仅keepalived配置文件配置有些许差别
Keepalived配置文件具体如下
CentOS 7.3 部署LVS + Keepalived 高可用群集
CentOS 7.3 部署LVS + Keepalived 高可用群集
CentOS 7.3 部署LVS + Keepalived 高可用群集
9、客户机测试
CentOS 7.3 部署LVS + Keepalived 高可用群集
CentOS 7.3 部署LVS + Keepalived 高可用群集
此时正常访问,下面我关闭主调度服务器的虚拟网卡再进行访问
CentOS 7.3 部署LVS + Keepalived 高可用群集
CentOS 7.3 部署LVS + Keepalived 高可用群集
CentOS 7.3 部署LVS + Keepalived 高可用群集
访问正常,说明备份调度服务器顶替了主调度服务器依然在工作。

猜你喜欢

转载自blog.51cto.com/13641879/2137255