LVS-DR cluster build script

1. script structure

 

A script for installing and configuring the scheduler, configured in two scripts real server, they are in the same directory

as the picture shows

 

 

2. Preparation premise

The scheduler can avoid dense landing two real servers

Confirm name of the NIC, VIP, RIP, port, and scheduling method, according to the values ​​of these parameters are the specific operation, the variable is adjusted to modify the script

 

3. script content

The scheduler installation and configuration script install_lvs_dr.sh

 

#! / bin / the bash 

# IP, port, weight, LVS mode and scheduling method provided 
the VIP = 192.168 . 113.15 
RIPl = 192.168 . 113.100 
of RIP2 = 192.168 . 113.200 
PORT = 80 
WEIGHTS = ( ' . 1 '  ' 2 ' ) 
IPVSTYPE = ' -g ' 
sCHEDULER = WRR 

# card name and content 
netname of = ens33 
# scheduler provided the VIP 
IF [-f / etc / sysconfig / Network-scripts / in ifcfg- netname of $!]; the then 
    echo " Card does not exist! " 
    Exit . 1 
Fi 
(CD / etc / sysconfig / Network-scripts / && CP in ifcfg- $ ,: netname of { 0 } &&   echo  " the TYPE = Ethernet 
BOOTPROTO = none 
NAME = $ netname of: 0 
the DEVICE = $ netname of : 0 
ONBOOT = yes 
IPADDR = $ VIP 
PREFIX = 24- " > ifcfg- $ netname: 0) 
systemctl restart Network 

# configure the real server 
IF [-f ./conf_rip1!. SH || [-f ./conf_rip2]!. SH ];the then 
    echo  " ! no script real server configuration " 
    Exit 2 
fi 
SSH -o StrictHostKeyChecking = NO root @ $ RIP1 ' bash -s ' <./conf_rip. SH $ VIP
 IF [$ -ne? 0 ]; the then 
    echo  " real ! server configuration error " 
    Exit 3 
fi 
SSH -o StrictHostKeyChecking = NO root @ $ RIP2 ' bash -s ' <./conf_rip. SH $ VIP
 IF [$ -ne? 0 ]; the then 
    echo  " real server configuration error! "
    exit 3
fi

#部署服务
if ! hash ipvsadm 2> /dev/null ; then
    yum -y install ipvsadm
fi
ipvsadm -C
ipvsadm -A -t $VIP:$PORT -s $SCHEDULER
ipvsadm -a -t $VIP:$PORT -r $RIP1 -w ${WEIGHTS} $IPVSTYPE
ipvsadm -a -t $VIP:$PORT -r $RIP2 -w ${WEIGHTS[1]} $IPVSTYPE

 

Real server configuration script conf_rip.sh

#!/bin/bash

#配置vip地址
(cd /etc/sysconfig/network-scripts/ && cp ifcfg-lo{,:0} && echo "DEVICE=lo:0
IPADDR=$1
NETMASK=255.255.255.255
NETWORK=$1
BROADCAST=$1
ONBOOT=yes
NAME=lo:0" > ifcfg-lo:0)
systemctl restart network

#修改arp内核参数
echo 'net.ipv4.conf.all.arp_ignore = 1
net.ipv4.conf.lo.arp_ignore = 1
net.ipv4.conf.all.arp_announce = 2
net.ipv4.conf.lo.arp_announce = 2' >> /etc/sysctl.conf
sysctl -p

 

Guess you like

Origin www.cnblogs.com/luoposhanchenpingan/p/11413580.html