LVS Load Balancing Chapter 2--LVS-DR (Direct Routing Mode)

      In the DR mode, the LVS load scheduler serves as the access entry of the cluster, but it is not used as a gateway. The nodes in the server are connected to the Internet, and the web response sent to the client does not pass through the LVS load scheduler.

In this way, inbound and outbound data are processed separately, so the LVS load scheduler and all nodes need to be configured with VIP addresses in order to respond to the access of the entire cluster.

 surroundings:

 Load scheduler ens33:192.168.253.110 ens33:0 :192.168.253.100

 Node 1: ens33: 192.168.253.120 lo:0: 192.168.253.100

 Node 2: ens33: 192.168.253.130 lo:0: 192.168.253.100

[root@localhost ~]# setenforce 0
[root@localhost ~]# systemctl stop firewalld    防火墙全部关闭状态
  • Load scheduler: Using virtual interface mode (eth0:0), bind the VIP address to the network card eth0 in order to respond to cluster access. ens33:192.168.253.110 ens33:0:192.168.253.100

1. Load the lvs kernel module

 LVS has now become a part of the Linux kernel, compiled as an ip_vs module by default, and can be called automatically when necessary. The following operations can manually load the ip_vs module and view the version information of the ip_vs module in the current system.

[root@localhost ~]# modprobe ip_vs    加载ip_vs模块
[root@localhost ~]# cat /proc/net/ip_vs     查看ip_vs版本信息
IP Virtual Server version 1.2.1 (size=4096)
[root@localhost ~]# yum -y install ipvsadm   安装管理工具

2. Add the virtual interface of the virtual address and the local route

[root@localhost ~]# ifconfig ens33:0 192.168.253.100 broadcast 192.168.253.100 netmask 255.255.255.255 up     此种方法是临时的,重启网卡则不生效
[root@localhost ~]# route add -host 192.168.253.100 dev ens33:0   添加路由
##[root@localhost ~]# vim /etc/rc.local  配置中添加可以不用操作这步 
 /sbin/route add -host 192.168.253.100 dev ens33:0  ##

3. Configure the load distribution strategy

[root@localhost ~]# ipvsadm -A -t 192.168.253.100:80 -s rr
[root@localhost ~]# ipvsadm -a -t 192.168.253.100:80 -r 192.168.253.120:80 -g -w 1
[root@localhost ~]# ipvsadm -a -t 192.168.253.100:80 -r 192.168.253.130:80 -g -w 1
[root@localhost ~]# ipvsadm -ln   #查看节点状态

4. Configure the web server, where I configure both nodes at the same time

When using the DR mode, the node server also needs a VIP address, and adjusts the kernel's ARP response parameters to prevent the VIP MAC address from being updated and avoid conflicts. Otherwise, the web server configuration is the same as NAT mode.

Configure virtual IP address

Each node server also needs to have vip, 192.168.20.139, but the address here is only used as the source address for sending web response packets, and does not need to monitor the client's access request (monitored and distributed by the scheduler). Therefore, the virtual interface lo:0 is used to carry the VIP address, and a routing record is added to the machine to limit the data accessing VIP to the local area to avoid communication disorder.

#两台节点都操作
[root@localhost ~]# ifconfig lo:0 192.168.253.100 broadcast 192.168.253.100 netmask 255.255.255.255 up   临时的重启网卡则不生效
[root@localhost ~]# route add -host 192.168.253.100 dev lo:0
[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
[root@localhost ~]# yum -y install httpd
web1 [root@localhost ~]# echo "welcome to hya" > /var/www/html/index.html
web2 [root@localhost ~]# echo "welcome to hya2" > /var/www/html/index.html
[root@localhost ~]# systemctl  start httpd

4. Test through vip

[root@localhost ~]# ipvsadm -lnc
IPVS connection entries
pro expire state       source             virtual            destination
TCP 14:45  ESTABLISHED 192.168.253.1:50930 192.168.253.100:80 192.168.253.120:80
TCP 14:53  ESTABLISHED 192.168.253.1:50925 192.168.253.100:80 192.168.253.130:80

 

Guess you like

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