当前位置: 首页 > news >正文

基于 CentOS 7 构建 LVS-DR 群集。

1.准备实验环境

本次实验我准备了4台虚拟机

DS:DIP--192.168.163.138

        VIP--192.168.163.200

RIP1(web1)--192.168.163.140

RIP2(web2)--192.168.163.141

Client:user--192.168.163.142

2.配置服务器环境

1)搭建简易的web服务

RIP1

[root@localhost ~]# yum install httpd
[root@localhost ~]# echo "web1 test, ip is `hostname -I` ." > /var/www/html/index.html
[root@localhost ~]# systemctl start httpd

RIP2

[root@localhost ~]# yum install httpd
[root@localhost ~]# echo "web2 test, ip is `hostname -I` ." > /var/www/html/index.html
[root@localhost ~]# systemctl start httpd

使用Client验证

[root@localhost ~]# curl 192.168.163.140
web2 test ip is 192.168.163.140 .
[root@localhost ~]# curl 192.168.163.141
web1 test, ip is 192.168.163.141  .

2)配置VIP虚拟ip地址

[root@localhost ~]# nmcli connection show
NAME   UUID                                  TYPE      DEVICE 
ens33  5e4131fb-0601-422a-916f-9a0e8b16deb7  ethernet  ens33 
[root@localhost ~]# ifconfig ens33:200 192.168.163.200/24 
[root@localhost ~]# ifconfig
ens33: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500inet 192.168.163.138  netmask 255.255.255.0  broadcast 192.168.163.255inet6 fe80::83c2:22a3:b848:9285  prefixlen 64  scopeid 0x20<link>inet6 fe80::3d2:78bf:c3a6:7bd7  prefixlen 64  scopeid 0x20<link>inet6 fe80::5f89:8967:3a3a:a5f4  prefixlen 64  scopeid 0x20<link>ether 00:0c:29:3b:1d:03  txqueuelen 1000  (Ethernet)RX packets 24394  bytes 25080376 (23.9 MiB)RX errors 0  dropped 0  overruns 0  frame 0TX packets 8102  bytes 717188 (700.3 KiB)TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0ens33:200: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500inet 192.168.163.200  netmask 255.255.255.0  broadcast 192.168.163.255ether 00:0c:29:3b:1d:03  txqueuelen 1000  (Ethernet)lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536inet 127.0.0.1  netmask 255.0.0.0inet6 ::1  prefixlen 128  scopeid 0x10<host>loop  txqueuelen 1000  (Local Loopback)RX packets 77  bytes 9856 (9.6 KiB)RX errors 0  dropped 0  overruns 0  frame 0TX packets 77  bytes 9856 (9.6 KiB)TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0
[root@localhost ~]# nmcli connection up ens33
连接已成功激活(D-Bus 活动路径:/org/freedesktop/NetworkManager/ActiveConnection/8)

3)手动绑定VIP和手写访问VIP的路由

RIP1:

[root@localhost ~]# ifconfig lo:200 192.168.163.200 netmask 255.255.255.255 up
[root@localhost ~]# ifconfig
ens33: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500inet 192.168.163.141  netmask 255.255.255.0  broadcast 192.168.163.255inet6 fe80::83c2:22a3:b848:9285  prefixlen 64  scopeid 0x20<link>inet6 fe80::3d2:78bf:c3a6:7bd7  prefixlen 64  scopeid 0x20<link>inet6 fe80::5f89:8967:3a3a:a5f4  prefixlen 64  scopeid 0x20<link>ether 00:0c:29:d4:2c:1e  txqueuelen 1000  (Ethernet)RX packets 4113  bytes 317195 (309.7 KiB)RX errors 0  dropped 0  overruns 0  frame 0TX packets 1935  bytes 218535 (213.4 KiB)TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536inet 127.0.0.1  netmask 255.0.0.0inet6 ::1  prefixlen 128  scopeid 0x10<host>loop  txqueuelen 1000  (Local Loopback)RX packets 6  bytes 468 (468.0 B)RX errors 0  dropped 0  overruns 0  frame 0TX packets 6  bytes 468 (468.0 B)TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0lo:200: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536inet 192.168.163.200  netmask 255.255.255.
[root@localhost ~]# route add -host 192.168.163.200 dev lo
[root@localhost ~]# route -n
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
0.0.0.0         192.168.163.2   0.0.0.0         UG    100    0        0 ens33
192.168.163.0   0.0.0.0         255.255.255.0   U     100    0        0 ens33
192.168.163.200 0.0.0.0         255.255.255.255 UH    0      0        0 lo

