Keepalived 双网络(内外网)故障同步漂移主备模式

Posted by Sunday on 2018-08-13

前言

在生产环境当中,内网与公网都是独立分开的,因此内网和公网不用同步漂移,例如:Keepalived+LVS-DR、Keepalived+Nginx、Keepalived+HAProxy 都无需同步漂移。

注:Keepalived+LVS-NAT模式除外。

架构图

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
    +------+              +--------+
|Client| >>> |Internet|
+------+ +--------+
/\
+-----------------------+
| 公网VIP1:172.16.20.91 |
+-----------------------+
/ \
+--------------------------+ +-------------------------+
|公网VIP:Master (eth2) |<---->|公网VIP:BACKUP (eth2) |
|公网:172.16.20.101(eth2) | |公网:172.16.20.102(eth2) |
|--------------------------|多播IP|--------------------------|
|KA+Lvs/Nginx/HAProxy | |KA+Lvs/Nginx/HAProxy |
|内网VIP:Master (eth1) | |内网VIP:BACKUP (eth1) |
|内网:192.168.10.101 (eth1)|<---->|内网:192.168.10.102 (eth1)|
+-----------------------+ +----------------------------+
\ /
+-----------------------+
|内网VIP1:192.168.10.91 |
+-----------------------+
\/
+------------+
| APP Server |
+------------+

keepalived配置

Master配置

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
global_defs {
notification_email {
root@localhost
}
notification_email_from ka@localhost
smtp_server 127.0.0.1
smtp_connect_timeout 30
router_id ka101
vrrp_mcast_group4 224.0.0.111
}

vrrp_sync_group VG_1 {
group {
Extranet_1
Intranet_1
}
}

vrrp_instance Extranet_1 {
state MASTER
interface eth0
virtual_router_id 171
priority 100
advert_int 1
authentication {
auth_type PASS
auth_pass sunday0
}
virtual_ipaddress {
172.16.20.91/16
}
notify_master "/etc/keepalived/notify.sh master"
notify_backup "/etc/keepalived/notify.sh backup"
notify_fault "/etc/keepalived/notify.sh fault"
}
vrrp_instance Intranet_1 {
state MASTER
interface eth1
virtual_router_id 191
priority 100
advert_int 1
authentication {
auth_type PASS
auth_pass sunday1
}
virtual_ipaddress {
192.168.10.91
}
notify_master "/etc/keepalived/notify.sh master"
notify_backup "/etc/keepalived/notify.sh backup"
notify_fault "/etc/keepalived/notify.sh fault"
}

Backup配置

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
global_defs {
notification_email {
root@localhost
}
notification_email_from ka@localhost
smtp_server 127.0.0.1
smtp_connect_timeout 30
router_id ka102
vrrp_mcast_group4 224.0.0.111
}

vrrp_sync_group VG_1 {
group {
Extranet_1
Intranet_1
}
}

vrrp_instance Extranet_1 {
state BACKUP
interface eth0
virtual_router_id 171
priority 100
advert_int 1
authentication {
auth_type PASS
auth_pass sunday0
}
virtual_ipaddress {
172.16.20.91/16
}
notify_master "/etc/keepalived/notify.sh master"
notify_backup "/etc/keepalived/notify.sh backup"
notify_fault "/etc/keepalived/notify.sh fault"
}
vrrp_instance Intranet_1 {
state BACKUP
interface eth1
virtual_router_id 191
priority 100
advert_int 1
authentication {
auth_type PASS
auth_pass sunday1
}
virtual_ipaddress {
192.168.10.91
}
notify_master "/etc/keepalived/notify.sh master"
notify_backup "/etc/keepalived/notify.sh backup"
notify_fault "/etc/keepalived/notify.sh fault"
}

1
2
3
4
5
6
7
Aug 13 18:31:38 node1 Keepalived_vrrp[1133]: Opening file '/etc/keepalived/keepalived.conf'.
Aug 13 18:31:38 node1 Keepalived_vrrp[1133]: Unknown keyword 'dynamic_interfaces'
Aug 13 18:31:38 node1 Keepalived_vrrp[1133]: WARNING - default user 'keepalived_script' for script execution does not exist - please create.
Aug 13 18:31:38 node1 Keepalived_vrrp[1133]: (Intranet_1): Cannot find an IP address to use for interface eth1
Aug 13 18:31:39 node1 Keepalived[1131]: Keepalived_vrrp exited with permanent error CONFIG. Terminating
解决:ifconfig eth1 172.16.20.101/16 up
eth1配置IP,因为如果接口没有IP,keepalived将以FAULT状态启动,keepalived 2.0.5以上版本,只需将dynamic_interfaces添加到global_defs即可

https://serverfault.com/questions/918642/start-keepalived-without-ip-on-interface

https://renwole.com/archives/1097