基本环境
MASTER机,10.0.0.9
BACKUP机,10.0.0.10
1,安装
2,配置(低版本貌似才需要这个配置)
3,MASTER配置keepalived.conf,避免立即将vip还回去配置双BACKUP
4,BACKUP配置keepalived.conf
5,启动
[code="java"]
# keepalived
[/code]
由于/etc/rc.d/init.d/keepalived start报错,故采用如此启动
6,MASTER机验证网络信息
[code="java"]
# ip a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 16436 qdisc noqueue state UNKNOWN
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
link/ether 00:50:56:20:3d:2a brd ff:ff:ff:ff:ff:ff
inet 10.0.0.9/24 brd 10.0.0.255 scope global eth0
inet 10.0.0.100/32 scope global eth0
inet 10.0.0.101/32 scope global eth0
inet6 fe80::250:56ff:fe20:3d2a/64 scope link
valid_lft forever preferred_lft forever
3: eth1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
link/ether 00:50:56:34:80:48 brd ff:ff:ff:ff:ff:ff
inet 192.168.0.9/16 brd 192.168.0.255 scope global eth1
inet 192.168.0.100/32 scope global eth1
inet 192.168.0.101/32 scope global eth1
inet6 fe80::250:56ff:fe34:8048/64 scope link
valid_lft forever preferred_lft forever
[/code]
7,停MASTER机keepalived服务,验证BACKUP机网络
[code="java"]
# /etc/rc.d/init.d/keepalived stop
Stopping keepalived: [ OK ]
[/code]
[code="java"]
# ip a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 16436 qdisc noqueue state UNKNOWN
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
link/ether 00:50:56:2e:2b:6d brd ff:ff:ff:ff:ff:ff
inet 10.0.0.10/24 brd 10.0.0.255 scope global eth0
inet 10.0.0.100/32 scope global eth0
inet 10.0.0.101/32 scope global eth0
inet6 fe80::250:56ff:fe2e:2b6d/64 scope link
valid_lft forever preferred_lft forever
3: eth1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
link/ether 00:50:56:3b:e8:e2 brd ff:ff:ff:ff:ff:ff
inet 192.168.0.10/16 brd 192.168.0.255 scope global eth1
inet 192.168.0.100/32 scope global eth1
inet 192.168.0.101/32 scope global eth1
inet6 fe80::250:56ff:fe3b:e8e2/64 scope link
valid_lft forever preferred_lft forever
[/code]
8,更新后的配置
[code="java"]
# cat /etc/keepalived/keepalived.conf
global_defs {
notification_email {
jie.zhang@ttpod.com
}
notification_email_from keepalived@ttpod.com
smtp_server 127.0.0.1
stmp_connect_timeout 30
router_id keepalived_for_backup
}
vrrp_script check_top {
script "/root/bin/check_top"
interval 10
weight 10
}
vrrp_instance VI_1 {
state BACKUP
interface eth0
virtual_router_id 11
priority 10
advert_int 1
nopreempt
authentication {
auth_type PASS
auth_pass 1111
}
virtual_ipaddress {
10.0.0.100/24 dev eth0 label eth0:0
10.0.0.101/24 dev eth0 label eth0:1
}
track_script {
check_top weight 20
}
}
vrrp_instance VI_2 {
state BACKUP
interface eth1
virtual_router_id 21
priority 10
advert_int 1
nopreempt
authentication {
auth_type PASS
auth_pass 1111
}
virtual_ipaddress {
192.168.0.100/16 dev eth1 label eth1:0
192.168.0.101/16 dev eth1 label eth1:1
}
track_script {
check_top
}
}
[/code]
9,查看网络信息
ip a
[code="java"]
# ip a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 16436 qdisc noqueue state UNKNOWN
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
link/ether 00:50:56:20:3d:2a brd ff:ff:ff:ff:ff:ff
inet 10.0.0.9/24 brd 10.0.0.255 scope global eth0
inet 10.0.0.100/24 scope global eth0:0
inet 10.0.0.101/24 scope global eth0:1
inet6 fe80::250:56ff:fe20:3d2a/64 scope link
valid_lft forever preferred_lft forever
3: eth1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
link/ether 00:50:56:34:80:48 brd ff:ff:ff:ff:ff:ff
inet 192.168.0.9/16 brd 192.168.0.255 scope global eth1
inet 192.168.0.100/16 scope global eth1:0
inet 192.168.0.101/16 scope global eth1:1
inet6 fe80::250:56ff:fe34:8048/64 scope link
valid_lft forever preferred_lft forever
[/code]
ifconfig
[code="java"]
# ifconfig
eth0 Link encap:Ethernet HWaddr 00:50:56:20:3D:2A
inet addr:10.0.0.9 Bcast:10.0.0.255 Mask:255.255.255.0
inet6 addr: fe80::250:56ff:fe20:3d2a/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:1206 errors:0 dropped:0 overruns:0 frame:0
TX packets:1282 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:125352 (122.4 KiB) TX bytes:148912 (145.4 KiB)
eth0:0 Link encap:Ethernet HWaddr 00:50:56:20:3D:2A
inet addr:10.0.0.100 Bcast:0.0.0.0 Mask:255.255.255.255
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
eth0:1 Link encap:Ethernet HWaddr 00:50:56:20:3D:2A
inet addr:10.0.0.101 Bcast:0.0.0.0 Mask:255.255.255.255
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
eth1 Link encap:Ethernet HWaddr 00:50:56:34:80:48
inet addr:192.168.0.9 Bcast:192.168.0.255 Mask:255.255.0.0
inet6 addr: fe80::250:56ff:fe34:8048/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:349754 errors:0 dropped:0 overruns:0 frame:0
TX packets:476 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:21502934 (20.5 MiB) TX bytes:32269 (31.5 KiB)
eth1:0 Link encap:Ethernet HWaddr 00:50:56:34:80:48
inet addr:192.168.0.100 Bcast:0.0.0.0 Mask:255.255.255.255
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
eth1:1 Link encap:Ethernet HWaddr 00:50:56:34:80:48
inet addr:192.168.0.101 Bcast:0.0.0.0 Mask:255.255.255.255
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
inet6 addr: ::1/128 Scope:Host
UP LOOPBACK RUNNING MTU:16436 Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:0 (0.0 b) TX bytes:0 (0.0 b)
[/code]
MASTER机,10.0.0.9
BACKUP机,10.0.0.10
1,安装
wget http://www.keepalived.org/software/keepalived-1.2.7.tar.gz
tar xvzf keepalived-1.2.7.tar.gz
cd keepalived-1.2.7
./configure
make
make install
2,配置(低版本貌似才需要这个配置)
cp /usr/local/etc/rc.d/init.d/keepalived /etc/rc.d/init.d/
cp /usr/local/etc/sysconfig/keepalived /etc/sysconfig/
mkdir /etc/keepalived
cp /usr/local/sbin/keepalived /usr/sbin/
vi /etc/keepalived/keepalived.conf
3,MASTER配置keepalived.conf,避免立即将vip还回去配置双BACKUP
vrrp_instance VI_1 {
state BACKUP
interface eth0
virtual_router_id 11
priority 100
advert_int 1
authentication {
auth_type PASS
auth_pass 1111
}
virtual_ipaddress {
10.0.0.100
10.0.0.101
}
}
vrrp_instance VI_2 {
state BACKUP
interface eth1
virtual_router_id 21
priority 100
advert_int 1
authentication {
auth_type PASS
auth_pass 1111
}
virtual_ipaddress {
192.168.0.100
192.168.0.101
}
}
4,BACKUP配置keepalived.conf
vrrp_instance VI_1 {
state BACKUP
interface eth0
virtual_router_id 11
priority 10
advert_int 1
authentication {
auth_type PASS
auth_pass 1111
}
virtual_ipaddress {
10.0.0.100
10.0.0.101
}
}
vrrp_instance VI_2 {
state BACKUP
interface eth1
virtual_router_id 21
priority 10
advert_int 1
authentication {
auth_type PASS
auth_pass 1111
}
virtual_ipaddress {
192.168.0.100
192.168.0.101
}
}
5,启动
[code="java"]
# keepalived
[/code]
由于/etc/rc.d/init.d/keepalived start报错,故采用如此启动
6,MASTER机验证网络信息
[code="java"]
# ip a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 16436 qdisc noqueue state UNKNOWN
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
link/ether 00:50:56:20:3d:2a brd ff:ff:ff:ff:ff:ff
inet 10.0.0.9/24 brd 10.0.0.255 scope global eth0
inet 10.0.0.100/32 scope global eth0
inet 10.0.0.101/32 scope global eth0
inet6 fe80::250:56ff:fe20:3d2a/64 scope link
valid_lft forever preferred_lft forever
3: eth1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
link/ether 00:50:56:34:80:48 brd ff:ff:ff:ff:ff:ff
inet 192.168.0.9/16 brd 192.168.0.255 scope global eth1
inet 192.168.0.100/32 scope global eth1
inet 192.168.0.101/32 scope global eth1
inet6 fe80::250:56ff:fe34:8048/64 scope link
valid_lft forever preferred_lft forever
[/code]
7,停MASTER机keepalived服务,验证BACKUP机网络
[code="java"]
# /etc/rc.d/init.d/keepalived stop
Stopping keepalived: [ OK ]
[/code]
[code="java"]
# ip a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 16436 qdisc noqueue state UNKNOWN
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
link/ether 00:50:56:2e:2b:6d brd ff:ff:ff:ff:ff:ff
inet 10.0.0.10/24 brd 10.0.0.255 scope global eth0
inet 10.0.0.100/32 scope global eth0
inet 10.0.0.101/32 scope global eth0
inet6 fe80::250:56ff:fe2e:2b6d/64 scope link
valid_lft forever preferred_lft forever
3: eth1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
link/ether 00:50:56:3b:e8:e2 brd ff:ff:ff:ff:ff:ff
inet 192.168.0.10/16 brd 192.168.0.255 scope global eth1
inet 192.168.0.100/32 scope global eth1
inet 192.168.0.101/32 scope global eth1
inet6 fe80::250:56ff:fe3b:e8e2/64 scope link
valid_lft forever preferred_lft forever
[/code]
8,更新后的配置
[code="java"]
# cat /etc/keepalived/keepalived.conf
global_defs {
notification_email {
jie.zhang@ttpod.com
}
notification_email_from keepalived@ttpod.com
smtp_server 127.0.0.1
stmp_connect_timeout 30
router_id keepalived_for_backup
}
vrrp_script check_top {
script "/root/bin/check_top"
interval 10
weight 10
}
vrrp_instance VI_1 {
state BACKUP
interface eth0
virtual_router_id 11
priority 10
advert_int 1
nopreempt
authentication {
auth_type PASS
auth_pass 1111
}
virtual_ipaddress {
10.0.0.100/24 dev eth0 label eth0:0
10.0.0.101/24 dev eth0 label eth0:1
}
track_script {
check_top weight 20
}
}
vrrp_instance VI_2 {
state BACKUP
interface eth1
virtual_router_id 21
priority 10
advert_int 1
nopreempt
authentication {
auth_type PASS
auth_pass 1111
}
virtual_ipaddress {
192.168.0.100/16 dev eth1 label eth1:0
192.168.0.101/16 dev eth1 label eth1:1
}
track_script {
check_top
}
}
[/code]
9,查看网络信息
ip a
[code="java"]
# ip a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 16436 qdisc noqueue state UNKNOWN
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
link/ether 00:50:56:20:3d:2a brd ff:ff:ff:ff:ff:ff
inet 10.0.0.9/24 brd 10.0.0.255 scope global eth0
inet 10.0.0.100/24 scope global eth0:0
inet 10.0.0.101/24 scope global eth0:1
inet6 fe80::250:56ff:fe20:3d2a/64 scope link
valid_lft forever preferred_lft forever
3: eth1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
link/ether 00:50:56:34:80:48 brd ff:ff:ff:ff:ff:ff
inet 192.168.0.9/16 brd 192.168.0.255 scope global eth1
inet 192.168.0.100/16 scope global eth1:0
inet 192.168.0.101/16 scope global eth1:1
inet6 fe80::250:56ff:fe34:8048/64 scope link
valid_lft forever preferred_lft forever
[/code]
ifconfig
[code="java"]
# ifconfig
eth0 Link encap:Ethernet HWaddr 00:50:56:20:3D:2A
inet addr:10.0.0.9 Bcast:10.0.0.255 Mask:255.255.255.0
inet6 addr: fe80::250:56ff:fe20:3d2a/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:1206 errors:0 dropped:0 overruns:0 frame:0
TX packets:1282 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:125352 (122.4 KiB) TX bytes:148912 (145.4 KiB)
eth0:0 Link encap:Ethernet HWaddr 00:50:56:20:3D:2A
inet addr:10.0.0.100 Bcast:0.0.0.0 Mask:255.255.255.255
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
eth0:1 Link encap:Ethernet HWaddr 00:50:56:20:3D:2A
inet addr:10.0.0.101 Bcast:0.0.0.0 Mask:255.255.255.255
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
eth1 Link encap:Ethernet HWaddr 00:50:56:34:80:48
inet addr:192.168.0.9 Bcast:192.168.0.255 Mask:255.255.0.0
inet6 addr: fe80::250:56ff:fe34:8048/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:349754 errors:0 dropped:0 overruns:0 frame:0
TX packets:476 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:21502934 (20.5 MiB) TX bytes:32269 (31.5 KiB)
eth1:0 Link encap:Ethernet HWaddr 00:50:56:34:80:48
inet addr:192.168.0.100 Bcast:0.0.0.0 Mask:255.255.255.255
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
eth1:1 Link encap:Ethernet HWaddr 00:50:56:34:80:48
inet addr:192.168.0.101 Bcast:0.0.0.0 Mask:255.255.255.255
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
inet6 addr: ::1/128 Scope:Host
UP LOOPBACK RUNNING MTU:16436 Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:0 (0.0 b) TX bytes:0 (0.0 b)
[/code]