Centos7 中lvs DR配置

服务器主机:

  10.200.3.100       DirectServer

  10.200.3.99         RealServer1

  10.200.3.101  RealServer2

       10.200.3.200      VIP

安装配置:

DirectServer端操作:

yum install ipvsadm

配置DirectServer,创建文件 /etc/init.d/lvs_vsadm.sh, 并赋予执行权限

#!/bin/sh
 
VIP=10.200.3.200
RIP1=10.200.3.99
RIP2=10.200.3.101
/etc/rc.d/init.d/functions

case "$1" in
start)
  echo "start LVS of DirectorServer"
  #set the Virtual IP Address
   ifconfig ens160:0 $VIP/24
   #/sbin/route add -host $VIP dev ens160:0
   #Clear IPVS table
   /sbin/ipvsadm -C
  #set LVS
  /sbin/ipvsadm -A -t $VIP:80 -s rr
  /sbin/ipvsadm -a -t $VIP:80 -r $RIP1:80 -g
  /sbin/ipvsadm -a -t $VIP:80 -r $RIP2:80 -g
  #Run LVS
  /sbin/ipvsadm
  #end
;;
stop)
 echo "close LVS Directorserver"
/sbin/ipvsadm -C
;;
*)
echo "Usage: $0 {start|stop}"
exit 1
esac

启动lvsadm服务:

#/etc/init.d/lvs_vsadm.sh start
start LVS of DirectorServer
IP Virtual Server version 1.2.1 (size=4096)
Prot LocalAddress:Port Scheduler Flags
  -> RemoteAddress:Port           Forward Weight ActiveConn InActConn
TCP  Pt-gitlab:http rr
  -> 10.200.3.99:http             Route   1      0          0         
  -> 10.200.3.101:http            Route   1      0          0         

 配置RealServer,两台配置一样,新建文件 /etc/init.d/realserver.sh 并赋予执行权限

#!/bin/sh
VIP=10.200.3.200
/etc/rc.d/init.d/functions
case "$1" in
    start)
        echo "Start LVS of RealServer"
        /sbin/ifconfig lo:0 $VIP broadcast $VIP netmask 255.255.255.255 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
        ;;
    stop)
        /sbin/ifconfig lo:0 down
        echo "Stop LVS of RealServer"
        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 "Usage:$0{start|stop}"
        exit 1
esac

启动执行脚本:

# /etc/init.d/lvs_dr.sh start 

 

至此,单节点lvsadm部署完成.

 

你可能感兴趣的:(Centos7 中lvs DR配置)