LVS的DR模式和NAT模式配置http

lvs 的 NAT

LVS服务器(DR)DIP:192.168.126.156VIP:192.168.126.250
apache服务器(RS1)IP:192.168.126.155VIP:192.168.126.250
apache服务器(RS2)IP:192.168.126.154VIP:192.168.126.250
##配置DR的IP
[root@localhost ~]# vim /etc/sysconfig/network-scripts/ifcfg-ens160  
TYPE=Ethernet
PROXY_METHOD=none
BROWSER_ONLY=no
BOOTPROTO=static
DEFROUTE=yes
IPV4_FAILURE_FATAL=no
IPV6INIT=yes
IPV6_AUTOCONF=yes
IPV6_DEFROUTE=yes
IPV6_FAILURE_FATAL=no
IPV6_ADDR_GEN_MODE=stable-privacy
NAME=ens160
UUID=4e00abb5-a536-48b9-a093-ce0b513ffbfb
DEVICE=ens160
ONBOOT=yes
IPADDR=192.168.126.156
IPADDR1=192.168.126.250
NETMASK=255.255.255.0
GATEWAY=192.168.126.2
DNS1=114.114.114.114
DNS2=8.8.8.8

[root@localhost ~]# ifup ens160

##开启转发功能
[root@localhost ~]# vim /etc/sysctl.conf 
net.ipv4.ip_forward = 1           ##添加此行
[root@localhost ~]# sysctl -p
net.ipv4.ip_forward = 1

##添加规则调度器
[root@localhost ~]# ipvsadm -A -t 192.168.126.156:80 -s rr
[root@localhost ~]# ipvsadm -ln
IP Virtual Server version 1.2.1 (size=4096)
Prot LocalAddress:Port Scheduler Flags
  -> RemoteAddress:Port           Forward Weight ActiveConn InActConn
TCP  192.168.126.156:80 rr
[root@localhost ~]# ipvsadm -a -t 192.168.126.156:80 -r 192.168.126.155:80 -m
[root@localhost ~]# ipvsadm -a -t 192.168.126.156 -r 192.168.126.154:80 -m
[root@localhost ~]# ipvsadm -Sn > /etc/sysconfig/ipvsadm
[root@localhost ~]# vim /etc/sysconfig/ipvsadm
[root@localhost ~]# cat /etc/sysconfig/ipvsadm
-A -t 192.168.14.10:80 -s rr
-a -t 192.168.14.10:80 -r 192.168.126.156:80 -m -w 1
-a -t 192.168.14.10:80 -r 192.168.126.154:80 -m -w 1

[root@localhost ~]# echo '192.168.126.155' > /var/www/html/index.html
[root@localhost ~]# systemctl enable --now httpd
Created symlink /etc/systemd/system/multi-user.target.wants/httpd.service → /usr/lib/systemd/system/httpd.service.
[root@localhost ~]# echo '192.168.126.154' > /var/www/html/index.html
[root@localhost ~]# systemctl enable --now httpd

[root@localhost network-scripts]# curl http://192.168.126.250
yi
[root@localhost network-scripts]# curl http://192.168.126.250
er

lvs 的 DR

LVS服务器(DR)DIP:192.168.126.155VIP:192.168.126.250
apache服务器(RS1)IP:192.168.126.154VIP:192.168.126.250
apache服务器(RS2)IP:192.168.126.156VIP:192.168.126.250
TYPE=Ethernet
PROXY_METHOD=none
BROWSER_ONLY=no
BOOTPROTO=static
DEFROUTE=yes
IPV4_FAILURE_FATAL=no
IPV6INIT=yes
IPV6_AUTOCONF=yes
IPV6_DEFROUTE=yes
IPV6_FAILURE_FATAL=no
IPV6_ADDR_GEN_MODE=stable-privacy
NAME=ens160
UUID=4e00abb5-a536-48b9-a093-ce0b513ffbfb
DEVICE=ens160
ONBOOT=yes
IPADDR=192.168.126.155
IPADDR1=192.168.126.250
NETMASK=255.255.255.0
GATEWAY=192.168.126.2
DNS1=114.114.114.114
DNS2=8.8.8.8

[root@RS1 ~]# ifup ens160

##配置RS1与RS2的APR内核参数
[root@RS1 ~]# vim /etc/sysctl.conf 
[root@RS1 ~]# cat /etc/sysctl.conf 
net.ipv4.conf.all.arp_ignore = 1 
net.ipv4.conf.all.arp_announce = 2

[root@RS1 ~]# sysctl -p
net.ipv4.conf.all.arp_ignore = 1
net.ipv4.conf.all.arp_announce = 2

[root@RS2 ~]# vim /etc/sysctl.conf 
[root@RS2 ~]# cat /etc/sysctl.conf 
net.ipv4.conf.all.arp_ignore = 1 
net.ipv4.conf.all.arp_announce = 2

[root@RS2 ~]# sysctl -p
net.ipv4.conf.all.arp_ignore = 1
net.ipv4.conf.all.arp_announce = 2


[root@RS2 ~]# vim /etc/sysconfig/network-scripts/ifcfg-ens160
TYPE=Ethernet
PROXY_METHOD=none
BROWSER_ONLY=no
BOOTPROTO=static
DEFROUTE=yes
IPV4_FAILURE_FATAL=no
IPV6INIT=yes
IPV6_AUTOCONF=yes
IPV6_DEFROUTE=yes
IPV6_FAILURE_FATAL=no
IPV6_ADDR_GEN_MODE=stable-privacy
NAME=ens160
UUID=4e00abb5-a536-48b9-a093-ce0b513ffbfb
DEVICE=ens160
ONBOOT=yes
IPADDR=192.168.126.154
IPADDR1=192.168.126.250
NETMASK=255.255.255.0
GATEWAY=192.168.126.2
DNS1=114.114.114.114
DNS2=8.8.8.8

[root@RS2 ~]# ifup ens160

##DR上安装ipvsadm
[root@RS1 ~]# yum -y install ipvsadm
[root@RS1 ~]# ipvsadm -a -t 192.168.126.250:80 -r 192.168.126.154:80 -g
[root@RS1 ~]# ipvsadm -a -t 192.168.126.250:80 -r 192.168.126.156:80 -g

[root@RS1 ~]# ipvsadm -Sn > /etc/sysconfig/ipvsadm
[root@RS1 ~]# echo "yi" > /usr/share/httpd/noindex/index.html
[root@RS2 ~]# echo "er" > /usr/share/httpd/noindex/index.html
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值