负载均衡群集——LVS+DR模型

标签: nginx  lvs  负载均衡  运维

一、实验组成

调度器 192.168.100:41
web1 192.168.100:42
web2 192.168.100.43
NFS共享服务器 192.168.100.44

二、实验拓扑

在这里插入图片描述

三、实验配置

3.1在调度器配置:192.168.100.41

  • 配置虚拟IP地址(VIP)
[[email protected] ~]# cd /etc/sysconfig/network-scripts/
[[email protected] network-scripts]# cp ifcfg-ens33 ifcfg-ens33:0
[[email protected] network-scripts]# vi ifcfg-ens33:0
NAME=ens33:0
DEVICE=ens33:0
ONBOOT=yes
IPADDR=192.168.100.10
NETMASK=255.255.255.255

[[email protected] network-scripts]# ifup ifcfg-ens33:0
[[email protected] network-scripts]# ifconfig
ens33: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.100.41  netmask 255.255.255.0  broadcast 192.168.100.255
        inet6 fe80::2fe2:b428:9454:6c2b  prefixlen 64  scopeid 0x20<link>
        ether 00:0c:29:9b:a7:cc  txqueuelen 1000  (Ethernet)
        RX packets 630  bytes 76327 (74.5 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 368  bytes 50671 (49.4 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

ens33:0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.100.10  netmask 255.255.255.0  broadcast 192.168.100.255
        ether 00:0c:29:9b:a7:cc  txqueuelen 1000  (Ethernet)

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 992  bytes 85912 (83.8 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 992  bytes 85912 (83.8 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:ca:42:28  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
  • 调整/proc响应参数 对于 DR 群集模式来说,由于 LVS 负载调度器和各节点需要共用 VIP 地址,应该关闭 Linux 内核的重定向参数响应,服务器不是一台路由器,那么它不会发送重定向,所以可以关闭该功能
[[email protected] network-scripts]# vi /etc/sysctl.conf 
net.ipv4.conf.all.send_redirects = 0
net.ipv4.conf.default.send_redirects = 0
net.ipv4.conf.ens33.send_redirects = 0

[[email protected] network-scripts]# sysctl -p     ###生效
net.ipv4.conf.all.send_redirects = 0
net.ipv4.conf.default.send_redirects = 0
net.ipv4.conf.ens33.send_redirects = 0
  • 配置负载分配策略
[[email protected] /]# ipvsadm -v
[[email protected] ~]# modprobe ip_vs
[[email protected] ~]# cat /proc/net/ip_vs
[[email protected] ~]#yum -y install ipvsadm
[[email protected] ~]#ipvsadm -A -t 192.168.100.10:80 -s rr
[[email protected] ~]#ipvsadm -a -t 192.168.100.10:80 -r 192.168.100.42:80 -g -w 1
[[email protected] ~]#ipvsadm -a -t 192.168.100.10:80 -r 192.168.100.43:80 -g -w 1

[[email protected] network-scripts]# ipvsadm-save
[[email protected] network-scripts]# systemctl enable ipvsadm

3.2配置存储服务器:192.168.100.44

rpm -q nfs-utils    ###如果没装,yum -y install nfs-utils
rpm -q rpcbind      ###如果没装,yum -y install rpcbind
[[email protected] ~]# systemctl start nfs
[[email protected] ~]# systemctl start rpcbind

[[email protected] ~]# vi /etc/exports
/opt/51xit 192.168.100.0/24 (rw,sync)
/opt/52xit 192.168.100.0/24 (rw,sync)

[[email protected] ~]# systemctl restart nfs
[[email protected] ~]# systemctl restart rpcbind
[[email protected] ~]# systemctl enable nfs
[[email protected] ~]# systemctl enable rpcbind
[[email protected] ~]# mkdir /opt/51xit /opt/52xit
[[email protected] ~]# echo "this is 51xit" >/opt/51xit/index.html
[[email protected] ~]# echo "this is 52xit" >/opt/52xit/index.html

3.3节点服务器1:192.168.100.42

  • 配置虚拟IP地址
[[email protected] ~]# cd /etc/sysconfig/network-scripts/
[[email protected] network-scripts]# cp ifcfg-lo ifcfg-lo:0
[[email protected] network-scripts]# vi ifcfg-lo:0
DEVICE=lo:0
IPADDR=192.168.100.10
NETMASK=255.255.255.255
ONBOOT=yes

[[email protected] network-scripts]# ifup lo:0
[[email protected] network-scripts]# ifconfig
ens33: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.100.42  netmask 255.255.255.0  broadcast 192.168.100.255
        inet6 fe80::8edf:281f:bd34:b245  prefixlen 64  scopeid 0x20<link>
        ether 00:50:56:22:ca:a7  txqueuelen 1000  (Ethernet)
        RX packets 787  bytes 91078 (88.9 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 366  bytes 54581 (53.3 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

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 884  bytes 76416 (74.6 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 884  bytes 76416 (74.6 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

lo:0: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536
        inet 192.168.100.10  netmask 255.255.255.255
        loop  txqueuelen 1000  (Local Loopback)

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:ca:42:28  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

[[email protected] network-scripts]# vi /etc/rc.local 
/sbin/route add -host 192.168.100.10 dev lo:0

[[email protected] network-scripts]# route add -host 192.168.100.10 dev lo:0
  • 调整/proc响应参数
[[email protected] network-scripts]# vi /etc/sysctl.conf 
net.ipv4.conf.all.arp_ignore = 1
net.ipv4.conf.all.arp_announce = 2
net.ipv4.conf.default.arp_ignore = 1
net.ipv4.conf.default.arp_announce = 2
net.ipv4.conf.lo.arp_ignore = 1
net.ipv4.conf.lo.arp_announce = 2

[[email protected] network-scripts]# sysctl -p
  • 安装httpd 挂载测试页
[[email protected] ~]# showmount -e 192.168.100.44     ####如果还没发布,请到存储服务器发布下,exportfs -rv
Export list for 192.168.100.44:
/opt/51xit  (everyone)
/opt/52xit (everyone)

[[email protected] ~]# yum -y install httpd
[[email protected] ~]# mount 192.168.100.44:/opt/51xit /var/www/html/
[[email protected] ~]# vi /etc/fstab 
192.168.100.44:/opt/51xit/ /var/www/html/        nfs     rw,tcp,intr     0 1        ###开机自动挂载,注意格式对齐

[[email protected] ~]# systemctl start httpd
[[email protected] ~]# systemctl enable httpd

登录192.168.100.42测试网站是否正常
在这里插入图片描述

3.4配置节点服务器2:192.168.100.43

  • 配置虚拟IP地址
[[email protected] ~]# cd /etc/sysconfig/network-scripts/
[[email protected] network-scripts]# cp ifcfg-lo ifcfg-lo:0
[[email protected] network-scripts]# vi ifcfg-lo:0
DEVICE=lo:0
IPADDR=192.168.100.10
NETMASK=255.255.255.255
ONBOOT=yes

[[email protected] network-scripts]# ifup lo:0
[[email protected] network-scripts]# ifconfig
ens33: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.100.43  netmask 255.255.255.0  broadcast 192.168.100.255
        inet6 fe80::8edf:281f:bd34:b245  prefixlen 64  scopeid 0x20<link>
        ether 00:50:56:22:ca:a7  txqueuelen 1000  (Ethernet)
        RX packets 787  bytes 91078 (88.9 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 366  bytes 54581 (53.3 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

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 884  bytes 76416 (74.6 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 884  bytes 76416 (74.6 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

lo:0: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536
        inet 192.168.100.10  netmask 255.255.255.255
        loop  txqueuelen 1000  (Local Loopback)

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:ca:42:28  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

[[email protected] network-scripts]# vi /etc/rc.local 
/sbin/route add -host 192.168.100.10 dev lo:0

[[email protected] network-scripts]# route add -host 192.168.100.100 dev lo:0
  • 调整/proc响应参数
[[email protected] network-scripts]# vi /etc/sysctl.conf 
net.ipv4.conf.all.arp_ignore = 1
net.ipv4.conf.all.arp_announce = 2
net.ipv4.conf.default.arp_ignore = 1
net.ipv4.conf.default.arp_announce = 2
net.ipv4.conf.lo.arp_ignore = 1
net.ipv4.conf.lo.arp_announce = 2

[[email protected] network-scripts]# sysctl -p
  • 安装httpd 挂载测试页
[[email protected] ~]# showmount -e 192.168.100.44     ####如果还没发布,请到存储服务器发布下,exportfs -rv
Export list for 192.168.100.44:
/opt/accp  (everyone)
/opt/bdqn (everyone)

[[email protected] ~]# yum -y install httpd
[[email protected] ~]# mount 192.168.100.44:/opt/52xit /var/www/html/
[[email protected] ~]# vi /etc/fstab 
192.168.100.44:/opt/52xit/ /var/www/html/        nfs     rw,tcp,intr     0 1        ###开机自动挂载,注意格式对齐

[[email protected] ~]# systemctl start httpd
[[email protected] ~]# systemctl enable httpd

登录192.168.100.43测试网站是否正常
在这里插入图片描述

3.5测试网站

192.168.100.10

在这里插入图片描述

在这里插入图片描述

版权声明:本文为m0_47452405原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://blog.csdn.net/m0_47452405/article/details/109486080

智能推荐

1264页面推荐(中等 union all )稍微的难点在于找1的朋友

![在这里插入图片描述](https://img-blog.csdnimg.cn/20200904233840843.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3FxXzQ1NTMxNTk0,size_16,color_FFFFFF,t...

单链表+单链表代码(链表最基础)

链表 链表是有顺序的表,在内存中存储: 链表是以节点的方式存储的 每个节点包括data域,next域:指向下一个节点 如图:发现链表的各个节点不一定是连续存放的,有跳跃的,不是连续存储 链表分为带头节点的链表和没有头结点的链表 添加: 1.先创建一个head头结点,作用就是单链表的头 2.后面每添加一个节点,就直接加入到链表最后 遍历: 代码 添加节点到链表里: 这里借助于temp节点,通过循环找...

Rtthread学习笔记(十三)RT-Thread Studio开启硬件看门狗Watchdog

一、开启硬件看门狗Watchdog 1、配置RT-Thread Settings 2、开启stm32f1xx_hal_conf.h中的宏定义 3.使用RT接口函数初始化硬件看门狗...

TYVJ 4864 天天去哪吃 || 清北学堂金秋杯大奖赛

题目描述: 记录一下i这个值上次出现的位置在哪里,就是pre...

java反编译

jvm 把Boolean类型的值flag当做int类型处理。​​​ Foo.java: 由 class 文件生成 jasm 文件:java -jar asmtools.jar jdis Foo.class > Foo.jasm  修改jasm文件: 执行反编译: java -jar jd-gui-1.6.6.jar File 打开Foo.class文件:b修改为2 重新执行java...

猜你喜欢

【学习笔记】03-v-html的学习和示例

v-html的认识和使用 示例: 显示结果: 注意:v-html是有复制的...

Java实现在线考试系统(系统介绍)

1.和现在有的考试系统有以下几种优势: a.和现在有的系统比较起来,本系统有科目、章节、老师、学生、班级等信息的管理,还有批阅试卷查看已批阅试卷等。传统的考试系统划分并不细,业务功能简单。 b.和学校的考试系统还有外面的考试系统比较起来,本系统是B/S结构,学校的考试系统一般为C/S结构,性能方面不如B/S结构,并且C/S接口需要安装客户端,客户端压力很大,我的系统只需要电脑具有浏览器,在同一局域...

计算机视觉--多视几何初步尝试

基础矩阵的原理 K和K’分别是两个相机的参数矩阵。p和p’是X在平面π的坐标表示。所以可以得出 具体计算过程 代码: #!/usr/bin/env python coding: utf-8 from PIL import Image from numpy import * from pylab import * import numpy as np from imp ...

java初学者怎么学习才可以快速入门

java初学者怎么学习才可以快速入门 一、了解JAVA 我们要知道:Java是由Sun Microsystems公司于1995年5月推出的Java面向对象程序设计语言。 Java之父:詹姆斯·高斯林 1.1 java的三个体系 Java SE(Java Platform Standard Edition)。Java SE 以前称为 J2SE。它允许开发和部署在桌面、服务器、嵌入式环境...

字段属性之主键&增删改查&自增长&唯一键约束

字段属性之主键&自增长&唯一键约束 主键 主键:primary key 主要的键 一张表中只有一个字段可以使用对应的键,用来唯一的约束该字段里面的数据,不能重复,这种称之为主键 一张表只能最多一个主键 增加主键 SQL操作中有多种方式增加主键大体分为三种 1.在创建表的时候直接在字段之后跟primary key关键字(主键本身不允许为空) 优点:非常直接:缺点:只能使用一个字段作为...