LVS配置

1 keepalived配置文件





! Configuration File for keepalived


global_defs {

#   notification_email {

#     [email protected]

#     [email protected]

#     [email protected]

#   }

#   notification_email_from [email protected]

#   smtp_server 192.168.200.1

#   smtp_connect_timeout 30

    router_id mobee

}

                              ***部分是主从之间的3个区别

vrrp_instance VI_2 {                    

    state BACKUP 

    interface bond0 

    virtual_router_id 70

    priority 100

    advert_int 1

    authentication {

        auth_type PASS

        auth_pass 1111

    }

    virtual_ipaddress {

       X.X.X.X           VIP的iP地址

    }

}


virtual_server x.x.x.x 80 {

    delay_loop 6

    lb_algo wrr

    lb_kind DR

    persistence_timeout 2400

    protocol TCP


    real_server Y.Y.Y.Y 80 {         后端web1的ip地址

        weight 10

        TCP_CHECK {

            connect_port 80

            connect_timeout 10

        }

    }


    real_server Z.Z.Z.Z 80 {        后端web2的ip地址    

        weight 10

        TCP_CHECK {

            connect_port 80

            connect_timeout 10

        }

    }

}


virtual_server X.X.X.X 443 {

    delay_loop 6

    lb_algo wrr

    lb_kind DR

    persistence_timeout 2400

    protocol TCP


    real_server Y.Y.Y.Y 443 {

        weight 10

        TCP_CHECK {

            connect_port 443

            connect_timeout 10

        }

    }


    real_server Z.Z.Z.Z 443 {

        weight 10

        TCP_CHECK {

            connect_port 443

            connect_timeout 10

        }

    }

}



2后端WEB服务器需要执行的IP脚本


#!/bin/bash

VIP=X.X.X.X


case $1 in

start)

  /sbin/ifconfig lo:0 $VIP broadcast $VIP netmask 255.255.255.255 up   

  /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 

  ;;

stop)

  /sbin/route del -host $VIP dev lo:0

  /sbin/ifconfig lo:0 down

  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


你可能感兴趣的:(LVS,keepalived)