搭建EMQX Broker遇到的坑总结
安装和启动
官方提供了压缩包和二进制安装两种方式,个人比较推荐使用二进制安装方式安装,其命令如下:
curl https://repos.emqx.io/install_emqx.sh | bash
但是在执行sudo systemctl start emqx
和sudo service emqx start
时,出现错误,执行/usr/bin/emqx console
查看日志,发现是8083端口被Tomcat占用,遂关闭Tomcat服务,重新启动即可。
Dashboard的https
在/etc/emqx/plugins/emqx_dashboard.conf
中,取消注释:
dashboard.listener.https = 18084
dashboard.listener.https.keyfile = [keyfile]
dashboard.listener.https.certfile = [certfile]
而后,在Nginx的反向代理中,代理到18083端口而非18084端口
SSL/WSS
参考网址:https://www.emqx.cn/blog/emqx-server-ssl-tls-secure-connection-configuration-guide
在/etc/emqx/emqx.conf
中,设置如下内容:
listener.ssl.external.keyfile = [keyfile]
listener.ssl.external.certfile = [certfile]
listener.wss.external.keyfile = [keyfile].
listener.wss.external.certfile = [certfile]
Nginx中如下配置反向代理:
location /mqtt {
proxy_pass http://0.0.0.0:8083/mqtt;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
# client_max_body_size 35m;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
}
重启EMQX即可。