当前位置:   article > 正文

lvs模式配置_lvs配置

lvs配置

1. lvs简介

LVS(Linux Virtual Server)即Linux虚拟服务器,是由章文嵩博士主导的开源负载均衡项目,目前LVS已经被集成到Linux内核模块中。该项目在Linux内核中实现了基于IP的数据请求负载均衡调度方案,其体系结构如图1所示,终端互联网用户从外部访问公司的外部负载均衡服务器,终端用户的Web请求会发送给LVS调度器,调度器根据自己预设的算法决定将该请求发送给后端的某台Web服务器,比如,轮询算法可以将外部的请求平均分发给后端的所有服务器,终端用户访问LVS调度器虽然会被转发到后端真实的服务器,但如果真实服务器连接的是相同的存储,提供的服务也是相同的服务,最终用户不管是访问哪台真实服务器,得到的服务内容都是一样的,整个集群对用户而言都是透明的。最后根据LVS工作模式的不同,真实服务器会选择不同的方式将用户需要的数据发送到终端用户,LVS工作模式分为NAT模式、TUN模式、以及DR模式。

1.1 Ivs: Linux Virtual Server

四层交换,四层路由:
根据请求报文的目标IP和PORT将其转发至后端主机集群中的某-台主机(根据挑选算法)
netfilter :

  • PREROUTING --> INPUT
  • PREROUTING --> FORWARD --> POSTROUTING
  • OUTPUT --> POSTROUTING

Ivs:
ipvsadm/ipvs

ipvsadm:用户空间的命令行工具,用于管理集群服务
ipvs:工作于内核中netfilter INPUT钩子.上

支持TCP,UDP,AH, EST, AH_ EST, SCTP等诸多协议
grep -i -A 2 "ipvs’ /boot/config-2.6.32-504.el6.x86_ 64
查看系统对ipvs的支持情况,包括算法

Ivs arch:

  • 调度器: director, dispatcher, balancer
  • RS: Real Server
  • Client IP: CIP
  • Director Virutal IP: VIP
  • Director IP: DIP
  • Real Server IP: RIP

lvs,4种工作模式
一,LVS_NAT
在这里插入图片描述

二,LVS_DR
在这里插入图片描述
三,LVS_TUN
在这里插入图片描述

1.2.Ivs scheduler: lvs调度器,即Ivs挑 选RS的算法

静态方法:仅根据算法本身进行调度

  • RR: round robin,轮调、轮询
  • WRR: weightedrr, 加权的rr,根据一定的比例进行轮调, 比如每次RS1给2个请求, RS2给1个请求
  • SH: source hash,源地址hash,实现session保持 的机制,将来自于同一个IP的请求始终调度至同一RS,每个服务单独调度
  • DH: destination hash,目标地址hash,将对同一个目标(资源)的请求始终发往同一个RS
    动态方法:根据算法及各RS的当前负载状态进行调度,根据指定的算法算出overhead (负载),最终挑选出overhead
    值最小的则为被选中的RS
  • LC: Least Connection,最少连接数,算法如下:
    overhead = Active * 256 + Inactive
  • WLC: WeightedLC, 加权的LC,算法如下:
    overhead= (Active* 256+Inactive) / weight
  • SED: Shortest Expection Delay,最短期望延迟,算法如下:
    overhead= (Active+ 1) * 256 /weight
  • NQ: Nevel Queue,是SED算法的改进,根据SED算法每台主机第- -次至少要均分配一 次,然后再按SED算法来挑
  • LBLC: Locality-Based LC,基于本地的最少连接数,即为动态的DH算法
    正向代理情形下的cache server调度
  • LBLCR: Locality- Based Least-Connection with Replication,带复制功能的LBLC算法
    准备工作
服务器名称IP版本
lvs192.168.106.20centos8/redhat8
RS1192.168.106.16centos8/redhat8
RS2192.168.106.17centos8/redhat8

为lvs这台虚拟机添加一块网卡

在这里插入图片描述

2.配置nat模式

配置IP地址信息
director (dip vip )
RS (rip)

//多了一个ens224网卡
[root@lvs ~]# ip a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host 
       valid_lft forever preferred_lft forever
