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: