需求1:CDN小节点使用尽可能少的资源实现高可用和负载均衡
需求2:需要支持10多个站点的反向代理后端环境:在前端做url_hash,后端缓存服务器使用和分别处理动静态内容,服务器证书在上解决方案:
使用来实现前端3台nginx的高可用,DNS轮询来均摊负载。每个https站点使用一个独立IP,非https站点分摊到这些IP上。在每台机器的lo上绑定所有的IP来启动nginx服务。
架构图:
原理:
正常情况下负载均摊,每台机器只负担2-3个HTTPS站点,比如此时nginxA只负责192.168.0.101和192.168.0.102这2个 HTTPS站点。当nginxB挂掉时,nginxA和nginxC会根据策略去分担192.168.0.103和192.168.0.104这2个站点 的访问,这时nginxA上负担的站点就可能就是192.168.0.101、192.168.0.102和192.168.0.104了。分配策略:
lo绑ip脚本:
#!/bin/sh echo ’2′ > /proc/sys/net/ /conf/lo/arp_announce echo ’1′ > /proc/sys/net/ipv4/conf/lo/arp_ignore echo ’2′ > /proc/sys/net/ipv4/conf/all/arp_announce echo ’1′ > /proc/sys/net/ipv4/conf/all/arp_ignoreifconfig lo:1 198.188.0.101 netmask 255.255.255.255 ifconfig lo:2 198.188.0.102 netmask 255.255.255.255 ifconfig lo:3 198.188.0.103 netmask 255.255.255.255 ifconfig lo:4 198.188.0.104 netmask 255.255.255.255 ifconfig lo:5 198.188.0.105 netmask 255.255.255.255 ifconfig lo:6 198.188.0.106 netmask 255.255.255.255
Ngnix A配置文件范例:
! Configuration File for keepalivedglobal_defs {
notification_email { duanli0n@gmail}notification_email_from nginx_ha1@snda.comsmtp_server 127.0.0.1smtp_connect_timeout 30router_id nginx_ha1}vrrp_instance VI_1 {
state MASTERinterface eth0virtual_router_id 51priority 150advert_int 1authentication { auth_type PASSauth_pass 1111}virtual_ipaddress { 192.168.0.101192.168.0.102}}vrrp_instance VI_2 {
state BACKUPinterface eth0virtual_router_id 52priority 100advert_int 1authentication { auth_type PASSauth_pass 1111}virtual_ipaddress { 192.168.0.103192.168.0.104}}vrrp_instance VI_3 {
state BACKUPinterface eth0virtual_router_id 53priority 50advert_int 1authentication { auth_type PASSauth_pass 1111}virtual_ipaddress { 192.168.0.105192.168.0.106}}作者:du@nli0n