2: ens160: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP group default qlen 1000
    link/ether 00:0c:29:9c:36:92 brd ff:ff:ff:ff:ff:ff
    inet 192.168.106.20/24 brd 192.168.106.255 scope global noprefixroute ens160
       valid_lft forever preferred_lft forever
    inet6 fe80::20c:29ff:fe9c:3692/64 scope link 
       valid_lft forever preferred_lft forever
3: ens224: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP group default qlen 1000
    link/ether 00:0c:29:9c:36:9c brd ff:ff:ff:ff:ff:ff
    inet 192.168.127.130/24 brd 192.168.127.255 scope global dynamic noprefixroute ens224
       valid_lft 1676sec preferred_lft 1676sec
    inet6 fe80::a7ee:c9be:508c:e9b6/64 scope link noprefixroute 
       valid_lft forever preferred_lft forever
//配置ens160网卡
[root@lvs ~]# cat /etc/sysconfig/network-scripts/ifcfg-ens160 
TYPE=Ethernet
BOOTPROTO=static
NAME=ens160
DEVICE=ens160
ONBOOT=yes
PREFIX=24
IPADDR=192.168.106.20
GATEWAY=192.168.106.2
DNS1=8.8.8.8

//配置ens224网卡
[root@lvs ~]# cd /etc/sysconfig/network-scripts/
[root@lvs network-scripts]# cp ifcfg-ens160 ifcfg-ens224
[root@lvs network-scripts]# ls
ifcfg-ens160  ifcfg-ens224
[root@lvs network-scripts]# cat ifcfg-ens224     //修改如下内容
TYPE=Ethernet
BOOTPROTO=static
NAME=ens160
DEVICE=ens160
ONBOOT=yes
PREFIX=24
IPADDR=192.168.127.130       //在虚拟环境下只能有一个网关,所以这里就没有设置网关
//重启一下
[root@lvs network-scripts]# reboot 
//ping一下
[root@lvs ~]# ping www.baidu.com
PING www.a.shifen.com (14.215.177.38) 56(84) bytes of data.
64 bytes from 14.215.177.38 (14.215.177.38): icmp_seq=1 ttl=128 time=33.1 ms
64 bytes from 14.215.177.38 (14.215.177.38): icmp_seq=2 ttl=128 time=29.9 ms
64 bytes from 14.215.177.38 (14.215.177.38): icmp_seq=3 ttl=128 time=30.4 ms
64 bytes from 14.215.177.38 (14.215.177.38): icmp_seq=4 ttl=128 time=29.4 ms
^C
--- www.a.shifen.com ping statistics ---
4 packets transmitted, 4 received, 0% packet loss, time 3007ms
rtt min/avg/max/mdev = 29.382/30.695/33.050/1.418 ms     //是可以访问到外网的
//配置RS1网卡
[root@RS1 ~]# yum -y install httpd    //先安装httpd
[root@RS1 ~]# cat /etc/sysconfig/network-scripts/ifcfg-ens160 
TYPE=Ethernet
BOOTPROTO=static
NAME=ens160
DEVICE=ens160
ONBOOT=yes
IPADDR=192.168.106.16
PREFIX=24
GATEWAY=192.168.106.20   //这里的网关要指向lvs的IP
DNS1=8.8.8.8
//配置RS2的网卡
[root@RS2 ~]# yum -y install httpd    //先安装httpd
[root@RS2 ~]# cat /etc/sysconfig/network-scripts/ifcfg-ens160 
TYPE=Ethernet
BOOTPROTO=static
NAME=ens160
DEVICE=ens160
ONBOOT=yes
IPADDR=192.168.106.17
PREFIX=24
GATEWAY=192.168.106.20   //这里的网关要指向lvs的IP
DNS1=8.8.8.8
//开启director的IP转发功能
[root@lvs ~]# vim /etc/sysctl.conf 
[root@lvs ~]# cat /etc/sysctl.conf 
# sysctl settings are defined through files in
# /usr/lib/sysctl.d/, /run/sysctl.d/, and /etc/sysctl.d/.
#
# Vendors settings live in /usr/lib/sysctl.d/.
# To override a whole file, create a new file with the same in
# /etc/sysctl.d/ and put new settings there. To override
# only specific settings, add a file with a lexically later
# name in /etc/sysctl.d/ and put new settings there.
#
# For more information, see sysctl.conf(5) and sysctl.d(5).
net.ipv4.ip_forward = 1        //在此文件中添加这一行
[root@lvs ~]# sysctl -p
net.ipv4.ip_forward = 1
[root@lvs ~]# dnf -y install ipvsadm   //安装这个命令
//在director上添加并保存规则
[root@lvs ~]# ipvsadm -A -t 192.168.127.130:80 -s rr
[root@lvs ~]# ipvsadm -a -t 192.168.127.130:80 -r 192.168.106.16 -m
[root@lvs ~]# ipvsadm -a -t 192.168.127.130:80 -r 192.168.106.17 -m
[root@lvs ~]# ipvsadm -l
IP Virtual Server version 1.2.1 (size=4096)
Prot LocalAddress:Port Scheduler Flags
  -> RemoteAddress:Port           Forward Weight ActiveConn InActConn
