DIP: the IP address RIP of the Scheduler: the IP address VIP of the real server in the background: it is the simplest and easiest way to implement the virtual IPNAT mode provided by the Service, the scheduler is fully responsible for client requests and replies to internal servers. The scheduler is equivalent to a vro and requires two NICs and two
DIP: the IP address of the scheduler.
RIP: Real backend server (reaLsErver) IP Address
VIP: the virtual IP address provided by the Service.
The NAT mode is the simplest and easiest to implement. The scheduler is fully responsible for the client's requests and replies to internal servers. The scheduler is equivalent to a vro and requires two NICs and two IP addresses (one public IP address and one private IP address). The public IP address, that is, the DIP, is used for processing on the local machine, VIP is bound to the scheduler (of course, for only one scheduler, VIP can be equal to DIP. If high availability is used, VIP is not equal to DIP, because the VIP slides on two or more schedulers, RIP (realserver IP) uses the internal IP address of the scheduler as the gateway, of course, for linux servers used as schedulers, You need to enable ip_forward. RIP usually uses some private IP addresses, which of course aims to save limited public IP addresses. Sometimes NAT is usedServer Load balancerThis is often due to limited IP address restrictions. Otherwise, Server Load balancer should not be used in this way. The reason is that the Server Load balancer often becomes a bottleneck in service provision and affects service quality.
The specific implementation process is as follows:
1. The client sends a request to the scheduler first. The scheduler modifies the PACKET socket (socket), IP: port, and modifies the VIP to the RIP of a service according to the scheduling algorithm, and leave the connection cache in your own hash to switch to the realserver Node just selected when the next packet arrives.
2. The Realserver server processes the subcontract. After the process is completed, modify the destination address of the subcontract to DIP and send the subcontract to the scheduler.
3. The scheduler modifies the socket again, changes the destination address to the client address, and then completes the request.
Linux server hosts under three VMS on the experimental platform (CentOS 5.5 and kernel version 2.6 support LVS by default, so you can directly use it without re-compiling the kernel ), one is used as the scheduler, and the other two are used as the realserver.
1. settings on the Scheduler
[Root @ localhost ~] # Vi/etc/sysconfig/network // set the Gateway
NETWORKING = yes
NETWORKING_IPV6 = yes
HOSTNAME = localhost. localdomain
GATEWAY = 192.168.1.1
[Root @ localhost ~] # Vi/etc/sysconfig/network-scripts/ifcfg-eth0 // set public ip (simulated)
# AdvaNcEdMicro Devices [AMD] 79c970 [PCnet32 LANCE]
DEVICE = eth0
BOOTPROTO =StatIc
IPADDR = 192.168.1.196
NETMASK = 255.255.255.0
DHCPCLASS =
HWADDR = 00: 0C: 29: 09: 22: 5D
ONBOOT = yes
[Root @ localhost ~] # Vi/etc/sysconfig/network-scripts/ifcfg-eth1 // another Nic is a private IP
# Advanced Micro Devices [AMD] 79c970 [PCnet32 LANCE]
DEVICE = eth1
BOOTPROTO = static
IPADDR = 10.0.0.1
NETMASK = 255.255.255.0
ONBOOT = yes
[Root @ localhost ~] #/Etc/init. d/network restart // restart the network service
[Root @ localhost ~] #Ifconfig
Eth0 Link encap: Ethernet HWaDdR 00: 0C: 29: 09: 22: 5D
Inet addr: 192.168.1.196 Bcast: 192.168.1.255 Mask: 255.255.255.0
Eth1 Link encap: Ethernet HWaddr 00: 0C: 29: 09: 22: 67
Inet addr: 10.0.0.1 Bcast: 10.0.0.255 Mask: 255.255.255.0
Lo Link encap: Local Loopback
Inet addr: 127.0.0.1 Mask: 255.0.0.0
[Root @ localhost ~] # Yum-y install ipvsadm // install LVS management tool
[Root @ localhost ~] # Vi/etc/init. d/lvsnat // writeClusterYou can also add scripts one by one.
#! /Bin/bash
# LVS script NAT
VIP = 192.168.1.200
RIP1 = 10.0.0.2
RIP2 = 10.0.0.3
#./Etc/rc. d/init. d/functions
Case "$1" in
Start)
Echo "1">/proc/sys/net/ipv4/ip_forward
/Sbin/iptables-F
/Sbin/iptables-t nat-F
/Sbin/ifconfig eth0: 0 $ VIP netmask running 255.255.0 up
/Sbin/ipvsadm-A-t $ VIP: 80-s rr // use the polling Algorithm
/Sbin/ipvsadm-a-t $ VIP: 80-r $ RIP1? M // use NAT
/Sbin/ipvsadm-a-t $ VIP: 80-r $ RIP2-m
/Sbin/ipvsadm
Echo "start LVS of DirectorServer NAT"
;;
Stop)
Echo "0">/proc/sys/net/ipv4/ip_forward
/Sbin/ipvsadm-C
/Sbin/ifconfig eth0: 0 down
Echo "stop LVS of DirectorServer NAT"
;;
*)
Echo "Usage: $0 {start | stop }"
ExIt 1
Esac
[Root @ localhost ~] #ChmodA + x/etc/init. d/lvsnat // Add executable permission