1. Prepare for LVS installation:
1. Prepare four Centos 6.2 x86_64
Note: SELinux and IPtables firewalls are disabled in this experiment.
Manage IP addresses |
Role |
Remarks |
192.168.1.101 |
LVS Master scheduler Master ctor) |
The VIP address for external services is 192.168.1.180. |
192.168.1.114 |
LVS slave scheduler Backup ctor) |
Can be used as a real RS server) |
192.168.1.104 |
RS1 Real Server) |
|
192.168.1.103 |
RS2 Real Server) |
|
2. Configure simple HTTP Services
The following uses the apache service as an example to install the httpd service using yum-y install httpd.
Perform the following operations on 192.168.1.103 and 192.168.1.104 respectively:
- [Root @ centos ~] # Yum-y install httpd
- Echo 103> On/var/www/html/index.html #104, change the 103 field to 104)
- [Root @ centos ~] # Service httpd start # start the http service
- [Root @ centos ~] # Ps-ef | grep httpd # Check if the process has similar output, indicating that the startup is successful.
Root 1535 1 0 23:27? 00:00:00/usr/sbin/httpd
Apache 1537 1535 0? 00:00:00/usr/sbin/httpd
Apache 1538 1535 0? 00:00:00/usr/sbin/httpd
Apache 1539 1535 0? 00:00:00/usr/sbin/httpd
- [Root @ centos ~] # Setenforce 0 # disable SELinux
- [Root @ centos ~] #/Etc/rc. d/init. d/iptables stop # disable the Firewall
3. Test the http service configuration:
650) this. width = 650; "border =" 0 "alt =" "src =" http://www.bkjia.com/uploads/allimg/131228/024524N00-0.png "/>
Note: The last digit of the IP address represents the RS content, which is easy for everyone to see the test results. In actual business, the RS service content should be identical.
4. Start LVS Installation
Download related software packages:
- [root@centos1 ~]# mkdir download
- [root@centos1 ~]# cd download/
- [root@centos1 download]# wget http://www.linuxvirtualserver.org/software/kernel-2.6/ipvsadm-1.24.tar.gz
5. Installation command Note: The following installation operations must be performed on 192.168.1.101 and 192.168.1.104:
- [Root @ centos1 download] # uname-r # view the Linux kernel version
- 2.6.32-220. el6.x86 _ 64
- [Root @ centos1 download] # ln-s/usr/src/kernels/2.6.32-220. el6.x86 _ 64 // usr/src/linux # If this step is not performed, an error is reported during installation.
- Note: the path of the ln command must be the same as the kernel version output by uname-r. If no kernel version is available, the path is/usr/src/kernels/2.6.32-220. el6.x86 _ 64/the kernel-devel package must be installed.
- [Root @ centos1 download] # tar zxvf ipvsadm-1.24.tar.gz
- [Root @ centos1 download] # cd ipvsadm-1.24
- [Root @ centos1 ipvsadm-1.24] # make
- [Root @ centos1 ipvsadm-1.24] # make install
- [Root @ centos1 ipvsadm-1.24] # ipvsadm # execute the ipvsadm command to add LVS to the Linux Kernel
- IP Virtual Server version 1.2.1 (size = 4096)
- Prot LocalAddress: Port sched1_flags
- -> RemoteAddress: Port Forward Weight ActiveConn InActConn
- [Root @ centos1 ipvsadm-1.24] # lsmod | grep ip_vs # Check whether LVS has been added to the Linux kernel, if the following output indicates that it has been successful.
- Ip_vs 108133 0
- Ipv6 322029 154 ip_vs, ip6t_REJECT, nf_conntrack_ipv6, nf_defrag_ipv6
6. Configure The LVS Server
Configure the lvs dr mode on 192.168.1.101 and 192.168.1.114 respectively.
1) Configure LVS and create a script to configure LVS
Note: The configuration on 192.168.1.101 and 192.168.1.114 is the same.
- [Root @ centos1 bin] # vim lvs_dr.sh
- #! /Bin/bash
- ./Etc/init. d/functions
- Vim lvs_dr.sh
- #! /Bin/bash
- GW = 192.168.1.1
- # Website director vip.
- SNS_VIP = 192.168.1.181
- SNS_RIP1 = 192.168.1.103
- SNS_RIP2 = 192.168.1.104
- Logger $0 called with $1
- Case "$1" in
- Start)
- # Set squid vip
- /Sbin/ipvsadm -- set 30 5 60
- /Sbin/ifconfig eth0: 0 $ SNS_VIP broadcast $ SNS_VIP netmask 255.255.255 up
- /Sbin/route add-host $ SNS_VIP dev eth0: 0
- /Sbin/ipvsadm-A-t $ SNS_VIP: 80-s wrr-p 3
- /Sbin/ipvsadm-a-t $ SNS_VIP: 80-r $ SNS_RIP1: 80-g-w 1
- /Sbin/ipvsadm-a-t $ SNS_VIP: 80-r $ SNS_RIP2: 80-g-w 1
- Touch/var/lock/subsys/ipvsadm>/dev/null 2> & 1
- ;;
- Stop)
- /Sbin/ipvsadm-C
- /Sbin/ipvsadm-Z
- Ifconfig eth0: 0 down
- Ifconfig eth0: 1 down
- Route del $ SNS_VIP
- Route del $ SS_VIP
- Rm-rf/var/lock/subsys/ipvsadm>/dev/null 2> & 1
- Echo "ipvsadm stoped"
- ;;
- Status)
- If [! -E/var/lock/subsys/ipvsadm]; then
- Echo "ipvsadm stoped"
- Exit 1
- Else
- Echo "ipvsadm OK"
- Fi
- ;;
- *)
- Echo "Usage: $0 {start | stop | status }"
- Exit 1
- Esac
- Exit 0
- [Root @ centos1 bin] # chmod + x lvs_dr.sh
- [Root @ centos1 bin] # cp lvs_dr.sh/etc/rc. d/init. d/# Easy to start
- [Root @ centos1 bin] # service lvs_dr.sh start # start The lvs service
Run the ipvsadm-Ln command to check whether the following output exists. If yes, The LVS configuration is successful.
- [root@centos1 bin]# ipvsadm
- IP Virtual Server version 1.2.1 (size=4096)
- Prot LocalAddress:Port Scheduler Flags
- -> RemoteAddress:Port Forward Weight ActiveConn InActConn
- TCP 192.168.1.181:http wrr persistent 3
- -> 192.168.1.104:http Route 1 0 0
- -> 192.168.1.103:http Route 1 0 0
7. Configure The lvs rs Server
- [Root @ centos bin] # vim lvs_dr.sh
- #! /Bin/bash
- ./Etc/init. d/functions
- SNS_VIP = 192.168.1.181
-
- Case "$1" in
- Start)
- Ifconfig lo: 0 $ SNS_VIP netmask 255.255.255.255 broadcast $ SNS_VIP
- /Sbin/route add-host $ SNS_VIP 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
- Sysctl-p>/dev/null 2> & 1
- Echo "RealServer Start OK"
- ;;
- Stop)
- Ifconfig lo: 0 down
- Route del $ SNS_VIP>/dev/null 2> & 1
- Echo "0">/proc/sys/net/ipv4/conf/lo/arp_ignore
- Echo "0">/proc/sys/net/ipv4/conf/lo/arp_announce
- Echo "0">/proc/sys/net/ipv4/conf/all/arp_ignore
- Echo "0">/proc/sys/net/ipv4/conf/all/arp_announce
- Echo "RealServer Stoped"
- ;;
- *)
- Echo "Usage: $0 {start | stop }"
- Exit 1
- Esac
- Exit 0
- [Root @ centos bin] # cp lvs_dr.sh/etc/rc. d/init. d/
- [Root @ centos bin] # service lvs_dr.sh start # start The lvs RS Server
- RealServer Start OK
8. verify whether the lvs dr mode is configured successfully.
Enter LVS http: // 192.168.1.181 in the browser
650) this. width = 650; "border =" 0 "alt =" "src =" http://img1.51cto.com/attachment/201301/170751847.png "/>
Open another browser and enter http: // 192.168.1.181 again to check whether the content is the same.
650) this. width = 650; "border =" 0 "alt =" "src =" http://www.bkjia.com/uploads/allimg/131228/0245243632-2.png "/>
The content accessed by two browsers is different, and the lvs dr mode is successfully configured.
By now, the lvs dr mode has been configured. The following describes how to configure lvs dr + Keepalived high-availability server Load balancer.
This article from the "ordinary days" blog, please be sure to keep this source http://wolfchen.blog.51cto.com/2211749/1122841