TCP  lvs:http rr
  -> 192.168.106.16:http          Masq    1      0          0         
  -> 192.168.106.17:http          Masq    1      0          0         
  [root@lvs ~]# ipvsadm -Sn > /etc/sysconfig/ipvsadm     //写到这文件中
[root@lvs ~]# cat /etc/sysconfig/ipvsadm   
-A -t 192.168.127.130:80 -s rr 
-a -t 192.168.127.130:80 -r 192.168.106.16:80 -m -w 1
-a -t 192.168.127.130:80 -r 192.168.106.17:80 -m -w 1
//关闭sellinux和防火墙
//RS1
[root@RS1 html]# systemctl disable --now firewalld.service 
Removed /etc/systemd/system/multi-user.target.wants/firewalld.service.
Removed /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service.
[root@RS1 html]# setenforce 0
[root@RS1 ~]# cat /etc/selinux/config 

# This file controls the state of SELinux on the system.
# SELINUX= can take one of these three values:
#     enforcing - SELinux security policy is enforced.
#     permissive - SELinux prints warnings instead of enforcing.
#     disabled - No SELinux policy is loaded.
SELINUX=disabled     //修改为disabled
# SELINUXTYPE= can take one of these three values:
#     targeted - Targeted processes are protected,
#     minimum - Modification of targeted policy. Only selected processes are protected. 
#     mls - Multi Level Security protection.
SELINUXTYPE=targeted
//RS2
[root@RS2 ~]# systemctl disable --now firewalld.service 
Removed /etc/systemd/system/multi-user.target.wants/firewalld.service.
Removed /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service.
[root@RS2 ~]# vim /etc/selinux/config 
[root@RS2 ~]# setenforce 0
[root@RS2 ~]# cat /etc/selinux/config 

# This file controls the state of SELinux on the system.
# SELINUX= can take one of these three values:
#     enforcing - SELinux security policy is enforced.
#     permissive - SELinux prints warnings instead of enforcing.
#     disabled - No SELinux policy is loaded.
SELINUX=disabled     //修改为disabled
# SELINUXTYPE= can take one of these three values:
#     targeted - Targeted processes are protected,
#     minimum - Modification of targeted policy. Only selected processes are protected. 
#     mls - Multi Level Security protection.
SELINUXTYPE=targeted
//lvs
[root@lvs ~]# systemctl disable  --now firewalld
[root@lvs ~]# vim /etc/selinux/config 

