LVS-DR模式+keepalived+nginx+tomcat实现动静分离、负载均衡、高可用实验

实验条件:

test2——20.0.0.20——主服务器——ipvsadm、keepalived服务

test3——20.0.0.30——备服务器——ipvsadm、keepalived服务

nginx5——20.0.0.51——后端真实服务器1(tomcat的代理服务器)——nginx服务

nginx6——20.0.0.61——后端真实服务器2(tomcat的代理服务器)——nginx服务

tomcat——20.0.0.12——后端真实服务器3——tomcat服务

tomcat——20.0.0.22——后端真实服务器4——tomcat服务

VIP地址:20.0.0.200

test1客户端

LVS-DR模式+keepalived+nginx+tomcat实现动静分离、负载均衡、高可用实验_第1张图片

实验步骤:

  1. 配置test2主服务器

(1)下载ipvsadm、keepalived服务

LVS-DR模式+keepalived+nginx+tomcat实现动静分离、负载均衡、高可用实验_第2张图片

重启服务

LVS-DR模式+keepalived+nginx+tomcat实现动静分离、负载均衡、高可用实验_第3张图片

保存配置文件:ipvsadm-save > /etc/sysconfig/ipvsadm

(2)备份keepalived服务的配置文件

LVS-DR模式+keepalived+nginx+tomcat实现动静分离、负载均衡、高可用实验_第4张图片

(3)修改keepalived服务的配置文件

LVS-DR模式+keepalived+nginx+tomcat实现动静分离、负载均衡、高可用实验_第5张图片

LVS-DR模式+keepalived+nginx+tomcat实现动静分离、负载均衡、高可用实验_第6张图片

(4)查看vip地址和集群

LVS-DR模式+keepalived+nginx+tomcat实现动静分离、负载均衡、高可用实验_第7张图片

LVS-DR模式+keepalived+nginx+tomcat实现动静分离、负载均衡、高可用实验_第8张图片

(5)关闭主服务器的转发功能和重定向

net.ipv4.ip_forward = 0

net.ipv4.conf.all.send_redirects = 0

net.ipv4.conf.default.send_redirects = 0

net.ipv4.conf.ens33.send_redirects = 0

LVS-DR模式+keepalived+nginx+tomcat实现动静分离、负载均衡、高可用实验_第9张图片

LVS-DR模式+keepalived+nginx+tomcat实现动静分离、负载均衡、高可用实验_第10张图片

2、配置test3主服务器

(1)下载ipvsadm、keepalived服务

LVS-DR模式+keepalived+nginx+tomcat实现动静分离、负载均衡、高可用实验_第11张图片

重启服务

保存配置文件:ipvsadm-save > /etc/sysconfig/ipvsadm

(2)备份keepalived服务的配置文件

LVS-DR模式+keepalived+nginx+tomcat实现动静分离、负载均衡、高可用实验_第12张图片

(3)远程复制并修改主服务器keepalived服务的配置文件

LVS-DR模式+keepalived+nginx+tomcat实现动静分离、负载均衡、高可用实验_第13张图片

(4)查看vip地址和集群

LVS-DR模式+keepalived+nginx+tomcat实现动静分离、负载均衡、高可用实验_第14张图片

LVS-DR模式+keepalived+nginx+tomcat实现动静分离、负载均衡、高可用实验_第15张图片

(5)关闭备服务器的转发功能和重定向

LVS-DR模式+keepalived+nginx+tomcat实现动静分离、负载均衡、高可用实验_第16张图片

LVS-DR模式+keepalived+nginx+tomcat实现动静分离、负载均衡、高可用实验_第17张图片

3、配置nginx5(test的后端真实服务器,tomcat的代理服务器)

(1)安装nginx服务

(2)设置回环接口

LVS-DR模式+keepalived+nginx+tomcat实现动静分离、负载均衡、高可用实验_第18张图片

(3)绑定回环接口

(4)内核参数优化(只让RIP返回响应结果)

net.ipv4.conf.lo.arp_ignore = 1

net.ipv4.conf.lo.arp_announce = 2

net.ipv4.conf.all.arp_ignore = 1

net.ipv4.conf.all.arp_announce = 2

LVS-DR模式+keepalived+nginx+tomcat实现动静分离、负载均衡、高可用实验_第19张图片

LVS-DR模式+keepalived+nginx+tomcat实现动静分离、负载均衡、高可用实验_第20张图片

