In this paper, the implementation of LVS using NAT mode, about NAT topology map please refer to my previous article, this article purely experimental, NAT in production environment is not recommended, because the load balancer easy to become a bottleneck!
Install version centos-6.5-x86_64-minimal on 1.vmware9
2. When the installation is complete, set its hostname to Lvs-master
Hostname lvs-mastersudo-i
3. Then copy two copies of the virtual machine files to become RS1 and RS2
Three virtual machines are bridged network mode, the biggest advantage is the direct use of real routes to them in the same LAN can access each other. There is no need to configure two network cards on the Lvs-master, just configure one more virtual IP.
4. Configure on the Lvs-master:
Modprobe-l |grep Ipvs
If you see it as a result, you can continue.
Installing Ipvsadm
Yum-y Install Ipvsadm
Open Nginx
Service Nignx Startchkconfig Nginx on
Configure VIP 192.168.83.198 Let it provide HTTP service to the outside
Ifconfig eth0:0 192.168.83.198 netmask 255.255.255.255 Broadcast 192.168.83.230
Let it have the IP forwarding function
Echo 1 >/proc/sys/net/ipv4/ip_forward
Configure Virtual Services
Ipvsadm-a-T 192.168.20.87:80-s WLC
Add a real Server1
Ipvsadm-a-T 192.168.83.198:80-r 192.168.83.87-g
Add a real Server2
Ipvsadm-a-T 192.168.83198:80-r 192.168.83.88-g
Finally, write the above five scripts on the/etc/rc.local and let the machine start to run automatically.
5. Configure on the RS1
Add the following four sentences to the end of the/etc/sysctl.conf file:
Net.ipv4.conf.lo.arp_ignore = 1net.ipv4.conf.lo.arp_announce = 2net.ipv4.conf.all.arp_ignore = 1net.ipv4.conf.all.arp_announce = 2
Above indicates that ARP is turned off
Ifconfig lo:0 192.168.83.198 netmask 255.255.255.255 broadcast 192.168.83.198 up
Add route
Route add-host 192.168.83.198 Dev lo:0
Open Nginx Service
Service Nginx Start
Represents index.html
Echo ' The response is from Real Server1 ' >/var/www/html/index.html
6. Configuration on RS2 and RS1 similarity
7. Final Test
The last visit to 192.168.83.198 will appear the response is from real server1 or the response is from real server2~
That ' s it!
Implementing LVS Load Balancing (NAT) on VMware