# This file controls the state of SELinux on the system.
# SELINUX= can take one of these three values:
#     enforcing - SELinux security policy is enforced.
#     permissive - SELinux prints warnings instead of enforcing.
#     disabled - No SELinux policy is loaded.
SELINUX=disabled     //修改为disabled
# SELINUXTYPE= can take one of these three values:
#     targeted - Targeted processes are protected,
#     minimum - Modification of targeted policy. Only selected processes are protected. 
#     mls - Multi Level Security protection.
SELINUXTYPE=targeted
[root@lvs ~]# setenforce 0
setenforce: SELinux is disabled
//RS1和RS2分别放一个不同的网站。过程不做演示
//在虚拟机中测试
[root@lvs ~]# curl 192.168.127.130
hello world
[root@lvs ~]# curl 192.168.127.130
<!DOCTYPE html>
<html>
        <head>
                <meta charset="utf-8" />
                <title>在线考试试卷</title>
        </head>
        <body>
                <p><h1>HTML在线考试试题</h1></p>
        </body>
        <ol type="1">
                <li>.HTML中,换行使用的标签是()。</li>
                        <ol type="A">
                                <li>&lt;br/&gt;</li>
                                <li>&lt;p&gt;</li>
                                <li>&lt;hr/&gt;</li>
                                <li>&lt;img/&gt;</li>
                        </ol>
                <li>.&lt;img/&gt;标签的()属性用于指定图像的地址。</li>
                        <ol type="A">
                                <li>alt</li>
                                <li>href</li>
                                <li>src</li>
                                <li>addr</li>
                        </ol>
                <li>.创建一个超级链接使用的是()标签。</li>
                        <ol type="A">
                                <li>&lt;a&gt;</li>
                                <li>&lt;ol&gt;</li>
                                <li>&lt;img/&gt;</li>
                                <li>&lt;hr/&gt;</li>
                        </ol>
                <li>.&lt;img/&gt;标签的()属性用来设置图片与旁边内容的水平距离。</li>
                        <ol type="A">
                                <li>hspace</li>
                                <li>vspace</li>
                                <li>border</li>
                                <li>alt</li>
                        </ol>
                <li>.下面HTML结构中,不属于列表结构的是()。</li>
                        <ol type="A">
                                <li>ul-li</li>
                                <li>ol-li</li>
                                <li>dl-dt-dd</li>
                                <li>p-br</li>
                        </ol>
                </ol>
</html>
[root@lvs ~]# vim /etc/sysconfig/network-scripts/ifcfg-ens224 
[root@lvs ~]# curl 192.168.127.130
hello world
[root@lvs ~]# curl 192.168.127.130
<!DOCTYPE html>
<html>
        <head>
                <meta charset="utf-8" />
                <title>在线考试试卷</title>
        </head>
        <body>
                <p><h1>HTML在线考试试题</h1></p>
        </body>
        <ol type="1">
                <li>.HTML中,换行使用的标签是()。</li>
                        <ol type="A">
                                <li>&lt;br/&gt;</li>
                                <li>&lt;p&gt;</li>
                                <li>&lt;hr/&gt;</li>
                                <li>&lt;img/&gt;</li>
                        </ol>
                <li>.&lt;img/&gt;标签的()属性用于指定图像的地址。</li>
                        <ol type="A">
                                <li>alt</li>
                                <li>href</li>
                                <li>src</li>
                                <li>addr</li>
                        </ol>
                <li>.创建一个超级链接使用的是()标签。</li>
                        <ol type="A">
                                <li>&lt;a&gt;</li>
                                <li>&lt;ol&gt;</li>
                                <li>&lt;img/&gt;</li>
                                <li>&lt;hr/&gt;</li>
                        </ol>
                <li>.&lt;img/&gt;标签的()属性用来设置图片与旁边内容的水平距离。</li>
                        <ol type="A">
                                <li>hspace</li>
                                <li>vspace</li>
                                <li>border</li>
                                <li>alt</li>
                        </ol>
                <li>.下面HTML结构中,不属于列表结构的是()。</li>
                        <ol type="A">
                                <li>ul-li</li>
                                <li>ol-li</li>
                                <li>dl-dt-dd</li>
                                <li>p-br</li>
                        </ol>
                </ol>
