lvs-nat模式实现http负载均衡集群

环境

名称IP类型
DR192.168.163.250VIP
DR192.168.163.135DIP
RS1192.168.163.137RIP
RS2192.168.163.134RIP

在DR上配置DIP(135)和VIP(250)

[root@DR network-scripts]# cat ifcfg-ens160 
TYPE=Ethernet
BOOTPROTO=static
NAME=ens160
DEVICE=ens160
ONBOOT=yes

IPADDR0=192.168.163.135
GATEWAY0=192.168.163.1
NETMASK0=255.255.255.0

IPADDR1=192.168.163.250
GATEWAY1=192.168.163.1

接着.测试本机可以ping通VIP

在RS上分别配置RIP,并将网关指向DIP

[root@localhost network-scripts]# cat ifcfg-ens160 
TYPE=Ethernet
BROWSER_ONLY=no
BOOTPROTO=dhcp
NAME=ens160
DEVICE=ens160
ONBOOT=yes

IPADDR=192.168.163.134
GATEWAY=192.168.163.135
NETMASK=255.255.255.0

在DR上开启IP转发,配置转发规则

开启转发功能

[root@DR ~]# vim /etc/sysctl.conf
[root@DR ~]# sysctl -p
net.ipv4.ip_forward = 1

配置规则

[root@DR yum.repos.d]# ipvsadm -A -t 192.168.163.250:80 -s rr
[root@DR yum.repos.d]# ipvsadm -a -t 192.168.163.250:80 -r 192.168.163.134:80 -m
[root@DR yum.repos.d]# ipvsadm -a -t 192.168.163.250:80 -r 192.168.163.137:80 -m

查看规则

[root@DR yum.repos.d]# 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.163.250:80 rr
  -> 192.168.163.134:80           Masq    1      0          0         
  -> 192.168.163.137:80           Masq    1      0          0         

保存

[root@DR yum.repos.d]# ipvsadm -Sn > /etc/sysconfig/ipvsadm
[root@DR yum.repos.d]# cat /etc/sysconfig/ipvsadm
-A -t 192.168.163.250:80 -s rr
-a -t 192.168.163.250:80 -r 192.168.163.134:80 -m -w 1
-a -t 192.168.163.250:80 -r 192.168.163.137:80 -m -w 1

在RS上分别配置HTTP

[root@localhost yum.repos.d]# cd /var/www/html
[root@localhost html]# echo "RS1" > index.html
[root@localhost html]# systemctl enable --now httpd
Created symlink /etc/systemd/system/multi-user.target.wants/httpd.service → /usr/lib/systemd/system/httpd.service.
[root@localhost html]# ss -antl
State   Recv-Q  Send-Q     Local Address:Port                 Peer Address:Port               
LISTEN  0       128              0.0.0.0:22                        0.0.0.0:*                  
LISTEN  0       128                    *:80                              *:*                  
LISTEN  0       128                 [::]:22                           [::]:*     

验证

在这里插入图片描述

在这里插入图片描述

[root@DR ~]# curl http:///192.168.163.250
RS1
[root@DR ~]# curl http:///192.168.163.250
RS2

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值