LVS implements load balancing

IP address planning

        ____________

       |                        |

       |  client              |

       |____________|                     

     CIP = 192.168.0.253 (eth0)             

              |                           

              |                           

     VIP=192.168.194.130 (eth1)             

        ____________                      

       |                        |                     

       |  director          |                     

       |____________|                     

     DIP=192.168.201.129 (eth0)         

              |                           

           (switch)------------------------

              |                           |

     RIP=192.168.201.200 (eth1)       RIP=192.168.201.201 (eth1)

        _____________               _____________

       |                          |             |                          |

       | realserver1       |             | realserver2       |

       |_____________|             |_____________|  

Configure ip address:

Modify the configuration file: ifcfg-eth0 or ifcfg-eth1 under /etc/sysconfig/network-script/

 

There are two network cards on the director:

/etc/sysconfig/network-script/ifcfg-eth1 is modified to

DEVICE=eth1

BOOTPROTO=static

HWADDR=00:0C:29:21:6D:9F

IPADDR=192.168.194.130

NETMASK=255.255.255.0

GATEWAY=192.168.194.2

IPV6INIT=no

NM_CONTROLLED=no

ONBOOT=yes

TYPE=Ethernet

UUID="0ecd1937-cd5f-4282-b0a7-ad5cb48a4cb6"

USERCTL=no

DNS1=192.168.1.1

PEERDNS=yes

 

/etc/sysconfig/network-script/ifcfg-eth0 is modified to

DEVICE=eth0

BOOTPROTO=static

HWADDR=0:0c:29:21:6d:95

IPADDR=192.168.201.129

NETMASK=255.255.255.0

IPV6INIT=no

NM_CONTROLLED=no

ONBOOT=yes

TYPE=Ethernet

UUID="0ecd1937-cd5f-4282-b0a7-ad5cb48a4cb6"

USERCTL=no

DNS1=192.168.1.1

PEERDNS=yes

 

realserver1

/etc/sysconfig/network-script/ifcfg-eth0 is modified to

DEVICE="eth1"

BOOTPROTO="static"

IPADDR=192.168.201.200

NETMASK=255.255.255.0

GATEWAY=192.168.201.129

HWADDR="00:0C:29:13:5C:B0"

NM_CONTROLLED="no"

ONBOOT="yes"

TYPE="Ethernet"

UUID="a2e0838f-cd7d-45bd-92bc-9146f4f2aeb5"

 

Gateway needs to be specified as DIP

DEVICE="eth1"

BOOTPROTO="static"

HWADDR="00:0C:29:58:D7:F3"

IPADDR=192.168.201.201

NETMASK=255.255.255.0

GATEWAY=192.168.201.129

NM_CONTROLLED="no"

ONBOOT="yes"

TYPE="Ethernet"

UUID="a2e0838f-cd7d-45bd-92bc-9146f4f2aeb5"

 

After configuring the network, restart the network services of each host separately

service network restart

 

Close the iptables service of each host

service iptables stop

chkconfig iptables off

 

Install httpd on realserver1 and realserver2

yum -y install httpd

 

After the installation is complete, create a new index.html file in the /var/www/html path, and write the servername as the load balancer to distinguish whether the request is correctly distributed.

echo realserver1 > index.html

 

Start httpd services on realserver1 and realserver2 respectively

service httpd start

chkconfig httpd on

Access the web services of the two hosts respectively to see if the services are already accessible.

http://192.168.201.200

http://192.168.201.201

 

Enable routing forwarding on the director

echo "1" > /proc/sys/net/ipv4/ip_forward

 

 

Create a service in the director

ipvsadm -A -t 192.168.194.130:80 -s rr

 

 

ipvsadm -a -t 192.168.194.130:80 -r 192.168.201.200 -m -w 1

ipvsadm -a -t 192.168.194.130:80 -r 192.168.201.201 -m -w 1

 

 

Access through the director's VIP

http://192.168.194.130

Load balancing falls on two realservers

Save the established rules

service ipvsadm save

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=327042264&siteId=291194637