当前位置:主页 > 查看内容

MQ RabbitMQ 高可用集群(三):Ha-Proxy安装和配置

发布时间:2021-09-08 00:00| 位朋友查看

简介:1 简介 HAProxy是一款提供高可用性、负载均衡以及基于TCP和HTTP应用的代理软件HAProxy是完全免费的、借助HAProxy可以快速并且可靠的提供基于TCP和HTTP应用的代理解决方案。 HAProxy适用于那些负载较大的web站点这些站点通常又需要会话保持或七层处理。 HAPro……

1 简介

HAProxy是一款提供高可用性、负载均衡以及基于TCP和HTTP应用的代理软件,HAProxy是完全免费的、借助HAProxy可以快速并且可靠的提供基于TCP和HTTP应用的代理解决方案。

HAProxy适用于那些负载较大的web站点,这些站点通常又需要会话保持或七层处理。

HAProxy可以支持数以万计的并发连接,并且HAProxy的运行模式使得它可以很简单安全的整合进架构中,同时可以保护web服务器不被暴露到网络上。

引用: http://www.rabbitmq.com/blog/2011/02/10/introducing-publisher-confirms/

2 安装

74、75节点同时安装Haproxy,下面步骤统一

2.1 下载安装

下载haproxy:http://www.linuxea.com/tag/haproxy/

[root@localhost ~]# wget http://www.haproxy.org/download/1.6/src/haproxy-1.6.5.tar.gz
[root@localhost ~]# tar -zxvf haproxy-1.6.5.tar.gz -C /usr/local

编译安装

[root@localhost ~]# cd /usr/local/haproxy-1.6.5
[root@localhost haproxy-1.6.5]# make TARGET=linux31 PREFIX=/usr/local/haproxy
[root@localhost haproxy-1.6.5]# make install PREFIX=/usr/local/haproxy
[root@localhost haproxy-1.6.5]# mkdir /etc/haproxy

设置权限

[root@localhost haproxy-1.6.5]# groupadd -r -g 149 haproxy
[root@localhost haproxy-1.6.5]# useradd -g haproxy -r -s /sbin/nologin -u 149 haproxy

创建配置文件

[root@localhost haproxy-1.6.5]# touch /etc/haproxy/haproxy.cfg

2.2 配置

haproxy 配置文件haproxy.cfg详解

[root@localhost ~]# vi /etc/haproxy/haproxy.cfg
#logging options
global
	log 127.0.0.1 local0 info
	maxconn 5120
	chroot /usr/local/haproxy
	uid 99
	gid 99
	daemon
	quiet
	nbproc 20
	pidfile /var/run/haproxy.pid

defaults
	log global
	#使用4层代理模式,”mode http”为7层代理模式
	mode tcp
	#if you set mode to tcp,then you nust change tcplog into httplog
	option tcplog
	option dontlognull
	retries 3
	option redispatch
	maxconn 2000
	contimeout 10s
     ##客户端空闲超时时间为 60秒 则HA 发起重连机制
     clitimeout 10s
     ##服务器端链接超时时间为 15秒 则HA 发起重连机制
     srvtimeout 10s	
#front-end IP for consumers and producters

listen rabbitmq_cluster
	bind 0.0.0.0:5672
	#配置TCP模式
	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 bhz71 192.168.11.71:5672 check inter 5000 rise 2 fall 2
        server bhz72 192.168.11.72:5672 check inter 5000 rise 2 fall 2
        server bhz73 192.168.11.73:5672 check inter 5000 rise 2 fall 2
#配置haproxy web监控,查看统计信息
listen stats
	bind 192.168.11.74:8100
	mode http
	option httplog
	stats enable
	#设置haproxy监控地址为http://localhost:8100/rabbitmq-stats
	stats uri /rabbitmq-stats
	stats refresh 5s

3 管理与测试

3.1 启动 haproxy

[root@localhost ~]# /usr/local/haproxy/sbin/haproxy -f /etc/haproxy/haproxy.cfg

3.2 测试访问

访问如下地址可以对rmq节点进行监控:http://192.168.11.74:8100/rabbitmq-stats

在这里插入图片描述

3.3 关闭 haproxy

# 杀进程 killall haproxy
# 查询进程
ps -ef | grep haproxy
# 查询进程
netstat -tunpl | grep haproxy
# 查询并杀死进程
ps -ef |grep haproxy |awk '{print $2}'|xargs kill -9

4 相关信息

上一篇:MQ RabbitMQ 高可用集群(二):集群搭建

下一篇:MQ RabbitMQ 高可用集群(四):Keepalived安装和配置

博文不易,辛苦各位猿友点个关注和赞,感谢

;原文链接:https://blog.csdn.net/qq_15769939/article/details/115933189
本站部分内容转载于网络,版权归原作者所有,转载之目的在于传播更多优秀技术内容,如有侵权请联系QQ/微信:153890879删除,谢谢!

推荐图文


随机推荐