[size=large]参考博客[/size]
[url]http://blog.youkuaiyun.com/yanggd1987/article/details/52061083[/url]
[url]http://blog.youkuaiyun.com/zzhongcy/article/details/46443765[/url]
[url]http://blog.youkuaiyun.com/tantexian/article/details/50056199[/url]
[url]http://blog.youkuaiyun.com/audioo1/article/details/53189032[/url]
[url]http://www.cnblogs.com/ilanni/p/4750081.html[/url]
[url]https://www.cnblogs.com/wjoyxt/p/3766284.html[/url]
[size=xx-large][b]背景[/b][/size]
[size=large] 利用haproxy对Mosquitto集群进行负载均衡,Mosquitto是基于MQTT协议的消息中间服务器,MQTT协议是常用于物联网Iot的网络资源消耗相对较低的一种基于TCP层协议。[/size]
[size=xx-large][b]场景[/b][/size]
[size=large] 多台终端设备可以发送以及接受数据,请求连接Moquitto服务器,但由于一台Mosquitto服务器并发长连接负载的能力有限,希望通过中间服务器 负载均衡器(HAProxy服务器)平均负载到三台Moquitto服务器集群。[/size]
[size=xx-large][b]准备工作[/b][/size]
[size=large] 利用VMware14虚拟机搭建四台服务器Centos7.0系统并搭建集群,具体搭建可以参考[url]http://ymq267.iteye.com/blog/2409119[/url]
[url]http://ymq267.iteye.com/admin/blogs/2409128[/url]
10.10.10.15 haproxy tcp代理
10.10.10.16 mosquitto master
10.10.10.17 mosquitto slave
10.10.10.18 mosquitto slave
[/size]
[size=x-large][b]安装haproxy[/b][/size]
[size=large] 在10.10.10.15服务器中执行[/size]
[size=x-large][b]安装gcc[/b][/size]
[size=large] 需要有gcc,如果没有可能会报错。[/size]
[size=large] 如果不是Centos则需要下载解压或其他命令下载。[/size]
[size=xx-large][b]配置[/b][/size]
[size=large] haproxy.cfg是很重要且唯一需要修改的配置文件,如果没有可以手动创建。
yum命令在线下载的话,可以能不知道装在哪里,可以搜索haproxy。[/size]
[size=large] 我的haproxy.cfg文件是在/etc/haproxy/目录下,可以先备份一份在进行修改,以免出错。
[/size]
[size=x-large][b]具体haproxy.cfg配置文件内容[/b][/size]
[url]http://blog.youkuaiyun.com/yanggd1987/article/details/52061083[/url]
[url]http://blog.youkuaiyun.com/zzhongcy/article/details/46443765[/url]
[url]http://blog.youkuaiyun.com/tantexian/article/details/50056199[/url]
[url]http://blog.youkuaiyun.com/audioo1/article/details/53189032[/url]
[url]http://www.cnblogs.com/ilanni/p/4750081.html[/url]
[url]https://www.cnblogs.com/wjoyxt/p/3766284.html[/url]
[size=xx-large][b]背景[/b][/size]
[size=large] 利用haproxy对Mosquitto集群进行负载均衡,Mosquitto是基于MQTT协议的消息中间服务器,MQTT协议是常用于物联网Iot的网络资源消耗相对较低的一种基于TCP层协议。[/size]
[size=xx-large][b]场景[/b][/size]
[size=large] 多台终端设备可以发送以及接受数据,请求连接Moquitto服务器,但由于一台Mosquitto服务器并发长连接负载的能力有限,希望通过中间服务器 负载均衡器(HAProxy服务器)平均负载到三台Moquitto服务器集群。[/size]
[size=xx-large][b]准备工作[/b][/size]
[size=large] 利用VMware14虚拟机搭建四台服务器Centos7.0系统并搭建集群,具体搭建可以参考[url]http://ymq267.iteye.com/blog/2409119[/url]
[url]http://ymq267.iteye.com/admin/blogs/2409128[/url]
10.10.10.15 haproxy tcp代理
10.10.10.16 mosquitto master
10.10.10.17 mosquitto slave
10.10.10.18 mosquitto slave
[/size]
[size=x-large][b]安装haproxy[/b][/size]
[size=large] 在10.10.10.15服务器中执行[/size]
#yum install haproxy
[size=x-large][b]安装gcc[/b][/size]
[size=large] 需要有gcc,如果没有可能会报错。[/size]
#yum install -y gcc
[size=large] 如果不是Centos则需要下载解压或其他命令下载。[/size]
[size=xx-large][b]配置[/b][/size]
[size=large] haproxy.cfg是很重要且唯一需要修改的配置文件,如果没有可以手动创建。
yum命令在线下载的话,可以能不知道装在哪里,可以搜索haproxy。[/size]
#find / -name haproxy
[size=large] 我的haproxy.cfg文件是在/etc/haproxy/目录下,可以先备份一份在进行修改,以免出错。
[/size]
[size=x-large][b]具体haproxy.cfg配置文件内容[/b][/size]
#---------------------------------------------------------------------
# Example configuration for a possible web application. See the
# full configuration options online.
#
# http://haproxy.1wt.eu/download/1.4/doc/configuration.txt
#
#---------------------------------------------------------------------
#---------------------------------------------------------------------
# Global settings
#---------------------------------------------------------------------
global
# to have these messages end up in /var/log/haproxy.log you will
# need to:
#
# 1) configure syslog to accept network log events. This is done
# by adding the '-r' option to the SYSLOGD_OPTIONS in
# /etc/sysconfig/syslog
#
# 2) configure local2 events to go to the /var/log/haproxy.log
# file. A line like the following can be added to
# /etc/sysconfig/syslog
#
# local2.* /var/log/haproxy.log
#
log 127.0.0.1 local2
chroot /var/lib/haproxy
pidfile /var/run/haproxy.pid
maxconn 4000
use