Shell script: LVS simple script

Source: Internet
Author: User

Shell script: LVS simple script

After LVS is successfully installed, You can execute commands in the command line mode or customize scripts, which is convenient and scalable; the DR host can also execute vip binding and arp suppression using scripts;

DR automatically starts ipvs script:

If there are multiple VIPs, you can define arrays, and RIP as arrays. If there are multiple VIPs, you can add them;

[Root @ localhost ~] # Cat ipvs. sh
#! /Bin/bash
# Written by bkjia @ 2015-11-17
# Simple S start/stop scripts
 
./Etc/init. d/functions
 
VIP = 192.168.20.100
RIP = (
192.168.20.10
192.168.20.11
)
 
PORT = 80
IPVSADM =/sbin/ipvsadm
IFCONFIG =/sbin/ifconfig
 
Function ipvs_start (){
$ IFCONFIG eth0: 0 $ VIP/24 up
$ 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
}
 
Function ipvs_stop (){
$ IFCONFIG eth0: 0 down
$ IPVSADM-C
}
 
Case "$1" in
Start)
Ipvs_start
Action "s is started"/bin/true
;;
Stop)
Ipvs_stop
Action "s is stopped"/bin/true
;;
*)
Printf "USAGE: $0 {start | stop} \ n"
Esac

RS starts the ipvs script:

[Root @ localhost ~] # Cat lvs_rs.sh
#! /Bin/bash
# Written by bkjia @ 2015-11-17
VIP = 192.168.20.100
IFCONFIG =/sbin/ifconfig
$ IFCONFIG lo: 0 $ VIP/32 up
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

LVS + Keepalived achieves layer-4 load and high availability

LVS + Keepalived high-availability server Load balancer cluster architecture Experiment

Heartbeat + LVS build a high-availability server Load balancer Cluster

Build an LVS load balancing test environment

A stress test report for LVS

Install and deploy LVS in CentOS 7.0

This article permanently updates the link address:

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.