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");




  



你可能感兴趣的:(MQTT haproxy 负载均衡代理服务)