Keepalived 之 双主模式+DNS轮询机制 实现高负载

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Keepalived 之 双主模式+DNS轮询机制 实现高负载相关的知识,希望对你有一定的参考价值。

一、Keepalived双主模式+DNS轮询机制作用

作用:在单主模式下,备机通常会以等待状态放着,不接受任何数据,导致所有数据请求只往主机-负载均衡发送,做成资源浪费;而双主模式,即创造两个VIP,两个VIP分别放在两台负载均衡的机器上,同时两台主机均为对方的备机,以作VIP的漂移,服务接管作用,加入DNS轮询机制,使客户端的域名分别依次解释到两个VIP上,形成两台负载均衡主机同时对外提供服务。同时也解决了单主模式下的单机性能屏颈。

二、网络拓扑图

技术分享图片

三、两台负载均衡主机的Keepalived 配置文件

lb01 keepalived.conf

! Configuration File for keepalived

global_defs {
   notification_email {
   [email protected]
}
   notification_email_from [email protected]
   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 {
   [email protected]
}
   notification_email_from [email protected]
   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;
        }
    }
}

五、两台web主机,均为httpd,静态内容(内容不一致)

六、把www.kang.com分别添加两条A记录,解释IP为:10.3.150.200 与 10.3.150.201

七、从多个客户端分别访问www.kang.com 域名,同时观察两台负载均衡的nginx访问日志,看是否正常,如正常,代表DNS设置成功。

八、在两台负载均衡主机上,分别关停keepalived服务,看是否出现VIP漂移到备机上,如漂移过去,代表设置成功。

以上是关于Keepalived 之 双主模式+DNS轮询机制 实现高负载的主要内容,如果未能解决你的问题,请参考以下文章

MySQL高可用性之Keepalived+MySQL(双主热备)

高可用集群架构Keepalived双主热备

【keepalived】keepalived vrrp 双实例

DNS域名服务器双master+ntp时间服务器双主+keepalived企业高可用方案 附脚本

MySQL高可用之KeepAlived+双主

Nginx+keepalived(高可用双主模式)