Load Balancer Lvs_dr_tcp_http Single Dispatch

Source: Internet
Author: User

Prepare for three virtual, all CentOS6.5 x86_64
Note that the port consistency is maintained during the configuration process.
Director (Eth0 192.168.1.189, VIP eth0:0: 192.168.1.18) Director 78
Real Server1 (eth0 192.168.1.207, VIP lo:0:192.168.1.18) Server1 78
Real Server2 (eth0 192.168.1.208, VIP lo:0:192.168.1.18) Server2 78
1, configure the static IP, installation test httpd (two sets of realserver to do)
[email protected] ~]# Yum install-y httpd
[[email protected] ~]# echo "server1_aaa111" >/var/www/html/index.html writing data
[Email protected] ~]#/etc/init.d/httpd restart
[[email protected] ~]# Curl 192.168.1.207:78 (Modify port) Individual test results, also web-side test
server1_aaa111
[Email protected] ~]# Curl 192.168.1.208:78
server2_bbb222
2. Ipvsadm Installation and testing (director)
[email protected] ~]# Yum list |grep Ipvsadm
Ipvsadm.x86_64 1.26-4.el6
[email protected] ~]# Yum install-y ipvsadm
[[email protected] ~]# ipvsadm load Ipvsadm, you can also use Modprobe Ip_vs
IP Virtual Server version 1.2.1 (size=4096)
Prot Localaddress:port Scheduler Flags
Remoteaddress:port Forward Weight activeconn inactconn
[[email protected] ~]# lsmod |grep ip_vs View kernel module, the output means Ipvsadm has been loaded into the kernel, the LVS installation is complete
3, Dr New configuration file/usr/local/sbin/lvs_dr.sh
[[email protected] ~]# vim/usr/local/sbin/lvs_dr.sh detailed configuration See accessories
/sbin/ifconfig eth0:0 $VIP broadcast $VIP netmask 255.255.255.255 up new eth0:0 virtual network card
/sbin/ipvsadm-a-T $VIP: 78-s RR RR Polling method
/sbin/ipvsadm-a-T $VIP: 78-r $RIP 1:78-g g represents Dr Mode
[Email protected] ~]# sh/usr/local/sbin/lvs_dr.sh
[Email protected] ~]# ipvsadm-l

4. RS configuration file/usr/local/sbin/lvs.sh

The following configurations are required on both Rs.
New profile:/usr/local/sbin/lvs.sh, use Lo port for virtual IP configuration, and add routes to specify specific network exits
[Email protected] ~]# vim/usr/local/sbin/lvs.sh


[Email protected] ~]# sh/usr/local/sbin/lvs_rs.sh
View, one more lo:0 port and IP address.
5. Test results
The back end is tested with curl and three are displayed normally.


Attention
Web-side test: http://192.168.1.18:78/
Virtual IP Test Results: Note that the address has a cache, to try a few more times, can be implemented without a refresh switch once.
6, after the shutdown restart, to execute the script again, shut down the firewall.
A, check each IP address
b, check the firewall
C. Check if the director is loaded
7. Accessories
[Email protected] sbin]# cat/usr/local/sbin/lvs_dr.sh
#!/bin/sh
# Description:start LVS of Director server
vip=192.168.1.18
rip1=192.168.1.207
rip2=192.168.1.208
Source/etc/rc.d/init.d/functions
Case "$" in
Start
echo "Start LVS of Director Server"
# Set the Virtual IP Address and sysctl parameter
/sbin/ifconfig eth0:0 $VIP broadcast $VIP netmask 255.255.255.255 up
echo "1" >/proc/sys/net/ipv4/ip_forward
#Clear IPVS Table
/sbin/ipvsadm-c
#set LVS
/sbin/ipvsadm-a-T $VIP: 78-s RR
/sbin/ipvsadm-a-T $VIP: 78-r $RIP 1:78-g
/sbin/ipvsadm-a-T $VIP: 78-r $RIP 2:78-g
#Run LVS
/sbin/ipvsadm
;;
Stop
echo "Close LVS directorserver"
echo "0" >/proc/sys/net/ipv4/ip_forward
/sbin/ipvsadm-c
/sbin/ifconfig eth0:0 Down
;;
*)
echo "Usage: $ {start|stop}"
Exit 1
Esac
-------------------------------------------------------------
[Email protected] ~]# cat/usr/local/sbin/lvs.sh
#!/bin/bash
#description: Realserver ' s script
vip=192.168.1.18
Source/etc/rc.d/init.d/functions
Case "$" in
Start
Ifconfig lo:0 $VIP netmask 255.255.255.255 broadcast $VIP
/sbin/route add-host $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
echo "Realserver Start OK"
;;
Stop
Ifconfig lo:0 Down
Route del $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: $ {start|stop}"
Exit 1
Esac

Load Balancer Lvs_dr_tcp_http Single Dispatch

Related Article

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.