</html>     //可以看到访问的是同一个IP地址却是不同的网页。证明已经成功

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61
  • 62
  • 63
  • 64
  • 65
  • 66
  • 67
  • 68
  • 69
  • 70
  • 71
  • 72
  • 73
  • 74
  • 75
  • 76
  • 77
  • 78
  • 79
  • 80
  • 81
  • 82
  • 83
  • 84
  • 85
  • 86
  • 87
  • 88
  • 89
  • 90
  • 91
  • 92
  • 93
  • 94
  • 95
  • 96
  • 97
  • 98
  • 99
  • 100
  • 101
  • 102
  • 103
  • 104
  • 105
  • 106
  • 107
  • 108
  • 109
  • 110
  • 111
  • 112
  • 113
  • 114
  • 115
  • 116
  • 117
  • 118
  • 119
  • 120
  • 121
  • 122
  • 123
  • 124
  • 125
  • 126
  • 127
  • 128
  • 129
  • 130
  • 131
  • 132
  • 133
  • 134
  • 135
  • 136
  • 137
  • 138
  • 139
  • 140
  • 141
  • 142
  • 143
  • 144
  • 145
  • 146
  • 147
  • 148
  • 149
  • 150
  • 151
  • 152
  • 153
  • 154
  • 155
  • 156
  • 157
  • 158
  • 159
  • 160
  • 161
  • 162
  • 163
  • 164
  • 165
  • 166
  • 167
  • 168
  • 169
  • 170
  • 171
  • 172
  • 173
  • 174
  • 175
  • 176
  • 177
  • 178
  • 179
  • 180
  • 181
  • 182
  • 183
  • 184
  • 185
  • 186
  • 187
  • 188
  • 189
  • 190
  • 191
  • 192
  • 193
  • 194
  • 195
  • 196
  • 197
  • 198
  • 199
  • 200
  • 201
  • 202
  • 203
  • 204
  • 205
  • 206
  • 207
  • 208
  • 209
  • 210
  • 211
  • 212
  • 213
  • 214
  • 215
  • 216
  • 217
  • 218
  • 219
  • 220
  • 221
  • 222
  • 223
  • 224
  • 225
  • 226
  • 227
  • 228
  • 229
  • 230
  • 231
  • 232
  • 233
  • 234
  • 235
  • 236
  • 237
  • 238
  • 239
  • 240
  • 241
  • 242
  • 243
  • 244
  • 245
  • 246
  • 247
  • 248
  • 249
  • 250
  • 251
  • 252
  • 253
  • 254
  • 255
  • 256
  • 257
  • 258
  • 259
  • 260
  • 261
  • 262
  • 263
  • 264
  • 265
  • 266
  • 267
  • 268
  • 269
  • 270
  • 271
  • 272
  • 273
  • 274

3.配置dr模式

Ivs-dr配置: director只需要 一块网卡,vip配 置在Io接口中即可,此处假设dip与rip在同-网段
配置director的ip地址信息(dip, vip)
配置dip (编辑物理网卡配置文件/etc/sysconfig/network-scripts/ifcfg-eth0)
配置vip: .
ifconfig eth0:0 vip/32 broadcast vip up
配置RS的ip地址信息: .
配置rip (编辑物理网卡配置文件/etc/sysconfig/network-scripts/ifcfg-eth0)
修改网卡内核参数:编辑/etc/sysctl.conf文件, 添加如下内容:
net.ipv4.conf. alarp ignore = 1
net.ipv4.conf. alarp _announce = 2
配置vip:
ifconfig lo:0 vip/32 broadcast vip up
注意:此处必须先修改网卡内核参数然后再配置vip,因为如果先配vip,vip配好 后就会立马通告给别人,而修改馁核参数就是为了不通告
配置路由信息:在director和所有RS 上进行如下配置:
route add -host vip dev interface:0

先把lvs虚拟机恢复恢复快照

//修改名字
[root@localhost ~]# hostnamectl set-hostname lvs
[root@localhost ~]# bash
[root@lvs ~]# 
//关闭防火墙和selinux
[root@lvs ~]# systemctl disable --now firewalld
[root@lvs ~]# setenforce 0
setenforce: SELinux is disabled
[root@lvs ~]# cat /etc/selinux/config 

