emq集群配置nginx做负载均衡
创建 EMQ X 节点集群
例如:
节点 | IP 地址 |
---|---|
emqx@192.168.1.17 | 192.168.1.17 |
emqx@192.168.1.18 | 192.168.1.18 |
emqx@192.168.1.19 | 192.168.1.19 |
配置 /etc/nginx/nginx.conf
示例:
shell
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#私有网络部署