• 负载均衡那点事儿


    为什么今天想谈谈负载均衡,因为今天被问到了一个问题

    一个域名可否绑定多个IP?

    很明显,答案是:yes。至少我们备案时见过这种形式,即一个域名多个ip。

    那么,从技术层面来说,这种机制又如何实现呢?毕竟,DNS服务器负责解析域名,可它如何解析到多个IP地址呢?

    好比这位仁兄问的问题:http://stackoverflow.com/questions/10257969/is-it-possible-that-one-domain-name-has-multiple-corresponding-ip-addresses

    Q: For example, when we connect to www.abc.com, at first we try to connect to 1.1.1.1. And if first try fails, then we try 2.2.2.2. Is it possible? Can we register multiple backup IP addresses for one domain name?

    答案是:

    A: This is round robin DNS. This is a quite simple solution for load balancing. Usually DNS servers rotate/shuffle the DNS records for each incoming DNS request. Unfortunately it's not a real solution for fail-over. If one of the servers fail, some visitors will still be directed to this failed server.

    现在的域名服务器有一种叫做Round-robin DNS机制,说白了,DNS服务器会维护一个IP列表,列表中的IP值会循环滚动,每一次DNS请求到来时,就返回表中第一个IP地址。

    这实际上是dns层面的负载均衡,然而,这不能保证高可用性。因为,访问者仍旧有可能被引导至失效的服务器上(rp很差的时候,多个IP对应的服务器挂掉,更悲催的是,每次都不幸被解析到这几个IP上)。

    所以,不能寄希望简单通过DNS来实现负载均衡。有时候,我们需要搭建自己的负载均衡集群。

    暂且不说多IP多集群的负载均衡方式。就说最简单的吧,给你一个IP和对应的域名,是的,只有一个,如何实现负载均衡?

    有人说,这简单啊,自己搭建一台apache/ngix服务器,在前端扛着,往后端分发流量。嗯,是可以,不过万一挂了咋办?(单点失效)那岂不整个网站都废了?

    面对这种情况,通常的业界做法是,做一对负载均衡主机。

    看看大神们的回答吧!

    1.http://serverfault.com/questions/139077/what-happens-when-a-load-balancer-fails?rq=1

    Q:

    Let's say I'm using Amazon's EC2 load balancer. I have it hooked up to two instances (excuse me if my terminology isn't correct). What happens if the load balancer fails? Do both instances fail to work now?

    A:

    Typically load balancers are clustered together into a high-availability pair.

    If one load balancer fails, the secondary picks up the failure and becomes active. They have a heartbeat link between them that monitors status.

    If all load balancers fail (or are accidentally misconfigured), servers down-stream are knocked offline until the problem is resolved, or you manually route around them.

    2.http://serverfault.com/questions/362343/several-load-balancing-servers-listening-on-single-ip-port

    Q:

    Let's say I have a fully working, load-balanced application server environment.

    All servers have to fail-over gracefully. It's relatively easy to do with the application servers, but how can I achieve fail-over with the front load-balancer?

    Can I have multiple load-balancers listening on the same IP and port? Do I have to run a new one as soon as I detect the old one died?

    A:

    In basic terms:

    • You have two or more load balancers running at the same time
    • They are both configured with the same config, IP address, etc
    • They run a heartbeat
    • Only one is active at any given time
    • When the heartbeat from the active node goes away (fails), the rest negotiate between them who will come online next

    翻译成中文就是:准备两台负载均衡主机,一台处于激活状态,对外提供web服务,另一台处于未激活状态,不提供web服务。两台之间通过心跳包相互检测彼此是否正常工作。当一台机器失效后,另一个立马以相同的配置将自己激活,承接对外web服务工作。

    什么,两台都挂了?那只能说rp不够好了。话说回来,世上没有绝对的安全,我们能做的,就是尽量更加安全。

    如果采用Amazon云计算平台,则可以省去很多工作了。负载均衡有专门的ELB服务,可以直接调用。若是自己搭建集群,也可以采用auto-scaling服务,实现即时动态扩展。

  • 相关阅读:
    node 使用 ssh2-sftp-client 实现 FTP 的文件上传和下载功能
    gulp 使用 gulp.spritesmith 组件生成雪碧图
    webpack4 打包多页面应用
    javascript 两个变量值的互换
    微信公众号爬坑(react)
    文件上传(H5 + node)
    前后端分离 ajax 跨域 session 传值 (后端使用 node)
    webpack dev 日记
    npm报错 端口被占用 events.js:167 throw er; // Unhandled 'error' event Error: listen EADDRINUSE 127.0.0.1:9999
    多个 img 之间存在间隔
  • 原文地址:https://www.cnblogs.com/ShaneZhang/p/5563603.html
Copyright © 2020-2023  润新知