目录
.---> media [mp3, wma, wmv, rmvb, asf, divx]-\
/ +------------+
.-----> photo [gif, jpg, png, swf] ----> | Raid Array | <--.
/------------------- <---------\/ +------------+ \
user -> dns -> load balancing -> squid -> [cache] <----[html]----\ / |
\ \ \______<______/\ +-------------+ / |
\ \ \-----> web app ----> | html |--------^ |
\ \____________________________/\ | php,jsp,cgi | |
\ \ +-------------+ |
\ `-----> memcached [node1, node2, node(n)] |
\__________________________________________/\ |
`------> Database cluster |
+--------------------------------------+ \ |
| Author: neo chen <openunix#163.com> | `-------------+
| Nickname: netkiller |
| Homepage: http://netkiller.github.io |
+--------------------------------------+
集群有很多实现方法,分为硬件和软件,集群可以在不同网络层面上实现
实现IP轮循(Bind DNS)
硬件四层交换(硬件负载均衡设备 F5 BIG IP)
软件四层交换(linux virtual server)
应用层上实现(tomcat)
越是低层性能越好,越是上层功能更强
集群的分类
高可用性集群
负载均衡集群
超级计算集群
网站一般用到两种集群分别是高可用性集群和负载均衡集群
这是早期出现的负载均衡技术,直到现在,很多网站仍然使用DNS负载均衡。
你可通过ping命令观看它是如何工作的,例如你可反复ping个网域名。
C:\>ping www.163.com
Pinging www.cache.split.netease.com [220.181.28.52] with 32 bytes of data:
Reply from 220.181.28.52: bytes=32 time=226ms TTL=53
Reply from 220.181.28.52: bytes=32 time=225ms TTL=53
Reply from 220.181.28.52: bytes=32 time=226ms TTL=53
Reply from 220.181.28.52: bytes=32 time=226ms TTL=53
Ping statistics for 220.181.28.52:
Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),
Approximate round trip times in milli-seconds:
Minimum = 225ms, Maximum = 226ms, Average = 225ms
C:\>ping www.163.com
Pinging www.cache.split.netease.com [220.181.28.53] with 32 bytes of data:
Reply from 220.181.28.53: bytes=32 time=52ms TTL=52
Reply from 220.181.28.53: bytes=32 time=53ms TTL=52
Reply from 220.181.28.53: bytes=32 time=52ms TTL=52
Reply from 220.181.28.53: bytes=32 time=52ms TTL=52
Ping statistics for 220.181.28.53:
Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),
Approximate round trip times in milli-seconds:
Minimum = 52ms, Maximum = 53ms, Average = 52ms
C:\>ping www.163.com
Pinging www.cache.split.netease.com [220.181.28.50] with 32 bytes of data:
Reply from 220.181.28.50: bytes=32 time=51ms TTL=53
Reply from 220.181.28.50: bytes=32 time=52ms TTL=53
Reply from 220.181.28.50: bytes=32 time=52ms TTL=53
Reply from 220.181.28.50: bytes=32 time=51ms TTL=53
Ping statistics for 220.181.28.50:
Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),
Approximate round trip times in milli-seconds:
Minimum = 51ms, Maximum = 52ms, Average = 51ms
C:\>
DNS负载均衡主要优点
技术简单,容易实现,灵活,方便,成本低
Web服务器可以位于互联网的任意位置上,无地理限制。
DNS的主从结构非常稳定
可以有效的分散DDOS攻击。
你甚至可以在DNS服务商那里实现,自己不需要添加设备。而且没有带宽开销。
DNS负载均衡主要缺点
DNS负载均衡采用的是简单的轮循负载算法,不能够按照服务器节点的处理能力分配负载。
不支持故障转移(failover)和自动恢复failback ,如果某台服务器拓机,DNS仍会将用户解析到这台故障服务器上,导致不能响应客户端。
如果添加节点或撤出节点,不能即时更新到省市级DNS,可导致部分地区不能访问。
占用大量静态IP。
软件四层交换负载均衡为我们解决了几个问题
能够按照服务器节点的处理能力分配负载。
支持故障转移(failover)和自动恢复failback ,如果某节点拓机,调度器自动将它剔除,不响应客户端访问,当节点故障排除调度器立即恢复节点。
可以随时添加节点或撤出节点,即时生效,方便网站扩容。
软件四层交换负载均衡优点
仅仅需要一个静态IP。
节点位于私有网络上与WAN隔离,用户面对的只是调度器。
可以随时添加节点或撤出节点。
通过端口可以组建多个集群。
俗称:双机热备份
关键词:心跳线
两部服务器,或多部服务器,形成一个集群,当主服务器崩溃是,立即切换到其它节点上。
两部服务器要做到,内容实时同步,保持数据一直。
一般用 heartbeat + DRBD 实现。heartbeat负责切换服务器,DRBD用于同步数据。
负载均衡成熟产品
F5 Big IP
Array
这些设备可提供3,4,7层负载均衡HA,硬件已经压缩,HTTP头改写,URL改写...
其中3层交换部分多采用硬件实现。