Haproxy/ Varnish/ Cherokee/ Nginx/ Lighttpd

最近在蹦心的开发环境下交叉对比测试了标题中各个牛X东东的组合架构,最后采用的结构是:

Haproxy->Varnish->Nginx/Cherokee/Lighttpd

前端使用Haproxy作为BigIP的负载均衡节点,最新版对双机热备、L7交换均有较好支持,友好的web状态监控也很不错;至于为什么不选择Varnish、Nginx或者LVS作为负载均衡,不多说了,具体问题可以和我探讨;

在Haproxy下挂载Varnish作为cache和二级负载分发处理层,考虑因素是比squid更好的可配置性和理论性能数据;

后端的web server优先考虑Nginx,其次进行了部分节点部署Cherokee,一方面为了测试性能,也是为了跟踪该软件后续升级后的表现,从目前我的测试环境来看,并非有Nginx性能好,因为从Haproxy的优先选择结果来看,更多的会选择Nginx后端分发请求,即使有weight优先的情况下。Lightpd逐渐的退出我们的系统了,更新的停滞和相对性能无优势的现状使得被我逐渐放弃。

其实从很多中小站点来说,对于使用Haproxy还是Varnish或者Nginx做负载均衡,差别都是不大的,理论的测试数据对中小站点来说,没有太多实际意义,选择一个最熟悉,配置最方便的才是最好的,综合实际情况来说,用Nginx作为负载均衡还是不错的,比如可以集中处理日志,灵活的配置文件语法可以方便的使用正则配置L7交换逻辑,这些都是很实际的。

随着蹦心的发展,将不断根据具体情况调整架构并且随时和大家分享经验。

开发环境下的haproxy监控,点击图片看大图

开发环境下的haproxy监控,点击图片看大图

