== 背景:==
server1 172.25.254.1
server2 172.25.254.2
VIP 172.25.254.3
真机 172.25.254.38
在server1和server上源码编译nginx 并启动

在server1和server2中:
cd /usr/local/ngin/html
vi index.html
分别加入两台虚拟机的IP,以做区别。


然后分别安装keepalived

server1:
vim /etc/keepalived/keepalived.conf
! Configuration File for keepalived
global_defs {
notification_email {
root@localhost
}
notification_email_from keepalived@localhost
smtp_server 127.0.0.1
smtp_connect_timeout 30
router_id LVS_DEVEL
}
vrrp_script nginx_check {
script "/etc/keeplived/nginx_check.sh"
interval 2
weight -20
}
vrrp_instance VI_1 {
state MASTER
interface eth0
virtual_router_id 51
priority 100
advert_int 1
authentication {
auth_type PASS
auth_pass 1111
}
virtual_ipaddress {
172.25.254.3
}
}
server2:
vim /etc/keepalived/keepalived.conf
! Configuration File for keepalived
global_defs {
notification_email {
root@localhost
}
notification_email_from keepalived@localhost
smtp_server 127.0.0.1
smtp_connect_timeout 30
router_id LVS_DEVEL
}
vrrp_script nginx_check {
script "/etc/keeplived/nginx_check.sh"
interval 2
weight -20
}
vrrp_instance VI_1 {
state BACKUP
interface eth0
virtual_router_id 51
priority 50
advert_int 1
authentication {
auth_type PASS
auth_pass 1111
}
virtual_ipaddress {
172.25.254.3
}
}
server1和server2同时:
systemctl start keepalived
systemctl status keepalived
此时,由于优先级的关系,server拿到VIP,开启服务。
测试:


当serevr1的keepalived停止之后,server2自动获得vip



当重新启动serevr1的keepalived之后,因为优先级的关系,发现serevr1自动接管资源。


891

被折叠的 条评论
为什么被折叠?



