DR模式
LVS服务器(DR) | DIP:192.168.235.135 | VIP:192.168.235.250 |
---|
apache服务器(RS1) | IP:192.168.235.125 | VIP:192.168.235.250 |
apache服务器(RS2) | IP:192.168.235.156 | VIP:192.168.235.250 |
关闭防火墙和selinux
[root@DR ~]
Removed /etc/systemd/system/multi-user.target.wants/firewalld.service.
Removed /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service.
[root@RS1 ~]
[root@rs2 ~]
RS1和RS2下载安装httpd修改内容来提供访问
[root@RS1 ~]
[root@RS1 ~]
Created symlink /etc/systemd/system/multi-user.target.wants/httpd.service → /usr/lib/systemd/system/httpd.service.
[root@RS1 ~]
[root@rs2 ~]
[root@rs2 ~]
Created symlink from /etc/systemd/system/multi-user.target.wants/httpd.service to /usr/lib/systemd/system/httpd.service.
[root@rs2 ~]
DR配置VIP
[root@DR ~]
[root@DR ~]
2: ens160: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP group default qlen 1000
link/ether 00:0c:29:9f:b9:ba brd ff:ff:ff:ff:ff:ff
inet 192.168.235.135/24 brd 192.168.235.255 scope global dynamic noprefixroute ens160
valid_lft 1698sec preferred_lft 1698sec
inet 192.168.235.250/24 scope global secondary ens160
valid_lft forever preferred_lft forever
inet6 fe80::7ff5:eb54:cd1e:90c1/64 scope link noprefixroute
valid_lft forever preferred_lft forever
RS配置apr内核参数
[root@RS1 ~]
net.ipv4.conf.all.arp_ignore = 1
net.ipv4.conf.all.arp_announce = 2
[root@RS1 ~]
net.ipv4.conf.all.arp_ignore = 1
net.ipv4.conf.all.arp_announce = 2
[root@rs2 ~]
net.ipv4.conf.all.arp_ignore = 1
net.ipv4.conf.all.arp_announce = 2
[root@rs2 ~]
net.ipv4.conf.all.arp_ignore = 1
net.ipv4.conf.all.arp_announce = 2
RS上配置VIP
一定要先设置好内核参数在配置VIP,如果先配置VIP,VIP配置好后会立即通告给所有人,而修改内核参数就是为了不通告
[root@RS1 ~]
[root@RS1 ~]
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP group default qlen 1000
link/ether 00:0c:29:73:89:b1 brd ff:ff:ff:ff:ff:ff
inet 192.168.235.125/24 brd 192.168.235.255 scope global noprefixroute eth0
valid_lft forever preferred_lft forever
inet 192.168.235.250/24 scope global secondary eth0
valid_lft forever preferred_lft forever
inet6 fe80::20c:29ff:fe73:89b1/64 scope link
valid_lft forever preferred_lft forever
[root@rs2 ~]
[root@rs2 ~]
2: ens33: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
link/ether 00:0c:29:d7:f4:87 brd ff:ff:ff:ff:ff:ff
inet 192.168.235.156/24 brd 192.168.235.255 scope global noprefixroute dynamic ens33
valid_lft 1481sec preferred_lft 1481sec
inet 192.168.235.250/24 scope global secondary ens33
valid_lft forever preferred_lft forever
inet6 fe80::e7a9:b0e1:c122:7cf6/64 scope link noprefixroute
valid_lft forever preferred_lft forever
DR上配置 转发规则
LVS依赖于ipvsadm来进行配置,所以首先安装ipvsadm
[root@DR ~]
[root@DR ~]
[root@DR ~]
[root@DR ~]
[root@DR ~]
-A -t 192.168.235.250:80 -s rr
-a -t 192.168.235.250:80 -r 192.168.235.125:80 -g -w 1
-a -t 192.168.235.250:80 -r 192.168.235.156:80 -g -w 1
[root@DR ~]
-A:添加虚拟服务器
-t :指定vip及tcp端口
-s:指定算法
rr:轮询
-a :添加节点
-t :指定vip和端口
-r :指定节点ip及端口
-g:表示使用DR模式
-w:设置权重
测试
![在这里插入图片描述](https://i-blog.csdnimg.cn/blog_migrate/19742eaf195511a73a628a495e2596a6.png)
![在这里插入图片描述](https://i-blog.csdnimg.cn/blog_migrate/0e34c50b5988d5969d09dd354a8de41a.png)
NAT模式
LVS服务器(DR) | DIP:192.168.235.135 | VIP:192.168.235.250 |
---|
apache服务器(RS1) | IP:192.168.235.125 | 网关指向DIP |
apache服务器(RS2) | IP:192.168.235.156 | 网关指向DIP |
关闭防火墙和seLinux
[root@DR ~]
Removed /etc/systemd/system/multi-user.target.wants/firewalld.service.
Removed /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service.
[root@DR ~]
[root@RS1 ~]
Removed /etc/systemd/system/multi-user.target.wants/firewalld.service.
Removed /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service.
[root@RS1 ~]
[root@rs2 ~]
Removed /etc/systemd/system/multi-user.target.wants/firewalld.service.
Removed /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service.
[root@rs2 ~]
配置 DR的VIP
[root@DR ~]
[root@DR ~]
2: ens160: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP group default qlen 1000
link/ether 00:0c:29:9f:b9:ba brd ff:ff:ff:ff:ff:ff
inet 192.168.235.135/24 brd 192.168.235.255 scope global dynamic noprefixroute ens160
valid_lft 1698sec preferred_lft 1698sec
inet 192.168.235.250/24 scope global secondary ens160
valid_lft forever preferred_lft forever
inet6 fe80::7ff5:eb54:cd1e:90c1/64 scope link noprefixroute
valid_lft forever preferred_lft forever
下载httpd并修改显示内容
[root@RS1 ~]
[root@RS1 ~]
[root@RS1 ~]
[root@RS1 ~]
[root@rs2 ~]
[root@rs2 ~]
[root@rs2 ~]
配置 RS1网关指向DIP
[root@RS1 ~]
IPADDR=192.168.235.125
GATEWAY=192.168.235.9 / 成功
NETMASK=255.255.255.0
DNS1=114.114.114.114
DNS2=8.8.8.8
[root@RS2 ~]
IPADDR=192.168.235.156
GATEWAY=192.168.235.9 /成功
NETMASK=255.255.255.0
DNS1=114.114.114.114
DR上配置 转发规则
LVS依赖于ipvsadm来进行配置,所以首先安装ipvsadm
[root@DR ~]
开启转发功能
[root@DR ~]
[root@DR ~]
net.ipv4.ip_forward = 1
配置转发规则
[root@DR ~]
[root@DR ~]
IP Virtual Server version 1.2.1 (size=4096)
Prot LocalAddress:Port Scheduler Flags
-> RemoteAddress:Port Forward Weight ActiveConn InActConn
TCP 192.168.235.250:80 rr
[root@DR ~]
[root@DR ~]
[root@DR ~]
[root@DR ~]
-A -t 192.168.235.250:80 -s rr
-a -t 192.168.235.250:80 -r 192.168.235.125:80 -m -w 1
-a -t 192.168.235.250:80 -r 192.168.235.156:80 -m -w 1
-A:添加虚拟服务器
-t :指定vip及tcp端口
-s:指定算法
rr:轮询
-a :添加节点
-t :指定vip和端口
-r :指定节点ip及端口
-g:表示使用DR模式
-w:设置权重
测试
[root@DR ~]
hello yaya 192.168.235.125
[root@DR ~]
hello yaya 192.168.235.156