Category: 其他技术
You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.
15 Responses
  1. Joshua Zhu says:

    嗯,如果是单纯的做反向代理,HAProxy是性能最高的

  2. Michael says:

    [Comment ID #31686 Will Be Quoted Here]

    这位朋友有没有什么关于haproxy使用的好经验分享?

  3. Joshua Zhu says:

    @Michael:
    1、关于配置源码exampels目录下有不少例子。注意最大fd数(连接数)还有超时时间之类的。可适当调节一下进程数看看有没有效果。
    2、注意buffer大小对整个内存占用的影响。如果对默认值(16K)不满意,你可以修改它。
    3、sepoll的性能不错,但是有bug会导致CPU占用100%,我不知道现在这个bug修复了没有,如果你想稳妥点,那可以只用epoll。

    以上都要对你的实际应用测试后才知道是否有意义 🙂

  4. Michael says:

    [Comment ID #31692 Will Be Quoted Here]

    太好了,目前已经测试运行快一周了,我多试试不同的参数组合配置看看,感谢!

  5. bobo068 says:

    不错,我们现在用的是Nginx-> varnish -> Nginx+PHP,前端的响应时没有什么问题的。只是后端数据库感觉有些瓶颈,不知道你们是怎么处理的?

  6. Michael says:

    [Comment ID #31694 Will Be Quoted Here]

    后端数据库一般通过主辅库分离,然后配合mysql-proxy(LVS/Haproxy)等对多个辅库进行负载均衡,然后再加入memcached以及自己写的app中间数据引擎来缓存和索引,大致是这样

    Haproxy->Varnish->Nginx+PHP->Memcached->Proxy(LVS)->MySQL (Other App + MySQL)

  7. learsu says:

    生产环境中至少keepalived+haproxy*2保证前端转发正常吧。单台haproxy一旦出现问题整个项目不能用,风险太大吧。

  8. Michael says:

    没错,对于在预算允许的情况下,合理的架构设计最重要的一条就是避免任何的单点,但是实际情况下如何呢? 我们绝大部分的网站不在前端是单点,就是后台某个环节是单点,这任何的单点都会导致一旦出现故障,整个网站就出现系统维护或者暂时无法访问的提示页面出现,NB的公司通常会使用两台F5这样的设备实现高可靠性,稍差点的,一般会使用两台LVS或者Haproxy通过心跳线来做实时热备,更差点的公司,能考虑到使用LVS或者Haproxy已经不错了,绝大部分公司的实际情况是,根本考虑不到这些情况,有的也是因为预算不足所致。

    有关负载均衡,可以到我另外一个文章里面探讨:http://www.toplee.com/blog/71.html

  9. bobo068 says:

    后端数据库一般通过主辅库分离,然后配合mysql-proxy(LVS/Haproxy)等对多个辅库进行负载均衡,然后再加入memcached以及自己写的app中间数据引擎来缓存和索引,大致是这样

    Haproxy->Varnish->Nginx+PHP->Memcached->Proxy(LVS)->MySQL (Other App + MySQL)

    ————–

    呵,还好有括号说明,不然我还真理解成lua的那个“mysql-proxy”了。
    我们当前的mysql slave均衡还是通过代码随机选取的,谈不上真正意义上的均衡,接下来我是打算在内网放一台专用于的均衡的服务器,应该是lvs或者haproxy。
    另外,我观察到varnish的round-robin,random两个均衡策略对后端没有效果,不知道你碰到没有?
    director webserver round-robin {
    { .backend = sina1; }
    { .backend = sina2; }
    }

    #director webserver random {
    # .retries = 3;
    # { .backend = sina1; .weight=5; }
    # { .backend = sina2; .weight=5; }
    #}

  10. learsu says:

    生产环境会出现一个峰值并发,一旦峰值并发超出haproxy的承受范围您怎么处理?即使用keepalived把前端转到备机上的haproxy,但备机的haproxy仍然无法承受这个峰值转发,依然会有大量转发堆积到前端。影响用户体验。一般这种峰值只出现几分钟几十分钟不等。如果不使用F5之类的硬件有没有更好的解决办法?

  11. 深夜的蚊子 says:

    bobo068: 后端数据库一般通过主辅库分离,然后配合mysql-proxy(LVS/Haproxy)等对多个辅库进行负载均衡,然后再加入memcached以及自己写的app中间数据引擎来缓存和索引,大致是这样Haproxy->Varnish->Nginx+PHP->Memcached->Proxy(LVS)->MySQL (Other App + MySQL)————–呵,还好有括号说明,不然我还真理解成lua的那个“mysql-proxy”了。
    我们当前的mysql slave均衡还是通过代码随机选取的,谈不上真正意义上的均衡,接下来我是打算在内网放一台专用于的均衡的服务器,应该是lvs或者haproxy。
    另外,我观察到varnish的round-robin,random两个均衡策略对后端没有效果,不知道你碰到没有?
    director webserver round-robin { { .backend = sina1; } { .backend = sina2; }
    }#director webserver random {
    #.retries = 3;
    #{ .backend = sina1; .weight=5; }
    #{ .backend = sina2; .weight=5; }
    #}

    我认为前端不可能只用一台haproxy来做成载的吧,如果是多台又没有lvs进行分配请求就可以考虑使用dns轮询的方式做负载,当然这样也会有风险存在,但总比单台承担风险要强

    另外我认为,如果因为成本考虑而不能保证所有单点消除的话,可以考虑使用heartbeat2.x的技术,达到多机互为备份的做法,规避一下风险

  12. wwek says:

    都是高手啊。搜索资料看到博主的站 不错
    我只停留在部分用过的阶段。

  13. rfyiamcool says:

    对于这些个反向代理,我基本都用过,单单是性能对比的话 haproxy-varnish-nginx-squid
    也可能是本人水平的有限,通过google找了很多高手的例子 感觉squid做静态的,如 图片服务器的话 很强大

  14. mfl says:

    我想问下 Haproxy->Varnish 这两个分别怎么配置啊
    我配置了haproxy的服务器 跳出503

  15. Pingback: click through the next post
  16. Hello, i feel that i saw you visited my website thus i got here to return the choose?.I’m trying to
    to find things to improve my website!I guess its good enough to
    make use of a few of your ideas!!

  17. It’s awesome in support of me to have a web site, which is good designed for my
    knowledge. thanks admin

  18. g says:

    Touche. Outstanding arguments. Keep up the amazing work.

  19. I blog frequently and I really appreciate your content.
    The article has really peaked my interest. I am going to book mark your website
    and keep checking for new information about once a week.
    I opted in for your RSS feed too.

  20. Hey great blog! Does running a blog like this take a lot
    of work? I have absolutely no knowledge of coding but I was hoping to
    start my own blog in the near future. Anyways, should you have
    any recommendations or techniques for new blog owners please
    share. I know this is off topic but I just needed to ask.
    Cheers!

  21. Hey! This post couldn’t be written any better! Reading
    through this post reminds me of my previous room mate!
    He always kept chatting about this. I will forward this
    page to him. Fairly certain he will have a good read.
    Many thanks for sharing!

  22. Hi there friends, good piece of writing and nice urging commented here, I am genuinely enjoying by these.

  23. I’ve been surfing on-line more than 3 hours lately, yet I by no means discovered any attention-grabbing article like yours.
    It is beautiful price sufficient for me. In my view, if all site owners and bloggers made good content as you did, the internet
    shall be much more helpful than ever before.

  24. Hello, after reading this amazing piece of writing i am also delighted to share my experience here
    with friends.

  25. I like the valuable information you provide in your
    articles. I’ll bookmark your weblog and check again here regularly.
    I’m quite sure I’ll learn plenty of new stuff right here!
    Best of luck for the next!

  26. ps4 gamestop says:

    What’s up to every single one, it’s truly
    a pleasant for me to visit this website, it consists
    of useful Information.

  27. Helpful info. Lucky me I discovered your website unintentionally, and I’m stunned why
    this accident didn’t took place in advance! I bookmarked it.

  28. With havin so much written content do you ever run into any problems of plagorism or copyright violation? My site
    has a lot of completely unique content I’ve
    either created myself or outsourced but it seems a
    lot of it is popping it up all over the web without my permission.
    Do you know any solutions to help protect against content from being
    ripped off? I’d really appreciate it.

  29. quest bars says:

    My brother recommended I might like this blog. He was totally
    right. This post truly made my day. You can not imagine
    just how much time I had spent for this info!
    Thanks!

  30. I am sure this piece of writing has touched all the internet people, its really really pleasant post on building up new webpage.

  31. Thanks on your marvelous posting! I actually enjoyed reading it, you’re a great author.
    I will ensure that I bookmark your blog and may come back down the road.
    I want to encourage that you continue your great writing, have a nice holiday weekend!

Leave a Reply

Your email address will not be published. Required fields are marked *

*
To prove you're a person (not a spam script), type the security word shown in the picture. Click on the picture to hear an audio file of the word.
Anti-spam image