Cluster d'équilibrage de charge LVS ---------- Mode DR (routage direct)

Équilibrage de charge-mode DR

  • Cette fois, j'introduis principalement le mode DR dans l'équilibrage de
    charge.Le routage direct (Direct Routing) est appelé mode DR; il adopte une structure de réseau semi-ouverte, qui est similaire à la structure du mode TUN, mais les nœuds ne sont pas dispersés partout, mais sont situés dans le planificateur. Le même réseau physique, le planificateur de charge et chaque serveur de nœud sont connectés via le réseau local, sans qu'il soit nécessaire d'établir un tunnel IP dédié.

Insérez la description de l'image ici

Déploiement de l'environnement réseau

  • Cette fois, nous utiliserons le diagramme de topologie eNsp + 5 machines virtuelles pour construire la démonstration
    Insérez la description de l'image ici

  • Nœud serveur cluster
    1, un programmateur LVS (mode de connexion vm1)
    change ip: 192.168.100.21/24 passerelle: 192.168.100.1 redémarrer la carte réseau;

    2.
    Modifiez l'ip des deux serveurs de nœuds (mode de connexion vm1) : passerelle 192.168.100.22/24: 192.168.100.1 et redémarrez la carte réseau,
    modifiez l'ip: 192.168.100.23/24 passerelle: 192.168.100.1 et redémarrez la carte réseau;

    3. Un stockage partagé NFS (mode de connexion vm1)
    changez l'IP: 192.168.100.24/24 passerelle: 192.168.100.1 et redémarrez la carte réseau;

  • Client
    1. Une machine virtuelle (client) d'un système Windows (mode de connexion vm2) pour
    changer l'URL de l'adaptateur réseau ip: 192.168.200.100/24 ​​Passerelle: 192.168.200.1

  • Machine réelle
    1. Changez la carte réseau vm1 (utilisée pour se connecter au CRT) sur la machine réelle ,
    changez l'IP: 192.168.100.2/24 Passerelle: 192.168.100.1

  • Désactivez le pare-feu, la protection principale de toutes les machines virtuelles et installez les sources yum locales

Commencez à configurer LVS - mode DR

Configurer le planificateur LVS (192.168.100.21)

[1] Configurer l'adresse IP virtuelle (VIP)

[root@localhost ~]# cd /etc/sysconfig/network-scripts/
[root@localhost network-scripts]# ll
[root@localhost network-scripts]# cp ifcfg-ens33 ifcfg-ens33:0
[root@localhost network-scripts]# vi ifcfg-ens33:0
 
NAME=ens33:0
DEVICE=ens33:0
ONBOOT=yes
IPADDR=192.168.100.100
NETMASK=255.255.255.255

[root@localhost network-scripts]# ifup ens33:0
[root@localhost network-scripts]# ip addr                ####查看 lo:0 接口上设的IP是否出现(我这是最小化安装的)

[2] Ajuster les paramètres de réponse / proc Pour le mode de cluster DR, étant donné que le planificateur de charge LVS et chaque nœud doivent partager l'adresse VIP, le paramètre de redirection du noyau Linux doit être désactivé. Le serveur de réponse n'est pas un routeur, il n'enverra donc pas de redirection , Vous pouvez donc désactiver cette fonctionnalité (optimisation de la réponse)

[root@localhost ~]# 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

[root@localhost ~]# sysctl -p                   ####查看是否生效
net.ipv4.conf.all.send_redirects = 0
net.ipv4.conf.default.send_redirects = 0
net.ipv4.conf.ens33.send_redirects = 0

[3] Configurer la stratégie de répartition de la charge

[root@localhost /]# ipvsadm -v
[root@localhost ~]# modprobe ip_vs
[root@localhost ~]# cat /proc/net/ip_vs
[root@localhost ~]# yum -y install ipvsadm
[root@localhost ~]# ipvsadm -A -t 192.168.100.100:80 -s rr                #### 可以 ipvsadm -ln 查看下
[root@localhost ~]# ipvsadm -a -t 192.168.100.100:80 -r 192.168.100.22:80 -g -w 1
[root@localhost ~]# ipvsadm -a -t 192.168.100.100:80 -r 192.168.100.23:80 -g -w 1
[root@localhost ~]# ipvsadm-save > /opt/ipvsadm  

