700字范文,内容丰富有趣,生活中的好帮手!
700字范文 > 负载均衡工具 haproxy剖析

负载均衡工具 haproxy剖析

时间:2024-05-13 19:21:16

相关推荐

负载均衡工具 haproxy剖析

haproxy 进阶 应用场景

只是作为负载均衡的工具,至于是什么应用集群都可以,例如:上面的RabbitMQ集群

下面那redis集群再给大家举个例子:

创建+配置haproxy配置文件

#创建haproxy配置文件touch /etc/haproxy/haproxy.cfg#Haproxy配置PS:haproxy 配置文件haproxy.cfg详解vim /etc/haproxy/haproxy.cfg

添加内容如下:

#logging optionsgloballog 127.0.0.1 local0 info #日志输出配置,所有日志都记录在本机,通过local0输出maxconn 5120chroot /app/haproxy #haproxy 安装路径uid 99 #所属运行的用户uidgid 99 #所属运行的用户组daemon #后台运行quietnbproc 20pidfile /var/run/haproxy.pid #指定PID文件路径defaultslog global#使用4层代理模式,"mode http"为7层代理模式mode tcp#if you set mode to tcp,then you nust change tcplog into httplogoption tcplogoption dontlognullretries 3option redispatchmaxconn 2000#连接超时时间timeout connect 5s#客户端空闲超时时间为 60秒 则HA 发起重连机制timeout client 60s#服务器端连接超时时间为 15秒 则HA 发起重连机制timeout server 15s#front-end IP for consumers and producterslisten rabbitmq_clusterbind 0.0.0.0:5672 #绑定协议端口#配置TCP模式#所处理的类别,默认采用http模式,可配置成tcp作4层消息转发mode tcp#balance url_param userid#balance url_param session_id check_post 64#balance hdr(User-Agent)#balance hdr(host)#balance hdr(Host) use_domain_only#balance rdp-cookie#balance leastconn#balance source //ip#简单的轮询balance roundrobin#负载均衡策略#rabbitmq集群节点配置 #inter 每隔五秒对mq集群做健康检查, 2次正确证明服务器可用,2次失败证明服务器不可用,并且配置主备机制server redis-01 192.168.0.115:5672 check inter 5000 rise 2 fall 2server redis-02 192.168.0.117:5672 check inter 5000 rise 2 fall 2server redis-03 192.168.0.118:5672 check inter 5000 rise 2 fall 2#配置haproxy web监控,查看统计信息listen statsbind 192.168.0.119:8100 #前端浏览器中查看统计的WEB界面地址mode httpoption httplog #日志类别,采用httplogstats enablestats auth admin:123456 #设置查看统计的账号密码#设置haproxy监控地址为http://localhost:8100/rabbitmq-statsstats uri /rabbitmq-statsstats refresh 5s #5s刷新一次

注:以上配置基于haproxy-2.1.2 版本,低版本有部分差异

不相同部分剖析:

redis集群:

server redis-01 192.168.0.115:5672 check inter 5000 rise 2 fall 2server redis-02 192.168.0.117:5672 check inter 5000 rise 2 fall 2server redis-03 192.168.0.118:5672 check inter 5000 rise 2 fall 2

MQ集群:

server mq-01 192.168.0.115:5672 check inter 5000 rise 2 fall 2server mq-02 192.168.0.117:5672 check inter 5000 rise 2 fall 2server mq-03 192.168.0.118:5672 check inter 5000 rise 2 fall 2

其他部分属于公共自定义部分,保持默认即可

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。