Cthis article mainly introduces how to install and configure lvs in centos. all of the following operations need to disable Selenge and iptables. for details, refer to CentOS.
I. lvs-nat mode
Network configuration:
Copy codeThe code is as follows:
Lvs-server eth0: host-only adapter 192.168.56.101
Lvs-server eth1: Internal 192.168.0.1
Real-server-1 eth0: Internal 192.168.0.2
Real-server-2 eth0: Internal 192.168.0.3
Lvs-server:
1. install ipvsadm software
Copy codeThe code is as follows:
Yum-y install ipvsadm *
Echo 1>/proc/sys/net/ipv4/ip_forward vro function, ip forwarding
Ipvsadm-C
Ipvsadm-At 192.168.56.101: 80-s rr call mode
Ipvsadm-at 192.168.56.101: 80-r 192.168.0.2-m
Ipvsadm-at 192.168.56.101: 80-r 192.168.0.3-m
Ipvsadm-L-n
2. real-server-1:
Copy codeThe code is as follows:
Ifconfig eth0 192.168.0.2 netmask 255.255.255.0
Route add default gw 192.168.0.1
3. real-server-2
Copy codeThe code is as follows:
Ifconfig eth0 192.168.0.3 netmask 255.255.255.0
Route add default gw 192.168.0.1
Route-n View route table
II. lvs-ipturn
Network configuration:
Copy codeThe code is as follows:
Lvs-server eth0: host-only adapter 192.168.56.101
Real-server-1 eth0: host-only adapter 192.168.56.102
Real-server-2 eth0: host-only adapter 192.168.56.103
Lvs-server:
Configure virtual ip (vip)
Copy codeThe code is as follows:
Ifconfig tunl0 192.168.56.10 netmask 255.255.255.255 up
Route add-host 192.168.56.10 dev tunl0
Ivsadm-C
Ipvsadm-At 192.168.56.10: 80-s rr
Ipvsadm-at 192.168.56.10: 80-r 192.168.56.102-I
Ipvsadm-at 192.168.56.10: 80-r 192.168.56.103-I
Ipvsadm-L-n
Real-server-1:
Copy codeThe code is as follows:
Ifconfig tunl0 192.168.56.10 netmask 255.255.255.255 up
Route add-host 192.168.56.10 dev tunl0
Echo 1>/proc/sys/net/ipv4/conf/tunl0/arp_ignore
Echo 2>/proc/sys/net/ipv4/conf/tunl0/arp_announce
Echo 1>/proc/sys/net/ipv4/conf/all/arp_ignore
Echo 2>/proc/sys/net/ipv4/conf/all/arp_announce
Real-server-2:
Copy codeThe code is as follows:
Ifconfig tunl0 192.168.56.10 netmask 255.255.255.255 up
Route add-host 192.168.56.10 dev tunl0
Echo 1>/proc/sys/net/ipv4/conf/tunl0/arp_ignore
Echo 2>/proc/sys/net/ipv4/conf/tunl0/arp_announce
Echo 1>/proc/sys/net/ipv4/conf/all/arp_ignore
Echo 2>/proc/sys/net/ipv4/conf/all/arp_announce
III. lvs-dr
Network configuration:
Copy codeThe code is as follows:
Lvs-server eth0: host-only adapter 192.168.56.101
Real-server-1 eth0: host-only adapter 192.168.56.102
Real-server-2 eth0: host-only adapter 192.168.56.103
Lvs-server:
Ifconfig eth0: 0 192.168.56.10 netmask 255.255.255.255
Route add-host 192.168.56.10 dev eth0: 0
Ipvs:
Copy codeThe code is as follows:
Ipvsadm-C ipvsadm-At 192.168.56.10: 80-s rr ipvsadm-at 192.168.56.10: 80-r 192.168.56.102-g ipvsadm-at 192.168.56.10: 80-r 192.168.56.103-g ipvsadm-L-n
Real-server-1: ifconfig lo: 0 192.168.56.10 netmask 255.255.255.255 route add-host 192.168.56.10 dev lo: 0 echo 1>/proc/sys/net/ipv4/conf/lo/arp_ignore echo 2>/proc/sys/net/ipv4/conf/lo/arp_announce echo 1>/proc /sys/net/ipv4/conf/all/arp_ignore echo 2>/proc/sys/net/ipv4/conf/all/arp_announce
Real-server-2: ifconfig lo: 0 192.168.56.10 netmask 255.255.255.255 route add-host 192.168.56.10 dev lo: 0 echo 1>/proc/sys/net/ipv4/conf/lo/arp_ignore echo 2>/proc/sys/net/ipv4/conf/lo/arp_announce echo 1>/proc /sys/net/ipv4/conf/all/arp_ignore echo 2>/proc/sys/net/ipv4/conf/all/arp_announce