Detailed description of lvs dr Mode Server Load balancer configuration (configuration 1)

Source: Internet
Author: User

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:

 
 
  1. [Root @ centos ~] # Yum-y install httpd
  2. Echo 103> On/var/www/html/index.html #104, change the 103 field to 104)
  3. [Root @ centos ~] # Service httpd start # start the http service
  4. [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
  5. [Root @ centos ~] # Setenforce 0 # disable SELinux
  6. [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:

 
 
  1. [root@centos1 ~]# mkdir download 
  2. [root@centos1 ~]# cd download/ 
  3. [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:
 
 
  1. [Root @ centos1 download] # uname-r # view the Linux kernel version
  2. 2.6.32-220. el6.x86 _ 64
  3. [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.
  4. 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.
  5. [Root @ centos1 download] # tar zxvf ipvsadm-1.24.tar.gz
  6. [Root @ centos1 download] # cd ipvsadm-1.24
  7. [Root @ centos1 ipvsadm-1.24] # make
  8. [Root @ centos1 ipvsadm-1.24] # make install
  9. [Root @ centos1 ipvsadm-1.24] # ipvsadm # execute the ipvsadm command to add LVS to the Linux Kernel
  10. IP Virtual Server version 1.2.1 (size = 4096)
  11. Prot LocalAddress: Port sched1_flags
  12. -> RemoteAddress: Port Forward Weight ActiveConn InActConn
  13. [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.
  14. Ip_vs 108133 0
  15. 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.

 
 
  1. [Root @ centos1 bin] # vim lvs_dr.sh
  2. #! /Bin/bash
  3. ./Etc/init. d/functions
  4. Vim lvs_dr.sh
  5. #! /Bin/bash
  6. GW = 192.168.1.1
  7. # Website director vip.
  8. SNS_VIP = 192.168.1.181
  9. SNS_RIP1 = 192.168.1.103
  10. SNS_RIP2 = 192.168.1.104
  11. Logger $0 called with $1
  12. Case "$1" in
  13. Start)
  14. # Set squid vip
  15. /Sbin/ipvsadm -- set 30 5 60
  16. /Sbin/ifconfig eth0: 0 $ SNS_VIP broadcast $ SNS_VIP netmask 255.255.255 up
  17. /Sbin/route add-host $ SNS_VIP dev eth0: 0
  18. /Sbin/ipvsadm-A-t $ SNS_VIP: 80-s wrr-p 3
  19. /Sbin/ipvsadm-a-t $ SNS_VIP: 80-r $ SNS_RIP1: 80-g-w 1
  20. /Sbin/ipvsadm-a-t $ SNS_VIP: 80-r $ SNS_RIP2: 80-g-w 1
  21. Touch/var/lock/subsys/ipvsadm>/dev/null 2> & 1
  22. ;;
  23. Stop)
  24. /Sbin/ipvsadm-C
  25. /Sbin/ipvsadm-Z
  26. Ifconfig eth0: 0 down
  27. Ifconfig eth0: 1 down
  28. Route del $ SNS_VIP
  29. Route del $ SS_VIP
  30. Rm-rf/var/lock/subsys/ipvsadm>/dev/null 2> & 1
  31. Echo "ipvsadm stoped"
  32. ;;
  33. Status)
  34. If [! -E/var/lock/subsys/ipvsadm]; then
  35. Echo "ipvsadm stoped"
  36. Exit 1
  37. Else
  38. Echo "ipvsadm OK"
  39. Fi
  40. ;;
  41. *)
  42. Echo "Usage: $0 {start | stop | status }"
  43. Exit 1
  44. Esac
  45. Exit 0
  46. [Root @ centos1 bin] # chmod + x lvs_dr.sh
  47. [Root @ centos1 bin] # cp lvs_dr.sh/etc/rc. d/init. d/# Easy to start
  48. [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.

 
 
  1. [root@centos1 bin]# ipvsadm 
  2. IP Virtual Server version 1.2.1 (size=4096) 
  3. Prot LocalAddress:Port Scheduler Flags 
  4.   -> RemoteAddress:Port           Forward Weight ActiveConn InActConn 
  5. TCP  192.168.1.181:http wrr persistent 3 
  6.   -> 192.168.1.104:http           Route   1      0          0          
  7.   -> 192.168.1.103:http           Route   1      0          0          

7. Configure The lvs rs Server

 
 
  1. [Root @ centos bin] # vim lvs_dr.sh
  2. #! /Bin/bash
  3. ./Etc/init. d/functions
  4. SNS_VIP = 192.168.1.181
  5.  
  6. Case "$1" in
  7. Start)
  8. Ifconfig lo: 0 $ SNS_VIP netmask 255.255.255.255 broadcast $ SNS_VIP
  9. /Sbin/route add-host $ SNS_VIP dev lo: 0
  10. Echo "1">/proc/sys/net/ipv4/conf/lo/arp_ignore
  11. Echo "2">/proc/sys/net/ipv4/conf/lo/arp_announce
  12. Echo "1">/proc/sys/net/ipv4/conf/all/arp_ignore
  13. Echo "2">/proc/sys/net/ipv4/conf/all/arp_announce
  14. Sysctl-p>/dev/null 2> & 1
  15. Echo "RealServer Start OK"
  16. ;;
  17. Stop)
  18. Ifconfig lo: 0 down
  19. Route del $ SNS_VIP>/dev/null 2> & 1
  20. Echo "0">/proc/sys/net/ipv4/conf/lo/arp_ignore
  21. Echo "0">/proc/sys/net/ipv4/conf/lo/arp_announce
  22. Echo "0">/proc/sys/net/ipv4/conf/all/arp_ignore
  23. Echo "0">/proc/sys/net/ipv4/conf/all/arp_announce
  24. Echo "RealServer Stoped"
  25. ;;
  26. *)
  27. Echo "Usage: $0 {start | stop }"
  28. Exit 1
  29. Esac
  30. Exit 0
  31. [Root @ centos bin] # cp lvs_dr.sh/etc/rc. d/init. d/
  32. [Root @ centos bin] # service lvs_dr.sh start # start The lvs RS Server
  33. 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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.