1. Environment Preparation:
Three virtual machines: assigning IP (note that the LVS Scheduler provides services to the VIP, the other two ensure that the Web can provide normal service)
2, the work of the common version 1.24 and 1.2.6, if it is centos5 with 1.24, if 6 with 1.26 (LVs do not need to use a high version)
3,lsmod command -shows the kernel module loaded into the system Lsmod is actually the list modules abbreviation.
LB configuration:
4, first resolve the dependency: Yum install libnl* popt*-y
5, download LVS, note that the use of CENTOS6, after the completion of the decompression compiled.
wget http://www.linuxvirtualserver.org/software/kernel-2.6/ipvsadm-1.26.tar.gz
Tar zxf ipvsadm-1.26.tar.gz
CD ipvsadm-1.26
Make
Make install
Lsmod |grep Ip_vs
/sbin/ipvsadm #?modprobe Ip_vs
Cd.. /
6. View results lsmod |grep Ip_vs
Ip_vs 125220 0
LIBCRC32C 1246 1 Ip_vs
IPv6 317340 Ip_vs,ip6t_reject,nf_conntrack_ipv6,nf_defrag_ipv6
7, because LVS is based on the kernel, so: ln-s/usr/src/kernels/2.6.32-431.el6.x86_64//usr/src/linux
If not, it may be missing: kernel-devel-this package.
7, manually configure LVS before you better look at the help information, here a simple comment, but enough.
--add-service-a (Virtual service Add)
Add virtual service with options
--add-server-a Specifying nodes
Add real server with options
--TCP-SERVICE-T service-address Node IP
Service-address is host[:p ort]
--tcp-service-t Specify a VIP address and port
Service-address
--save-s Specifying the algorithm
Save rules to stdout
--persistent-p [Timeout] meeting session hold
Persistent service
Specify mode:-G Dr Mode-I tun mode-M NAT mode
-W Weights
8, add a VIP and two nodes.
Network Card settings:
Ifconfig eth0:0 10.10.70.14/24 up
Check: Ping 10.10.70.14
PING 10.10.70.14 (10.10.70.14) bytes of data.
Bytes from 10.10.70.14:icmp_seq=1 ttl=64 time=0.238 ms
Bytes from 10.10.70.14:icmp_seq=2 ttl=64 time=0.040 ms
Note: In the work to the VIP to the domain name.
Clear All configurations:
Ipvsadm-c
Set timeout: Ipvsadm--set 30 5 60 (can not match)
VIP add: ipvsadm-a-T 10.10.70.14:80-s rr-p 20
Node added: ipvsadm-a-T 10.10.70.14:80-r 10.10.70.10-g-W 1
Ipvsadm-a-T 10.10.70.14:80-r 10.10.70.11-g-W 1
9. View: Ipvsadm-l-N
IP Virtual Server version 1.2.1 (size=4096)
Prot Localaddress:port Scheduler Flags
Remoteaddress:port Forward Weight activeconn inactconn
TCP 10.10.70.14:80 RR Persistent 20
-10.10.70.11:80 Route 1 0 0
-10.10.70.11:80 Route 1 0 0
10. Example of node deletion: ipvsadm-d-t 10.10.70.14:80-r 10.10.70.12
VIP Deletion Example: ipvsadm-d-T 10.10.70.14:80
Node configuration:
12. Bind VIP on two node servers:
Ifconfig lo:0 10.10.70.14/32 up
Note: The VIP is bound on the loopback interface Lo Device (its broadcast address is itself), and the subnet mask is 255.255.255.255, guaranteeing no conflict
13. Suppress ARP accordingly:
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
14, after the test, you can also use Watch-n 1 ipvsadm-l-N to view on lb.
View: Ipvsadm-l-n--stats--sort and so on.
Note: All of the above configuration is a temporary configuration. ~~~~!!! Workaround: Write the script.
As follows:
#!/bin/bash
. /etc/init.d/functions
vip=10.10.70.14
Port=80
Rip= (
10.10.70.11
10.10.70.10
)
Start () {
Ifconfig eth0:0 $VIP/24 up
Route add-host $VIP Dev eth0
Ipvsadm-c
Ipvsadm--set 30 5 60
Ipvsadm-a-T $VIP: $PORT-S Rr-p 20
For ((i=0;i<${#RIP [*]};i++))
Do
Ipvsadm-a-T $VIP: $PORT-R ${rip[$i]}-g-w 1
Done
}
Stop () {
Ipvsadm-c
Ifconfig eth0:0 Down
Route del-host $VIP Dev eth0
}
Case "$" in
Start
Start
echo "Yes"
;;
Stop
Stop
echo "No"
;;
Restart
echo "Restart OK"
;;
*)
echo "Usage:$0 {stop| Start| REStat} "
Esac
This article from "As always" blog, declined reprint!
Configuration of LVs