原本打算直接用nginx反向代理,发现不好用,默认不支持长连接,见很多推荐HAProxy的,就试试吧~
wget http://haproxy.1wt.eu/download/1.4/src/haproxy-1.4.21.tar.gz
tar -zxvf haproxy-1.4.21.tar.gz
cd haproxy-1.4.21
make TARGET=linux26 PREFIX=/usr/local
make install PREFIX=/usr/local
cp haproxy-1.4.21/examples/haproxy.cfg /etc/haproxy.cfg
vim /etc/haproxy.cfg 修改配置文件:
global
log 127.0.0.1 alert debug
#log loghost local0 info
maxconn 4096
#chroot /usr/share/haproxy
uid 99
gid 99
daemon
#debug
#quiet
defaults
log global
mode http
option dontlognull
retries 3
option redispatch
maxconn 2000
contimeout 5000
clitimeout 50000
srvtimeout 50000
listen rabbitmq 0.0.0.0:56720
mode tcp
balance roundrobin
option tcpka
server rabbit1 192.168.1.93:5672 check inter 5000 downinter 500
server rabbit2 192.168.1.94:5672 check inter 5000
用当前机器56720端口,代理93、94两台rabbit机器的5672端口。
守护模式运行:
haproxy -f /etc/haproxy.cfg -D
BTW:尚未详细测试和调优等。
----------------------------------------------我是分割线---------------------------------------------------
参考资料:
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