/ipvs scheduling algorithm for LVS load Balancing implementation mechanism

Source: Internet
Author: User

Eight kinds of scheduling algorithms:
: rr|wrr|lc|wlc|lblc|dh|sh|
Wheel call scheduling (Round-robin scheduling)
Weighted wheel call scheduling (weighted Round-robin scheduling)
Minimum connection scheduling (Least-connection scheduling)
Weighted minimum connection scheduling (weighted least-connection scheduling)
Minimal links based on locality (locality-based least connections scheduling)
Local least-link with replication (locality-based least connections with Replication scheduling)
Target Address hash dispatch (destination hashing scheduling)
Source Address hash dispatch (hashing scheduling)

Three kinds of equilibrium mechanisms:

IP load Balancing technology is the most efficient in the implementation of the load scheduler.

The three mechanisms were:

Virtual server via network address translation (Vs/nat): There is also a port map that aims to make a group of servers a high-performance, highly available virtual server. Because this technology is easy to form a single point of failure, which makes the network inaccessible, and there are bandwidth bottlenecks. So LVS provides the following two kinds of implementations.

Virtual Server via IP tunneling (vs/tun): Virtualization services are implemented via IP tunneling.

Virtual server via direct Routing (VS/DR): A way to implement virtual servers directly (with the highest load capacity), this article builds DR mode.

Lvs

When using keepalived to do LVS, the real server (real-server) needs to write a script for ipvsadm alone, Windows needs to loop back to the network interface, and when Ipvsadm is enabled and working, Keepalived will take over control Ipvsadm.

Script:

The code is as follows Copy Code
#!/bin/bash
vip=192.168.2.130
/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
Sysctl-p >/dev/null 2>&1
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

Exit 0

Ipvsadm

Ipvsadm-l

Ipvsadm-ln

Ipvsadm-lnc

Vrrp_script Configuration

The code is as follows Copy Code

Vrrp_script Chk_sshd {
Script "killall-0 sshd" # cheaper than pidof
Interval 2 # Check every 2 seconds
Weight-4 # Default Prio:-4 if KO

# weight-40 # if failed, decrease of the priority
Fall 1 # require 2 failures for failures
Rise 1 # require 1 sucesses for OK
}

Vrrp_script Chk_haproxy {
Script "killall-0 haproxy" # cheaper than pidof
Interval 2 # Check every 2 seconds
}

Vrrp_script Chk_http_port {
#script "/TCP/127.0.0.1/80" # Connects and exits

#script "Nc-z 127.0.0.1" # Connects and exits

Script "</TCP/127.0.0.1/80" # Connects and exits
Interval 1 # Check every second
Weight-2 # Default Prio:-2 if Connect fails
}

Vrrp_script Chk_https_port {
Script "/tcp/127.0.0.1/443"
Interval 1
Weight-2
}

Vrrp_script Chk_smtp_port {
Script "/TCP/127.0.0.1/25"
Interval 1
Weight-2
}

Vrrp_instance Vi_1 {
Interface eth0
State MASTER
VIRTUAL_ROUTER_ID 51
Priority 100

virtual_ipaddress {
192.168.200.18/25
}

Track_interface {
eth1 Weight 2 # prio = +2 if up
Eth2 weight-2 # prio =-2 if down
Eth3 # no weight, fault if down
}

Track_script {
CHK_SSHD # Use default weight the script
Chk_haproxy Weight 2 # +2 If process is present
Chk_http_port
Chk_https_port
Chk_smtp_port
}
}

Vrrp_instance Vi_2 {
Interface eth1
State MASTER
VIRTUAL_ROUTER_ID 52
Priority 100

virtual_ipaddress {
192.168.201.18/26
}

Track_interface {
Eth0 Weight 2 # prio = +2 if up
Eth2 weight-2 # prio =-2 if down
Eth3 # no weight, fault if down
}

Track_script {
Chk_haproxy Weight 2
Chk_http_port
Chk_https_port
Chk_smtp_port
}
}

One example configuration:

The code is as follows Copy Code

! Configuration File for Keepalived

Global_defs {
Notification_email {
notify@aooshi.org
}
Notification_email_from servername@aooshi.org
Smtp_server 192.168.2.111
Smtp_connect_timeout 30
router_id webcache253-keepalived
}

Vrrp_script Check_http {
Script "</DEV/TCP/127.0.0.1/80"
Interval 5
Weight-10
}

Vrrp_instance vi_158 {
    State BACKUP
    interface eth0
  & nbsp VIRTUAL_ROUTER_ID
    Priority
    advert_int 1
    SMTP _alert
    Authentication {
        Auth_type pass
        auth_pass webcache
   }
    virtual_ipaddress {
        192.168.2.158 brd 192.168.2.255 label eth0:158
   }
 track_script {
  check_http
 
}

Vrrp_instance vi_159 {
    State MASTER
    interface eth0
  & nbsp VIRTUAL_ROUTER_ID
    Priority
    advert_int 1
    Smtp_alert
    Authentication {
        Auth_type pass
        auth_pass webcache
   }
    virtual_ipaddress {
        192.168.2.159 brd 192.168.2.255 label eth0:159
   }
 track_script {
  check_http
 
}

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.