LVS Load Balancing Chapter 3--LVS-NAT (Address Translation Mode)

        In the nat mode cluster, the lvs load scheduler is the gateway server for all nodes to access the Internet. Its external network address is 192.168.253.110, and it also serves as the VIP address of the entire cluster. The Lvs scheduler has two network cards respectively connected to the internal and external networks.

surroundings:

 Lvs load scheduler: ens33: 192.168.253.110 (external network in nat mode) ens37: 192.168.253.111.128 (network only host mode)

web1 side: ens33:192.168.253.120 (network only host mode) web2 side: 192.168.253.130 (network only host mode)

Install httpd on the web in advance, otherwise the host-only mode may not have internet

1. Load the ip_vs module, turn on the routing and forwarding function, and turn off the redirection of icmp

[root@localhost ~]# modprobe ip_vs
[root@localhost ~]# echo 1 > /proc/sys/net/ipv4/ip_forward    开启路由转发功能
[root@localhost ~]# echo 0 > /proc/sys/net/ipv4/conf/all/send_redirects   关闭icmp重定向
[root@localhost ~]# echo 0 > /proc/sys/net/ipv4/conf/default/send_redirects
#注意区分网卡名字,两个网卡分别为ens33和ens37
[root@localhost ~]# echo 0 > /proc/sys/net/ipv4/conf/ens33/send_redirects
[root@localhost ~]# echo 0 > /proc/sys/net/ipv4/conf/ens37/send_redirects

2. Install the lvs tool and configure the load distribution strategy

[root@localhost ~]# yum -y install ipvsadm
[root@localhost ~]# ipvsadm -A -t 192.168.253.110:80 -s rr
[root@localhost ~]# ipvsadm -a -t 192.168.253.110:80 -r 192.168.253.120:80 -m -w 1
[root@localhost ~]# ipvsadm -a -t 192.168.253.110:80 -r 192.168.253.130:80 -m -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.253.110:80 rr
  -> 192.168.253.120:80           Masq    1      0          0         
  -> 192.168.253.130:80           Masq    1      0          0    

3. Write a test page on web1 and 2 and start the service

[root@localhost ~]# echo "welcome to hya" > /var/www/html/index.html
[root@localhost ~]# echo "welcome to hya222" > /var/www/html/index.html
[root@localhost ~]# systemctl start httpd

4. Test

[root@localhost ~]# ipvsadm -lnc
IPVS connection entries
pro expire state       source             virtual            destination
TCP 00:11  SYN_RECV    192.168.253.110:60710 192.168.253.110:80 192.168.253.120:80
TCP 00:41  SYN_RECV    192.168.253.110:60712 192.168.253.110:80 192.168.253.130:80

 

 

Guess you like

Origin blog.csdn.net/yeyslspi59/article/details/108033040