Environment:
LVS/Dr server: 200.168.10.1
Real rip: 200.168.10.2
Real rip: 200.168.10.3
VIP: 200.168.10.10
LVS server configuration:
Disable iptables and selinux to prevent failure due to firewall and other reasons.
Install ipvsadm
Yum-y install ipvsadm *
Run the following script:
#! /Bin/bash
# Ipvs. sh
# Bind 200.168.10.10 to the eth0: 0 interface. The subnet mask is 4 255 so that 200.168.10.10 only has this ip address in this network segment and does not conflict with other ip addresses.
/Sbin/ifconfig eth0: 0 200.168.10.10 broadcast 200.168.10.10 netmask bandwidth limit 255 up
# Add 200.168.10.10 to the route table. It is best to add the route table to avoid having no ip addresses in the route table.
/Sbin/ifconfig route add-host 200.168.10.10 dev eth0: 0
# Clear existing records of ipvs
/Sbin/ipvsadm-C
# Add the virtual service rr representation algorithm (average allocation)
/Sbin/ipvsadm-At 200.168.10.10: 80-s rr
#-G indicates Dr mode,-I indicates ip-tun, and-m indicates NAT mode
/Sbin/ipvsadm-at 200.168.10.10: 80-r 200.168.10.2: 80-g
/Sbin/ipvsadm-at 200.168.10.10: 80-r 200.168.10.3: 80-g
/Sbin/ipvsadm-L-n
Linux real server configuration:
/Sbin/ifconfig lo: 0 200.168.10.10 broadcast 200.168.10.10 netmask bandwidth limit 255 up
/Sbin/ifconfig route add-host 200.168.10.10 dev lo: 0
Echo 1>/proc/sys/net/ipv4/conf/lo/arp_ignore
Echo 2>/proc/sys/net/ipv4/conf/lo/arp_annoounce
Echo 1>/proc/sys/net/ipv4/conf/all/arp_ignore
Echo 2>/proc/sys/net/ipv4/conf/all/arp_annoounce