# This file controls the state of SELinux on the system.
# SELINUX= can take one of these three values:
#     enforcing - SELinux security policy is enforced.
#     permissive - SELinux prints warnings instead of enforcing.
#     disabled - No SELinux policy is loaded.
SELINUX=disabled      //改为disabled
# SELINUXTYPE= can take one of these three values:
#     targeted - Targeted processes are protected,
#     minimum - Modification of targeted policy. Only selected processes are protected. 
#     mls - Multi Level Security protection.
SELINUXTYPE=targeted
//开启httpd并RS1和RS2的网站不同
//RS2
[root@RS2 ~]# systemctl enable --now httpd
Created symlink /etc/systemd/system/multi-user.target.wants/httpd.service → /usr/lib/systemd/system/httpd.service.
[root@RS2 ~]# ss -antl
State      Recv-Q     Send-Q         Local Address:Port         Peer Address:Port    
LISTEN     0          128                  0.0.0.0:111               0.0.0.0:*       
LISTEN     0          32             192.168.122.1:53                0.0.0.0:*       
LISTEN     0          128                  0.0.0.0:22                0.0.0.0:*       
LISTEN     0          5                  127.0.0.1:631               0.0.0.0:*       
LISTEN     0          128                     [::]:111                  [::]:*       
LISTEN     0          128                        *:80                      *:*       
LISTEN     0          128                     [::]:22                   [::]:*       
LISTEN     0          5                      [::1]:631                  [::]:*       
[root@RS2 ~]# echo "hello RS2" > /var/www/html/index.html
//RS1
[root@RS1 ~]# systemctl enable --now httpd
Created symlink /etc/systemd/system/multi-user.target.wants/httpd.service → /usr/lib/systemd/system/httpd.service.
[root@RS1 ~]# ss -antl
State      Recv-Q     Send-Q         Local Address:Port         Peer Address:Port    
LISTEN     0          128                  0.0.0.0:111               0.0.0.0:*       
LISTEN     0          32             192.168.122.1:53                0.0.0.0:*       
LISTEN     0          128                  0.0.0.0:22                0.0.0.0:*       
LISTEN     0          5                  127.0.0.1:631               0.0.0.0:*       
LISTEN     0          128                     [::]:111                  [::]:*       
LISTEN     0          128                        *:80                      *:*       
LISTEN     0          128                     [::]:22                   [::]:*       
LISTEN     0          5                      [::1]:631                  [::]:*       
[root@RS1 ~]# echo "hello RS1" > /var/www/html/index.html
[root@lvs ~]# dnf -y install net-tools    //安装这个包
//配置dip
[root@lvs network-scripts]# cat ifcfg-ens160 
TYPE=Ethernet
BOOTPROTO=static
NAME=ens160
DEVICE=ens160
ONBOOT=yes
PREFIX=24
GATEWAY=192.168.106.2
IPADDR=192.168.106.20
DNS1=8.8.8.8
//让网卡生效
[root@lvs network-scripts]# ifdown ens160;ifup ens160
Connection 'ens160' successfully deactivated (D-Bus active path: /org/freedesktop/NetworkManager/ActiveConnection/1)
Connection successfully activated (D-Bus active path: /org/freedesktop/NetworkManager/ActiveConnection/2)
//配置vip
[root@lvs ~]# ifconfig ens160:0 192.168.106.250/32 broadcast 192.168.106.250 up

