1.yum -y install keepalived
2.vi /etc/keepalived/keepalived.conf
vrrp_instance VI_1 {
state MASTER #从为BACKUP
interface eth0
virtual_router_id 51
priority 100 #MASTER 优先级高
advert_int 1
authentication {
auth_type PASS
auth_pass 1111
}
virtual_ipaddress {
192.168.2.199 #VIP
}
}
3.service keepalived start
4.ip addr show
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 08:00:27:c7:ec:ad brd ff:ff:ff:ff:ff:ff
inet 192.168.2.235/24 brd 192.168.2.255 scope global eth0
inet 192.168.2.199/32 scope global eth0
inet6 fe80::a00:27ff:fec7:ecad/64 scope link
valid_lft forever preferred_lft forever
5.nginx常规配置
6.测试
来源:oschina
链接:https://my.oschina.net/u/1436089/blog/780258