keepalived配置 global_defs { router_id master-1}vrrp_instance VI_1 { state MASTER interface bond0 virtual_router_id 50 priority 100 advert_int 1 authentication { auth_type PASS auth_pass 1111 } virtual_ipaddress { 10.30.92.243 }} 主vip节点
keepalived配置
global_defs {
router_id master-1
}
vrrp_instance VI_1 {
state MASTER
interface bond0
virtual_router_id 50
priority 100
advert_int 1
authentication {
auth_type PASS
auth_pass 1111
}
virtual_ipaddress {
10.30.92.243
}
}
主vip节点配置
global_defs {
router_id master-2
}
vrrp_instance VI_1 {
state BACKUP
interface bond0
virtual_router_id 50
priority 90
advert_int 1
authentication {
auth_type PASS
auth_pass 1111
}
virtual_ipaddress {
10.30.92.243
}
}
备vip节点配置
Nginx配置
两台服务器上都安装nginx服务,并且两台服务器上的nginx配置都保持一致。这样即使有一台nginx主机挂掉,我们依然可以通过备vip主机访问服务
server {
listen 80;
server_name localhost;
#charset koi8-r;
#access_log logs/host.access.log main;
#location / {
# root html;
# index index.html index.htm;
#}
location / {
proxy_pass http://10.30.92.72:38100;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
}
nginx.conf
隧道访问VIP
vip上的nginx:80转发到后端服务