(5)设置静态页面

LVS-DR模式+keepalived+nginx+tomcat实现动静分离、负载均衡、高可用实验_第21张图片

LVS-DR模式+keepalived+nginx+tomcat实现动静分离、负载均衡、高可用实验_第22张图片

(6)设置反向代理(作为tomcat的代理服务器访问tomcat)

LVS-DR模式+keepalived+nginx+tomcat实现动静分离、负载均衡、高可用实验_第23张图片

LVS-DR模式+keepalived+nginx+tomcat实现动静分离、负载均衡、高可用实验_第24张图片

4、配置nginx5(test的后端真实服务器,tomcat的代理服务器)

(1)安装nginx服务

(2)设置回环接口

LVS-DR模式+keepalived+nginx+tomcat实现动静分离、负载均衡、高可用实验_第25张图片

LVS-DR模式+keepalived+nginx+tomcat实现动静分离、负载均衡、高可用实验_第26张图片

(3)绑定回环接口

(4)内核参数优化(只让RIP返回响应结果)

LVS-DR模式+keepalived+nginx+tomcat实现动静分离、负载均衡、高可用实验_第27张图片

LVS-DR模式+keepalived+nginx+tomcat实现动静分离、负载均衡、高可用实验_第28张图片

(5)设置静态页面

LVS-DR模式+keepalived+nginx+tomcat实现动静分离、负载均衡、高可用实验_第29张图片

LVS-DR模式+keepalived+nginx+tomcat实现动静分离、负载均衡、高可用实验_第30张图片

(6)设置反向代理(作为tomcat的代理服务器访问tomcat)

LVS-DR模式+keepalived+nginx+tomcat实现动静分离、负载均衡、高可用实验_第31张图片

LVS-DR模式+keepalived+nginx+tomcat实现动静分离、负载均衡、高可用实验_第32张图片

5、配置后端真实服务器的动态页面

(1)tomcat1

LVS-DR模式+keepalived+nginx+tomcat实现动静分离、负载均衡、高可用实验_第33张图片

LVS-DR模式+keepalived+nginx+tomcat实现动静分离、负载均衡、高可用实验_第34张图片

LVS-DR模式+keepalived+nginx+tomcat实现动静分离、负载均衡、高可用实验_第35张图片

LVS-DR模式+keepalived+nginx+tomcat实现动静分离、负载均衡、高可用实验_第36张图片

用./shutdown.sh和./startup.sh脚本文件启动服务,不是用restart

LVS-DR模式+keepalived+nginx+tomcat实现动静分离、负载均衡、高可用实验_第37张图片

(2)tomcat2

LVS-DR模式+keepalived+nginx+tomcat实现动静分离、负载均衡、高可用实验_第38张图片

LVS-DR模式+keepalived+nginx+tomcat实现动静分离、负载均衡、高可用实验_第39张图片

LVS-DR模式+keepalived+nginx+tomcat实现动静分离、负载均衡、高可用实验_第40张图片

LVS-DR模式+keepalived+nginx+tomcat实现动静分离、负载均衡、高可用实验_第41张图片

LVS-DR模式+keepalived+nginx+tomcat实现动静分离、负载均衡、高可用实验_第42张图片

6、测试

(1)静态页面

LVS-DR模式+keepalived+nginx+tomcat实现动静分离、负载均衡、高可用实验_第43张图片

(2)动态页面

LVS-DR模式+keepalived+nginx+tomcat实现动静分离、负载均衡、高可用实验_第44张图片

(3)模拟主服务器故障

LVS-DR模式+keepalived+nginx+tomcat实现动静分离、负载均衡、高可用实验_第45张图片

LVS-DR模式+keepalived+nginx+tomcat实现动静分离、负载均衡、高可用实验_第46张图片

测试

LVS-DR模式+keepalived+nginx+tomcat实现动静分离、负载均衡、高可用实验_第47张图片

(4)模拟主服务器恢复

LVS-DR模式+keepalived+nginx+tomcat实现动静分离、负载均衡、高可用实验_第48张图片

LVS-DR模式+keepalived+nginx+tomcat实现动静分离、负载均衡、高可用实验_第49张图片

测试

LVS-DR模式+keepalived+nginx+tomcat实现动静分离、负载均衡、高可用实验_第50张图片

你可能感兴趣的:(lvs,nginx,tomcat)