RIP2同上

4)在DS上配置LVS

下载ipvsadm

[root@localhost ~]# yum install ipvsadm -y

添加ipvsadm服务

[root@localhost ~]# ipvsadm -A -t 192.168.163.200:80 -s rr
[root@localhost ~]# ipvsadm -a -t 192.168.163.200:80 -r 192.168.163.141 -g -w 1
[root@localhost ~]# ipvsadm -a -t 192.168.163.200:80 -r 192.168.163.140 -g -w 1
[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.163.200:80 rr-> 192.168.163.140:80           Route   1      0          0         -> 192.168.163.141:80           Route   1      0          0         

5)在RS上配置ARP抑制

[root@localhost ~]# echo "1" > /proc/sys/net/ipv4/conf/lo/arp_ignore
[root@localhost ~]# echo "2" > /proc/sys/net/ipv4/conf/lo/arp_announce
[root@localhost ~]# echo "1" > /proc/sys/net/ipv4/conf/all/arp_ignore
[root@localhost ~]# echo "2" > /proc/sys/net/ipv4/conf/all/arp_announce

RIP1和RIP2皆如此

6)结果测试

在Client上进行测试

[root@localhost ~]# for ((i=1;i<=10;i++)); do curl 192.168.163.200;done
web1 test, ip is 192.168.163.141  .
web2 test ip is 192.168.163.140 .
web1 test, ip is 192.168.163.141  .
web2 test ip is 192.168.163.140 .
web1 test, ip is 192.168.163.141  .
web2 test ip is 192.168.163.140 .
web1 test, ip is 192.168.163.141  .
web2 test ip is 192.168.163.140 .
web1 test, ip is 192.168.163.141  .
web2 test ip is 192.168.163.140 .

成功访问到服务

http://www.lryc.cn/news/120590.html

相关文章:

  • 防火墙组建双击热备后,点击管理对端设备,老是打不开,怎么办?
  • 【Kubernetes】Kubernetes之Pod详解
  • 电商与客服系统完美对接指南源码-无缝对接唯一客服系统-提升电商客户体验...
  • 新知识:Monkey 改进版之 App Crawler
  • 黑马头条项目学习--Day3: 自媒体文章发布
  • 使用frp实现内网穿透
  • 安装 opendr 踩坑记
  • 各地区-各行业法人单位、区划数63个指标(2010-2022年)
  • W5500-EVB-PICO作为TCP Client 进行数据回环测试(五)
  • web前端面试--递归(斐波那契数列)
  • Vue3 Props组件简单应用(父组件获取子组件数据)
  • Mybatis查询
  • 如何让ES低成本、高性能?滴滴落地ZSTD压缩算法的实践分享
  • [数据集][目标检测]PCB板缺陷目标检测数据集VOC格式693张6类别
  • Linux 安装中文输入法
  • redisson
  • 源码分析——HashMap(JDK1.8)源码+底层数据结构分析
  • 企业举办活动邀请媒体的意义和重要性
  • 从零开始学python(十六)爬虫集群部署
  • flutter
  • iOS 开发-编译第三方库 openssl及curl
  • 运维监控学习笔记1
  • 由于找不到vcruntime140.dll,无法继续执行代码,三种修复方法
  • 【FPGA零基础学习之旅#10】按键消抖模块设计与验证(一段式状态机实现)
  • 【EI复现】基于阶梯碳交易的含P2G-CCS耦合和燃气掺氢的虚拟电厂优化调度(Matlab代码实现)
  • 高防cdn和高防服务器有什么不一样?
  • ppt怎么压缩?试试这样压缩文件
  • stm32 cubemx ps2无线(有线)手柄
  • 【TI毫米波雷达笔记】sdk传参时的type避坑
  • 【算法挨揍日记】day02——双指针算法_快乐数、盛最多水的容器