RabbitMQ+HAProxy

原本打算直接用nginx反向代理,发现不好用,默认不支持长连接,见很多推荐HAProxy的,就试试吧~

  1. wget http://haproxy.1wt.eu/download/1.4/src/haproxy-1.4.21.tar.gz  
  2. tar -zxvf haproxy-1.4.21.tar.gz   
  3. cd haproxy-1.4.21  
  4. make TARGET=linux26 PREFIX=/usr/local  
  5. make install PREFIX=/usr/local  
  6. cp haproxy-1.4.21/examples/haproxy.cfg /etc/haproxy.cfg  

vim /etc/haproxy.cfg 修改配置文件:

  1. global  
  2.         log 127.0.0.1  alert debug  
  3.         #log loghost    local0 info  
  4.         maxconn 4096  
  5.         #chroot /usr/share/haproxy  
  6.         uid 99  
  7.         gid 99  
  8.         daemon  
  9.         #debug  
  10.         #quiet  
  11.   
  12. defaults  
  13.         log     global  
  14.         mode    http  
  15.         option  dontlognull  
  16.         retries 3  
  17.         option  redispatch  
  18.         maxconn 2000  
  19.         contimeout      5000  
  20.         clitimeout      50000  
  21.         srvtimeout      50000  
  22.   
  23. listen  rabbitmq 0.0.0.0:56720  
  24.         mode    tcp  
  25.         balance roundrobin  
  26.         option  tcpka  
  27.         server  rabbit1 192.168.1.93:5672 check inter 5000 downinter 500  
  28.         server  rabbit2 192.168.1.94:5672 check inter 5000   

用当前机器56720端口,代理93、94两台rabbit机器的5672端口。

守护模式运行:

haproxy -f /etc/haproxy.cfg -D

BTW:尚未详细测试和调优等。

----------------------------------------------我是分割线---------------------------------------------------

参考资料:

http://haproxy.1wt.eu/

http://blog.chenlb.com/2009/06/install-haproxy-and-configure-load-balance.html

http://www.joshdevins.net/2010/04/16/rabbitmq-ha-testing-with-haproxy/

http://blog.chinaunix.net/uid-10249062-id-163273.html

原文地址:https://www.cnblogs.com/lchb/p/2889925.html