高并发与负载均衡--lvs-DR模型试验

本文介绍了如何搭建LVS负载均衡系统,通过配置主机VIP和分机RIP,详细展示了LVS-DR模型的实现过程。首先创建主机IP,然后配置分机IP,并使用ipvsadm工具进行设置。最后,启动httpd服务并验证了高并发场景下的工作状态。
摘要由CSDN通过智能技术生成

 

注意:搭建时注意主机IP(VIP)和分机IP(RIP)的先后顺序,首先先创建主机IP,再配置RIP。

LVS搭建

LVS主机VIP配置操作如下:

[root@centos7-1 ~]# ifconfig
ens33: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.159.10  netmask 255.255.255.0  broadcast 192.168.159.255
        inet6 fe80::20c:29ff:fe99:5ef2  prefixlen 64  scopeid 0x20<link>
        ether 00:0c:29:99:5e:f2  txqueuelen 1000  (Ethernet)
        RX packets 1349266  bytes 1278637291 (1.1 GiB)
        RX errors 101  dropped 0  overruns 0  frame 0
        TX packets 344151  bytes 24511218 (23.3 MiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0
        device interrupt 19  base 0x2000  

lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536
        inet 127.0.0.1  netmask 255.0.0.0
        inet6 ::1  prefixlen 128  scopeid 0x10<host>
        loop  txqueuelen 1000  (Local Loopback)
        RX packets 208  bytes 17968 (17.5 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 208  bytes 17968 (17.5 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

virbr0: flags=4099<UP,BROADCAST,MULTICAST>  mtu 1500
        inet 192.168.122.1  netmask 255.255.255.0  broadcast 192.168.122.255
        ether 52:54:00:98:fb:a9  txqueuelen 1000  (Ethernet)
        RX packets 0  bytes 0 (0.0 B)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 0  bytes 0 (0.0 B)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

[root@centos7-1 ~]# ifconfig eth33:2 192.168.159.100/24
SIOCSIFADDR: 没有那个设备
eth33:2: ERROR while getting interface flags: 没有那个设备
SIOCSIFNETMASK: 没有那个设备
[root@centos7-1 ~]# ifconfig ens33:2 192.168.159.100/24
[root@centos7-1 ~]# ifconfig
ens33: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.159.10  netmask 255.255.255.0  broadcast 192.168.159.255
        inet6 fe80::20c:29ff:fe99:5ef2  prefixlen 64  scopeid 0x20<link>
        ether 00:0c:29:99:5e:f2  txqueuelen 1000  (Ethernet)
        RX packets 1349468  bytes 1278652342 (1.1 GiB)
        RX errors 101  dropped 0  overruns 0  frame 0
        TX packets 344250  bytes 24522004 (23.3 MiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0
        device interrupt 19  base 0x2000  

ens33:2: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.159.100  netmask 255.255.255.0  broadcast 192.168.159.255
        ether 00:0c:29:99:5e:f2  txqueuelen 1000  (Ethernet)
        device interrupt 19  base 0x2000  

lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536
        inet 127.0.0.1  netmask 255.0.0.0
        inet6 ::1  prefixlen 128  scopeid 0x10<host>
        loop  txqueuelen 1000  (Local Loopback)
        RX packets 208  bytes 17968 (17.5 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 208  bytes 17968 (17.5 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

virbr0: flags=4099<UP,BROADCAST,MULTICAST>  mtu 1500
        inet 192.168.122.1  netmask 255.255.255.0  broadcast 192.168.122.255
        ether 52:54:00:98:fb:a9  txqueuelen 1000  (Ethernet)
        RX packets 0  bytes 0 (0.0 B)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 0  bytes 0 (0.0 B)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

[root@centos7-1 ~]# echo 1 > /proc/sys/net/ipv4/ip_forward

[root@centos7-1 ~]# yum install ipvsadm -y
已加载插件:fastestmirror, langpacks
Loading mirror speeds from cached hostfile
 * base: mirrors.aliyun.com
 * extras: mirrors.aliyun.com
 * updates: mirrors.aliyun.com
base                                                      | 3.6 kB  00:00:00     
extras                                                    | 2.9 kB  00:00:00     
updates                                                   | 2.9 kB  00:00:00     
updates/7/x86_64/primary_db                               | 5.8 MB  00:00:02     
正在解决依赖关系
--> 正在检查事务
---> 软件包 ipvsadm.x86_64.0.1.27-7.el7 将被 安装
--> 解决依赖关系完成

依赖关系解决

=================================================================================
 Package           架构             版本                    源              大小
=================================================================================
正在安装:
 ipvsadm           x86_64           1.27-7.el7              base            45 k

事务概要
=================================================================================
安装  1 软件包

总下载量:45 k
安装大小:75 k
Downloading packages:
ipvsadm-1.27-7.el7.x86_64.rpm                             |  45 kB  00:00:00     
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  正在安装    : ipvsadm-1.27-7.el7.x86_64                                    1/1 
  验证中      : ipvsadm-1.27-7.el7.x86_64                                    1/1 

已安装:
  ipvsadm.x86_64 0:1.27-7.el7                                                    

完毕!
[root@centos7-1 ~]# ipvsadm -A -t 192.168.159.100:80 -s rr
[root@centos7-1 ~]# 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.159.100:80 rr
[root@centos7-1 ~]# ipvsadm -a -t 192.168.159.100:80 -r 192.168.159.12:80 -g
[root@centos7-1 ~]# 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.159.100:80 rr
  -> 192.168.159.12:80            Route   1      0          0         
[root@centos7-1 ~]# ipvsadm -a -t 192.168.159.100:80 -r 192.168.159.13:80 -g
[root@centos7-1 ~]# 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.159.100:80 rr
  -> 192.168.159.12:80            Route   1      0          0         
  -> 192.168.159.13:80            Route   1      0          0         
[root@centos7-1 ~]# netstat -natp
Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name    
tcp        0      0 0.0.0.0:111             0.0.0.0:*               LISTEN      1/systemd           
tcp        0      0 0.0.0.0:6000            0.0.0.0:*               LISTEN      5444/X              
tcp        0      0 192.168.122.1:53        0.0.0.0:*               LISTEN      7418/dnsmasq        
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN      5251/sshd           
tcp        0      0 127.0.0.1:631           0.0.0.0:*               LISTEN      5253/cupsd          
tcp        0      0 127.0.0.1:25            0.0.0.0:*               LISTEN      5517/master         
tcp        0      0 127.0.0.1:6010          0.0.0.0:*               LISTEN      15857/sshd: root@pt 
tcp        0      0 127.0.0.1:6011          0.0.0.0:*               LISTEN    

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值