hmzone 发表于 2018-12-29 09:13:37

keepalived 双网卡服务器双机热备

  环境准备
  test1
  eth0:18.1.30.58eth1:192.168.87.200

  test2
  eth0:18.1.30.59eth1:192.168.87.180
  

  VIP
  18.1.30.30            192.168.87.87

  

  test1keepalived的配置

  vrrp_sync_group VGM {
       group {
          VI_HA
             }
}
vrrp_instance VI_HA {
    state MASTER
    interface eth0
    virtual_router_id 51
    priority100
    advert_int 1
    authentication {
      auth_type PASS
      auth_pass 1111
    }
track_interface {
       eth0
       eth1
   }
    virtual_ipaddress {
      18.1.30.30/24 dev eth0
      192.168.87.87/24 dev eth1
    }
}
  

  test2keepalived的配置
  vrrp_sync_group VGM {
       group {
          VI_HA
             }
}
vrrp_instance VI_HA {
    state BACKUP
    interface eth0
    virtual_router_id 51
    priority99
    advert_int 1
    authentication {
      auth_type PASS
      auth_pass 1111
    }
track_interface {
       eth0
       eth1
   }
    virtual_ipaddress {
      18.1.30.30/24 dev eth0
      192.168.87.87/24 dev eth1
    }
}
  

  测试
  http://blog.运维网.com/attachment/201306/155750343.jpg

  

  # ifdown eth0
  

http://blog.运维网.com/attachment/201306/155901547.jpg
  

  

  

  双网卡双vrrp实例
  如果keepalived有两个网段,每个网段开启一个vrrp实例,当外网出现故障的话,keepalived任然认为自己很健康,所以就进行master和backup的切换,这样会导致外网不可用
解决方法是把两个实例放进一个sync group中

  test2keepalived的配置
  global_defs {
   router_idHAWEB
}
vrrp_sync_group VGM {
       group {
          VI_HA_1
          VI_HA_1
             }
}
vrrp_instance VI_HA_1 {
    state BACKUP
    interface eth0
    virtual_router_id 51
    priority99
    advert_int 1
    authentication {
      auth_type PASS
      auth_pass 1111
    }
    track_interface {
       eth0
       eth1
   }
    virtual_ipaddress {
      18.1.30.30/24 dev eth0
    }
}

  vrrp_instance VI_HA_2 {
    state BACKUP
    interface eth1
    virtual_router_id 51
    priority99
    advert_int 1
    authentication {
      auth_type PASS
      auth_pass 1111
    }
    track_interface {
       eth0
       eth1
   }
    virtual_ipaddress {
      192.168.87.87/24 dev eth1
    }
}

test1keepalived的配置
  global_defs {
   router_idHAWEB
}
vrrp_sync_group VGM {
       group {
          VI_HA_1
          VI_HA_1
             }
}
vrrp_instance VI_HA_1 {
    state MASTER
    interface eth0
    virtual_router_id 51
    priority100
    advert_int 1
    authentication {
      auth_type PASS
      auth_pass 1111
    }
    track_interface {
       eth0
       eth1
   }
    virtual_ipaddress {
      18.1.30.30/24 dev eth0
    }
}

vrrp_instance VI_HA_2 {
    state BACKUP
    interface eth1
    virtual_router_id 51
    priority100
    advert_int 1
    authentication {
      auth_type PASS
      auth_pass 1111
    }
    track_interface {
       eth0
       eth1
   }
    virtual_ipaddress {
      192.168.87.87/24 dev eth1
    }
}
  

  测试
  http://blog.运维网.com/attachment/201306/155750343.jpg

  # ifdown eth0
  

http://blog.运维网.com/attachment/201306/155901547.jpg
  

  

  

  




页: [1]
查看完整版本: keepalived 双网卡服务器双机热备