一、Keepalived双主模式+DNS轮询机制作用
作用:在单主模式下,备机通常会以等待状态放着,不接受任何数据,导致所有数据请求只往主机-负载均衡发送,做成资源浪费;而双主模式,即创造两个VIP,两个VIP分别放在两台负载均衡的机器上,同时两台主机均为对方的备机,以作VIP的漂移,服务接管作用,加入DNS轮询机制,使客户端的域名分别依次解释到两个VIP上,形成两台负载均衡主机同时对外提供服务。同时也解决了单主模式下的单机性能屏颈。
二、网络拓扑图
三、两台负载均衡主机的Keepalived 配置文件
lb01 keepalived.conf
! Configuration File for keepalived
global_defs {
notification_email {
345619885@qq.com
}
notification_email_from Alexandre.Cassen@firewall.loc
smtp_server 192.168.200.1
smtp_connect_timeout 30
router_id lb01
}
vrrp_instance VI_1 {
state MASTER
interface eth1
virtual_router_id 53
priority 150
advert_int 1
authentication {
auth_type PASS
auth_pass 3333
}
virtual_ipaddress {
10.3.150.200/24 dev eth1 label eth1:1
}
}
vrrp_instance VI_2 {
state BACKUP
interface eth1
virtual_router_id 54
priority 100
advert_int 1
authentication {
auth_type PASS
auth_pass 4444
}
virtual_ipaddress {
10.3.150.201/24 dev eth1 label eth1:1
}
}
lb02 keepalived.conf
! Configuration File for keepalived
global_defs {
notification_email {
345619885@qq.com
}
notification_email_from Alexandre.Cassen@firewall.loc
smtp_server 192.168.200.1
smtp_connect_timeout 30
router_id lb01
}
vrrp_instance VI_1 {
state BACKUP
interface eth1
virtual_router_id 53
priority 100
advert_int 1
authentication {
auth_type PASS
auth_pass 3333
}
virtual_ipaddress {
10.3.150.200/24 dev eth1 label eth1:1
}
}
vrrp_instance VI_2 {
state MASTER
interface eth1
virtual_router_id 54
priority 150
advert_int 1
authentication {
auth_type PASS
auth_pass 4444
}
virtual_ipaddress {
10.3.150.201/24 dev eth1 label eth1:1
}
}
四、两台负载均衡主机的上的nginx配置文件
worker_processes 1;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
server 10.3.150.198:80 weight=1;
server 10.3.150.199:80 weight=1;
}
server {
listen 80;
server_name localhost;
location / {
proxy_pass http://server_pools;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
}