双网卡使用keepalive配置LVS的direct模式,只有一个IP生效(双线双IP)
生产环境
CentOS 6.2 2.6.32-220.7.1.el6.x86_64
eth0 : 电信IP
eth1 : 联通IP
配置文件(/etc/keepalived/keepalived.conf)如下:
global_defs {
    router_id LVS-HA-1
}
vrrp_sync_group TEL {
      group {
            TELNET
      }
}
vrrp_sync_group UNI {
      group {
            UNICOM
      }
}
vrrp_instance TELNET {
    state MASTER
    interface eth0
    mcast_src_ip 113.74.32.22
    virtual_router_id 31
    priority 200
    advert_int 1
    authentication {
        auth_type PASS
        auth_pass LVS-HA-1
    }
    virtual_ipaddress {
	113.74.32.28
    }
}
vrrp_instance UNICOM {
    state MASTER
    interface eth1
    mcast_src_ip 112.97.66.22
    virtual_router_id 32
    priority 200
    advert_int 1
    authentication {
        auth_type PASS
        auth_pass LVS-HA-2
    }
    virtual_ipaddress {
        112.97.66.28
    }
}
virtual_server 113.74.32.28 80 {
    delay_loop 6
    lb_algo wrr
    lb_kind DR
    nat_mask 255.255.255.192
    persistence_timeout 50
    protocol TCP
    real_server 113.74.32.24 80 {
        weight 1
        TCP_CHECK {
            connect_timeout 3
            nb_get_retry 3
            delay_before_retry 3
	    connect_port 80
        }
    }
    real_server 113.74.32.25 80 {
        weight 1
        TCP_CHECK {
            connect_timeout 3
            nb_get_retry 3
            delay_before_retry 3
            connect_port 80
        }
    }
}
virtual_server 112.97.66.28 80 {
    delay_loop 6
    lb_algo wrr
    lb_kind DR
    nat_mask 255.255.255.192
    persistence_timeout 50
    protocol TCP
    real_server 112.97.66.24 80 {
        weight 1
        TCP_CHECK {
            connect_timeout 3
            nb_get_retry 3
            delay_before_retry 3
            connect_port 80
        }
    }
    real_server 112.97.66.25 80 {
        weight 1
        TCP_CHECK {
            connect_timeout 3
            nb_get_retry 3
            delay_before_retry 3
            connect_port 80
        }
    }
}
结果只有电信的虚拟IP能正常访问,联通总是不通,日志里显示都是正常的。/var/log/message里的信息如下:
Apr  1 18:09:35 localhost Keepalived_vrrp: Registering Kernel netlink command channel
Apr  1 18:09:35 localhost Keepalived_healthcheckers: Registering Kernel netlink reflector
Apr  1 18:09:35 localhost Keepalived_vrrp: Registering gratutious ARP shared channel
Apr  1 18:09:35 localhost Keepalived_healthcheckers: Registering Kernel netlink command channel
Apr  1 18:09:35 localhost Keepalived_healthcheckers: Opening file '/etc/keepalived/keepalived.conf'.
Apr  1 18:09:35 localhost Keepalived_healthcheckers: Configuration is using : 20293 Bytes
Apr  1 18:09:35 localhost Keepalived_vrrp: Opening file '/etc/keepalived/keepalived.conf'.
Apr  1 18:09:35 localhost Keepalived_vrrp: Configuration is using : 70569 Bytes
Apr  1 18:09:35 localhost Keepalived_vrrp: Using LinkWatch kernel netlink reflector...
Apr  1 18:09:35 localhost Keepalived_healthcheckers: Using LinkWatch kernel netlink reflector...
Apr  1 18:09:35 localhost Keepalived_healthcheckers: Activating healtchecker for service [113.74.32.24]:80
Apr  1 18:09:35 localhost Keepalived_healthcheckers: Activating healtchecker for service [113.74.32.25]:80
Apr  1 18:09:35 localhost Keepalived_healthcheckers: Activating healtchecker for service [112.97.66.24]:80
Apr  1 18:09:35 localhost Keepalived_healthcheckers: Activating healtchecker for service [112.97.66.25]:80
Apr  1 18:09:35 localhost Keepalived_vrrp: VRRP sockpool: [ifindex(2), proto(112), fd(10,11)]
Apr  1 18:09:35 localhost Keepalived_vrrp: VRRP sockpool: [ifindex(3), proto(112), fd(12,13)]
Apr  1 18:09:36 localhost Keepalived_vrrp: VRRP_Instance(UNICOM) Transition to MASTER STATE
Apr  1 18:09:36 localhost Keepalived_vrrp: VRRP_Instance(TELNET) Transition to MASTER STATE
Apr  1 18:09:37 localhost Keepalived_vrrp: VRRP_Instance(UNICOM) Entering MASTER STATE
Apr  1 18:09:37 localhost Keepalived_vrrp: VRRP_Instance(UNICOM) setting protocol VIPs.
Apr  1 18:09:37 localhost Keepalived_vrrp: VRRP_Instance(UNICOM) Sending gratuitous ARPs on eth1 for 112.97.66.28
Apr  1 18:09:37 localhost Keepalived_vrrp: VRRP_Group(UNI) Syncing instances to MASTER state
Apr  1 18:09:37 localhost Keepalived_healthcheckers: Netlink reflector reports IP 112.97.66.28 added
Apr  1 18:09:37 localhost Keepalived_vrrp: VRRP_Instance(TELNET) Entering MASTER STATE
Apr  1 18:09:37 localhost Keepalived_vrrp: VRRP_Instance(TELNET) setting protocol VIPs.
Apr  1 18:09:37 localhost Keepalived_vrrp: VRRP_Instance(TELNET) Sending gratuitous ARPs on eth0 for 113.74.32.28
Apr  1 18:09:37 localhost Keepalived_vrrp: VRRP_Group(TEL) Syncing instances to MASTER state
Apr  1 18:09:37 localhost Keepalived_healthcheckers: Netlink reflector reports IP 113.74.32.28 added
Apr  1 18:09:42 localhost Keepalived_vrrp: VRRP_Instance(UNICOM) Sending gratuitous ARPs on eth1 for 112.97.66.28
Apr  1 18:09:42 localhost Keepalived_vrrp: VRRP_Instance(TELNET) Sending gratuitous ARPs on eth0 for 113.74.32.28
ipvsadm的显示结果:
# ipvsadm
IP Virtual Server version 1.2.1 (size=4096)
Prot LocalAddress:Port Scheduler Flags
  -> RemoteAddress:Port           Forward Weight ActiveConn InActConn
TCP  113.74.32.28:http wrr persistent 50
  -> 113.74.32.24:http            Route   1      37         106
  -> 113.74.32.25:http            Route   1      12         83
TCP  112.97.66.28:http wrr persistent 50
  -> 112.97.66.24:http           Route   1      0          0
  -> 112.97.66.25:http           Route   1      0          0  
备注:联通IP在机房内部是能正常访问的。求解……
- higkoo's blog
- Log in or register to post comments
- 7938 reads
 
      