MQTT haproxy 负载均衡代理服务



https://github.com/lelylan/haproxy-mqtt.git 

实验环境:

       两台Ubuntu 14 虚拟机:

      第一台ubuntu设备为代理服务器     :

             ubuntu 安装 haproxy 代理服务器

      第二台ubuntu设备为 activemq 服务:

             ubuntu 安装activemq 消息服务器

           

 修改文件   haproxy.cfg   :   

  global
  ulimit-n 9999
  maxconn 9999
  maxpipes 9999
  tune.maxaccept 500
  log 127.0.0.1 local0
  log 127.0.0.1 local1 notice
  chroot /var/lib/haproxy
  user haproxy
  group haproxy

defaults
  log global
  mode http
  option dontlognull
  timeout connect 5000ms
  timeout client 50000ms
  timeout server 50000ms
  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 stats :80
  stats enable
  stats uri / # must be present to see the logs
  stats auth admin:admin

listen mqtt
  bind *:1883
  #bind *:8883 ssl crt /certs/lelylan-mqtt.pem
  mode tcp
  #Use this to avoid the connection loss when client subscribed for a topic and its idle for sometime
  option clitcpka # For TCP keep-alive
  timeout client 3h #By default TCP keep-alive interval is 2hours in OS kernal, 'cat /proc/sys/net/ipv4/tcp_keepalive_time'
  timeout server 3h #By default TCP keep-alive interval is 2hours in OS kernal
  option tcplog
  balance leastconn
  server node 192.168.253.161:1883 check   #  192.168..253.161 为 activemq 消息服务IP   
 # server mosca_1 178.62.122.204:1883 check
 # server mosca_2 178.62.104.172:1883 check

启动 haproxy 服务

  ./restart.bash

启动 activemq 服务:

  ~/mqtt/apache-activemq-5.14.5$ ./bin/activemq console

win7 客户端

String user = env("APOLLO_USER", "admin");
 String password = env("APOLLO_PASSWORD", "admin");
// String host = env("APOLLO_HOST", "localhost");
 String host = env("APOLLO_HOST", "192.168.253.134"); // 192.168.253.134 haproxy 服务器IP
// int port = Integer.parseInt(env("APOLLO_PORT", "61613"));
 int port = Integer.parseInt(env("APOLLO_PORT", "1883"));
// final String destination = arg(args, 0, "/topic/1/OOOOOOOOOO/aaaa");
 final String destination = arg(args, 0, "topic");




  



  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值