您的位置:首页 > 运维架构 > Nginx

利用HAProxy取代nginx代理activemq

2015-07-30 11:41 567 查看

由于nginx默认仅支持http应用层协议的端口,对四层tcp端口支持不好,需要安装额外的nginx_tcp_proxy_module模块,因此在不方便重新编译nginx模块时,可以用HAProxy代理activemq的tcp端口,只需要6个步骤就可以完成(以Ubuntu为例,CentOS大同小异)。

步骤1:安装HAProxy

apt-get install haproxy

步骤2:配置HAProxy配置文件

vim编辑/etc/haproxy/haproxy.cfg,将defaults段中的mode     http和option     httplog注释掉,添加一个tcp代理,如下文所示:global           log /dev/log     local0           log /dev/log     local1 notice           chroot /var/lib/haproxy           user haproxy           group haproxy           daemon      defaults           log     global           #mode     http           #option     httplog           option     dontlognull              contimeout 5000              clitimeout 50000              srvtimeout 50000           errorfile 400 /etc/haproxy/errors/400.http           errorfile 403 /etc/haproxy/errors/403.http           errorfile 408 /etc/haproxy/errors/408.http           errorfile 500 /etc/haproxy/errors/500.http           errorfile 502 /etc/haproxy/errors/502.http           errorfile 503 /etc/haproxy/errors/503.http           errorfile 504 /etc/haproxy/errors/504.http      listen activemq_cluster 0.0.0.0:61616          mode tcp          balance source          option tcpka          option tcplog          server  activemqnode1 192.168.100.81:61616 check inter 2000 rise 2 fall 3

步骤3:测试HAProxy配置文件是否正确

/usr/sbin/haproxy -c -f /etc/haproxy/haproxy.cfg

步骤4:启用HAProxy,允许init脚本启动HAProxy,如/etc/init.d/haproxy start或service haproxy start等

# /etc/default/haproxy ,ENABLED=1
sed -i 's/ENABLED=0/ENABLED=1/g' /etc/default/haproxy
cat /etc/default/haproxy
# Set ENABLED to 1 if you want the init script to start haproxy.      
ENABLED=1       
# Add extra flags here.       
#EXTRAOPTS="-de -m 16"

步骤5:启动HAProxy并检查运行结果

/etc/init.d/haproxy start或service haproxy start
/etc/init.d/haproxy status或service haproxy status
netstat –anop | grep haproxy或ps –ef | grep haproxy | grep –v grep

步骤6:允许防火墙通过设定的tcp端口

ufw allow 61616/tcp

接下来就可以测试和使用activemq了。

--end--

阅读更多
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: