emq集群配置nginx做负载均衡

emq集群配置nginx做负载均衡

创建 EMQ X 节点集群

emqx 集群搭建

例如:

节点 IP 地址
[email protected] 192.168.1.17
[email protected] 192.168.1.18
[email protected] 192.168.1.19
配置 /etc/nginx/nginx.conf

mqtt集群搭建并使用nginx做负载均衡_亲测得结论

示例:

vim /etc/nginx/nginx.conf

http {
}

#在http外添加如下配置
stream {
  upstream stream_backend {
      zone tcp_servers 64k;
      hash $remote_addr;
      server 192.168.1.17:1883 max_fails=2 fail_timeout=30s;
      server 192.168.1.18:1883 max_fails=2 fail_timeout=30s;
      server 192.168.1.19:1883 max_fails=2 fail_timeout=30s;
  }

  server {
      listen 8883 ssl;
      status_zone tcp_server;
      proxy_pass stream_backend;
      proxy_buffer_size 4k;
      ssl_handshake_timeout 15s;
      ssl_certificate     /etc/emqx/certs/cert.pem;
      ssl_certificate_key /etc/emqx/certs/key.pem;
  }
}  

参考链接:
https://docs.emqx.cn/enterprise/v4.3/tutorial/deploy.html#%E7%A7%81%E6%9C%89%E7%BD%91%E7%BB%9C%E9%83%A8%E7%BD%B2

你可能感兴趣的:(mqtt,nginx,mqtt,emq)