//配置RS的ip地址信息
[root@RS1 ~]# cat /etc/sysconfig/network-scripts/ifcfg-ens160 
TYPE=Ethernet
BOOTPROTO=static
NAME=ens160
DEVICE=ens160
ONBOOT=yes
IPADDR=192.168.106.16
PREFIX=24
GATEWAY=192.168.106.2
DNS1=8.8.8.8
//重置网卡
[root@RS1 ~]# ifdown ens160;ifup ens160
成功停用连接 "ens160"D-Bus 活动路径:/org/freedesktop/NetworkManager/ActiveConnection/5)
连接已成功激活(D-Bus 活动路径:/org/freedesktop/NetworkManager/ActiveConnection/6//修改RS2网卡
[root@RS2 ~]# cat /etc/sysconfig/network-scripts/ifcfg-ens160
TYPE=Ethernet
BOOTPROTO=static
NAME=ens160
DEVICE=ens160
ONBOOT=yes
IPADDR=192.168.106.17
PREFIX=24
GATEWAY=192.168.106.2
DNS1=8.8.8.8
//重置RS2网卡
[root@RS2 ~]# ifdown ens160;ifup ens160
成功停用连接 "ens160"D-Bus 活动路径:/org/freedesktop/NetworkManager/ActiveConnection/4)
连接已成功激活(D-Bus 活动路径:/org/freedesktop/NetworkManager/ActiveConnection/5//修改网卡内核参数:编辑/etc/sysctl.conf文件, 添加如下内容:
//配置RS2
[root@RS2 ~]# cat /etc/sysctl.conf 
# sysctl settings are defined through files in
# /usr/lib/sysctl.d/, /run/sysctl.d/, and /etc/sysctl.d/.
#
# Vendors settings live in /usr/lib/sysctl.d/.
# To override a whole file, create a new file with the same in
# /etc/sysctl.d/ and put new settings there. To override
# only specific settings, add a file with a lexically later
# name in /etc/sysctl.d/ and put new settings there.
#
# For more information, see sysctl.conf(5) and sysctl.d(5).
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
//配置RS1
[root@RS1 ~]# cat /etc/sysctl.conf 
# sysctl settings are defined through files in
# /usr/lib/sysctl.d/, /run/sysctl.d/, and /etc/sysctl.d/.
#
# Vendors settings live in /usr/lib/sysctl.d/.
# To override a whole file, create a new file with the same in
# /etc/sysctl.d/ and put new settings there. To override
# only specific settings, add a file with a lexically later
# name in /etc/sysctl.d/ and put new settings there.
#
# For more information, see sysctl.conf(5) and sysctl.d(5).
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
//配置vip
//RS1
[root@RS1 network-scripts]# ifconfig lo:0 192.168.106.250/32 broadcast 192.168.106.250 up
[root@RS1 network-scripts]# ifconfig     //能看到下面内容就说明成功
lo:0: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536
        inet 192.168.106.250  netmask 0.0.0.0
        loop  txqueuelen 1000  (Local Loopback)
//RS2
[root@RS2 ~]# ifconfig lo:0 192.168.106.250/32 broadcast 192.168.106.250 up
[root@RS2 ~]# ifconfig
lo:0: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536
        inet 192.168.106.250  netmask 0.0.0.0
        loop  txqueuelen 1000  (Local Loopback)
//配置路由信息:在director和所有RS上进行如下配置:
[root@lvs ~]# route add -host 192.168.106.250 dev ens160:0
[root@RS1 ~]# route add -host 192.168.106.250 dev lo:0
[root@RS2 ~]# route add -host 192.168.106.250 dev lo:0
//在director上添加并保存规则
[root@lvs ~]# dnf -y install ipvsadm    //下载这个包
[root@lvs ~]# ipvsadm -A -t 192.168.106.250:80 -s wrr
[root@lvs ~]# ipvsadm -a -t 192.168.106.250:80 -r 192.168.106.16 -g
[root@lvs ~]# ipvsadm -a -t 192.168.106.250:80 -r 192.168.106.17 -g
[root@lvs ~]# 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.106.250:80 wrr
  -> 192.168.106.16:80            Route   1      0          0         
  -> 192.168.106.17:80            Route   1      0          0         
[root@lvs ~]# ipvsadm -S > /etc/sysconfig/ipvsadm
[root@lvs ~]# cat /etc/sysconfig/ipvsadm
-A -t lvs:http -s wrr
-a -t lvs:http -r 192.168.106.16:http -g -w 1
-a -t lvs:http -r 192.168.106.17:http -g -w 1
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61
  • 62
  • 63
  • 64
  • 65
  • 66
  • 67
  • 68
  • 69
  • 70
  • 71
  • 72
  • 73
  • 74
  • 75
  • 76
  • 77
  • 78
  • 79
  • 80
  • 81
  • 82
  • 83
  • 84
  • 85
  • 86
  • 87
  • 88
  • 89
  • 90
  • 91
  • 92
  • 93
  • 94
  • 95
  • 96
  • 97
  • 98
  • 99
  • 100
  • 101
  • 102
  • 103
  • 104
  • 105
  • 106
  • 107
  • 108
  • 109
  • 110
  • 111
  • 112
  • 113
  • 114
  • 115
  • 116
  • 117
  • 118
  • 119
  • 120
  • 121
  • 122
  • 123
  • 124
  • 125
  • 126
  • 127
  • 128
  • 129
  • 130
  • 131
  • 132
  • 133
  • 134
  • 135
  • 136
  • 137
  • 138
  • 139
  • 140
  • 141
  • 142
  • 143
  • 144
  • 145
  • 146
  • 147
  • 148
  • 149
  • 150
  • 151
  • 152
  • 153
  • 154
  • 155
  • 156
  • 157
  • 158
  • 159
  • 160
  • 161
  • 162
  • 163
  • 164
  • 165
  • 166
  • 167
  • 168

4. 测试

在网站上填写你设置的vip
在这里插入图片描述
第一次访问到RS1

在这里插入图片描述
刷新一下就会访问到RS2,

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/在线问答5/article/detail/820554
推荐阅读
相关标签
  

闽ICP备14008679号