[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.100.100:80 rr
  -> 192.168.100.22:80            Route   1      0          0         
  -> 192.168.100.23:80            Route   1      0          0 

Configurer le stockage partagé NFS (192.168.100.24)

rpm -q nfs-utils    ###如果没装,yum -y install nfs-utils
rpm -q rpcbind      ###如果没装,yum -y install rpcbind

[root@localhost ~]# mkdir /opt/51xue /opt/52xue
[root@localhost ~]# echo 'i am superman 51xue' > /opt/51xue/index.html
[root@localhost ~]# echo 'you are pig 52xue' > /opt/52xue/index.html
[root@localhost ~]# vi /etc/exports                          #####添加下面二行(共享出去)
/opt/51xit 192.168.100.0/24 (rw,sync)           
/opt/52xit 192.168.100.0/24 (rw,sync)

[root@localhost ~]# systemctl start rpcbind
[root@localhost ~]# systemctl enable rpcbind
[root@localhost ~]# systemctl start nfs
[root@localhost ~]# systemctl enable nfs
[root@localhost ~]# showmount -e
Export list for localhost.localdomain:
/opt/52xue 192.168.100.0/24
/opt/51xue 192.168.100.0/24

Configurer le serveur de nœuds (192.168.100.22)

[1] Configurer l'adresse IP virtuelle

[root@localhost ~]# cd /etc/sysconfig/network-scripts/
[root@localhost network-scripts]# cp ifcfg-lo ifcfg-lo:0
[root@localhost network-scripts]# vi ifcfg-lo:0

DEVICE=lo:0
IPADDR=192.168.100.10
NETMASK=255.255.255.255
ONBOOT=yes

[root@localhost network-scripts]# ifup lo:0
[root@localhost network-scripts]# ip addr                   ####我是最小化安装
看看 lo:0 接口上设的IP是否出现

[root@localhost network-scripts]# vi /etc/rc.local 
/sbin/route add -host 192.168.100.100 dev lo:0                 ####在末尾添加

[root@localhost network-scripts]# route add -host 192.168.100.100 dev lo:0
( -bash: route: command not found     #### 出现这个报错就 yum -y install net-tools 安装这个工具)

[2] Ajuster les paramètres de réponse / proc

[root@localhost 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

[root@localhost network-scripts]# sysctl -p                    ####查看是否生效
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

[3] Installer la page de test de montage httpd

[root@localhost ~]# yum -y install httpd
[root@localhost ~]# systemctl start httpd
[root@localhost ~]# systemctl enable httpd
[root@localhost ~]# yum -y install nfs-utils
[root@localhost ~]# mount 192.168.100.24:/opt/51xue /var/www/html/
[root@localhost ~]# df -Th                       ####查看挂载情况
[root@localhost ~]# vi /etc/fstab 
192.168.100.24:/opt/51xue /var/www/html nfs defaults,_netdev 0 0        ###开机自动挂载,注意格式对齐
[root@localhost ~]# systemctl start nfs
[root@localhost ~]# systemctl enable nfs

[root@localhost ~]# showmount -e 192.168.100.24        ####如果还没发布,请到存储服务器发布下,exportfs -rv(如果报错就是配置出错了)
Export list for 192.168.100.24:
/opt/52xue 192.168.100.0/24
/opt/51xue 192.168.100.0/24
  • Connectez-vous à 192.168.100.22 pour vérifier si le site Web est normal.
    Test de la machine réelle:
    Insérez la description de l'image ici
    test du client:
    Insérez la description de l'image ici

Configurer le serveur de nœuds (192.168.100.23)

[1] Configurer l'adresse IP virtuelle

[root@localhost ~]# cd /etc/sysconfig/network-scripts/
[root@localhost network-scripts]# cp ifcfg-lo ifcfg-lo:0
[root@localhost network-scripts]# vi ifcfg-lo:0

DEVICE=lo:0
IPADDR=192.168.100.100
NETMASK=255.255.255.255
ONBOOT=yes

[root@localhost network-scripts]# ifup lo:0
[root@localhost network-scripts]# ip addr              ####我是最小化安装
看看 lo:0 接口上设的IP是否出现

[root@localhost network-scripts]# vi /etc/rc.local 
/sbin/route add -host 192.168.100.100 dev lo:0                ####在末尾添加

[root@localhost network-scripts]# route add -host 192.168.100.100 dev lo:0
( -bash: route: command not found     #### 出现这个报错就 yum -y install net-tools 安装这个工具)

[2] Ajuster les paramètres de réponse / proc

[root@localhost 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

[root@localhost network-scripts]# sysctl -p                 ####查看是否生效

   ...............

[3] Installer la page de test de montage httpd

[root@localhost ~]# yum -y install httpd
[root@localhost ~]# systemctl start httpd
[root@localhost ~]# systemctl enable httpd
[root@localhost ~]# yum -y install nfs-utils
[root@localhost ~]# mount 192.168.100.24:/opt/52xue /var/www/html/
[root@localhost ~]# df -Th                       ####查看挂载情况
[root@localhost ~]# vi /etc/fstab 
192.168.100.24:/opt/52xue /var/www/html nfs defaults,_netdev 0 0        ###开机自动挂载,注意格式对齐
[root@localhost ~]# systemctl start nfs
[root@localhost ~]# systemctl enable nfs

[root@localhost ~]# showmount -e 192.168.100.24     
Export list for 192.168.100.24:
/opt/52xue 192.168.100.0/24
/opt/51xue 192.168.100.0/24
  • Connectez-vous à 192.168.100.23 pour vérifier si le site Web est normal.
    Test de la machine réelle:
    Insérez la description de l'image ici
    test du client:
    Insérez la description de l'image ici

Équilibrage de charge LVS de test client

Insérez la description de l'image ici
Insérez la description de l'image ici

  • Test de la machine réelle
    Insérez la description de l'image ici
    Insérez la description de l'image ici

Je suppose que tu aimes

Origine blog.csdn.net/XCsuperman/article/details/108744813
conseillé
Classement