iojsioi 发表于 2018-12-31 06:07:09

keepalived配置基于lvs DR模型的HA

  
基本架构图如下:
http://s4.运维网.com/wyfs02/M01/77/24/wKioL1ZkB2HxXxwCAAEk-GGAgoU809.jpg
平台环境:centos6.x
1.    安装keepalived、安装ipvsadm
yum –y install keepalivedipvsadm
2.    配置服务
2.1 lvs realserver 配置脚本
#!/bin/bash
VIP1=192.168.1.199
case "$1" in
start)
echo " start LVS of REALServer"
/sbin/ifconfig lo:0 $VIP1 broadcast $VIP1 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 "close LVS Directorserver"
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
2.2 keepalived master 配置文件
! Configuration File for keepalived
global_defs {
   notification_email {
   root@localhost
   }
   notification_email_from keepalived@localhost
   smtp_server 127.0.0.1
   smtp_connect_timeout 30
   router_id LVS_DEVEL
}
vrrp_instance VI_1 {
    state MASTER
    interface eth0
    virtual_router_id 52
    priority 100
    advert_int 1
    authentication {
      auth_type PASS
      auth_pass 1111
    }
    virtual_ipaddress {
   192.168.1.199
    }
    notify_master "/etc/keepalived/notify.sh master"
    notify_backup "/etc/keepalived/notify.sh backup"
    notify_fault "/etc/keepalived/notify.sh fault"
}
virtual_server 192.168.1.199 80 {
    delay_loop 6
    lb_algo rr
    lb_kind DR
    nat_mask 255.255.255.0
    persistence_timeout 50
    protocol TCP
    real_server 192.168.1.204 80 {
         weight 1
         HTTP_GET {
            url {
            path http://192.168.1.204/index.html
            status_code 200
            }
            connect_timeout 3
            nb_get_retry 3
            delay_before_retry 3
         }
       }
   real_server 192.168.1.205 80 {
         weight 1
         HTTP_GET {
            url {
            path http://192.168.1.205/index.html
            status_code 200
            }
            connect_timeout 3
            nb_get_retry 3
            delay_before_retry 3
      }
    }
}
2.3keepalived backup配置文件
! Configuration File for keepalived
global_defs {
   notification_email {
      root@localhost
   }
   notification_email_from keepalived@localhost
   smtp_server 127.0.0.1
   smtp_connect_timeout 30
   router_id LVS_DEVEL
}
vrrp_instance VI_1 {
    state BACKUP
    interface eth0
    virtual_router_id 52
    priority 99
    advert_int 1
    authentication {
      auth_type PASS
      auth_pass 1111
    }
    virtual_ipaddress {
   192.168.1.199
    }
    notify_master "/etc/keepalived/notify.sh master"
    notify_backup "/etc/keepalived/notify.sh backup"
    notify_fault "/etc/keepalived/notify.sh fault"
}
virtual_server 192.168.1.199 80 {
    delay_loop 6
    lb_algo rr
    lb_kind DR
    nat_mask 255.255.255.0
    persistence_timeout 50
    protocol TCP
    real_server 192.168.1.204 80 {
         weight 1
         HTTP_GET {
            url {
            path http://192.168.1.204/index.html
            status_code 200
            }
            connect_timeout 3
            nb_get_retry 3
            delay_before_retry 3
         }
      }
       real_server 192.168.1.205 80 {
         weight 1
         HTTP_GET {
            url {
            path http://192.168.1.205/index.html
            status_code 200
            }
            connect_timeout 3
            nb_get_retry 3
            delay_before_retry 3
      }
    }
}

  

  3.测试
   启动服务,在master上查看ipvs规则生效状况
   http://s3.运维网.com/wyfs02/M02/77/24/wKioL1ZkCCPQ-O0oAAA8DylHHEQ106.png

   maill命令查看邮件
   http://s1.运维网.com/wyfs02/M00/77/26/wKiom1ZkB_WRdpVvAABzuddlizE646.png


down掉master查看backup是否能成功接管


查看状态是否转换   
http://s1.运维网.com/wyfs02/M01/77/25/wKioL1ZkCMKTj8N7AABSX_RoIR4544.png
  查看ipvs规则是否生效

http://s5.运维网.com/wyfs02/M02/77/26/wKiom1ZkCFWS41OMAAA8DylHHEQ573.png
  查看vip是否转移

http://s2.运维网.com/wyfs02/M00/77/25/wKioL1ZkCMOyTuj3AABgqbSuC6c088.png










  




页: [1]
查看完整版本: keepalived配置基于lvs DR模型的HA