Skip to content

EMQX 安装配置

EMQX 安装

需要在云服务器上安装 mqtt 服务器,用于 mqtt 通信。

服务器购买配置

作为案例,我们购买了一台腾讯云服务器,并安装了ubuntu 18.04系统,在这个基础上,我们选择 emqx 作为 mqtt 服务器进行安装配置。

Ubuntu | EMQX 5.0 文档

方式一:

下载适合操作系统的固定版本的安装包:EMQX 版本:5.0.10

推荐该种方式,后续 SSL 安全证书配置也是基于这种方式做的演示

shell
wget https://www.emqx.com/zh/downloads/broker/5.0.10/emqx-5.0.10-ubuntu18.04-amd64.deb

通过命令进行安装

shell
sudo apt install ./emqx-5.0.10-ubuntu18.04-amd64.deb

方式二:

1)通过以下命令配置 EMQX Apt 源:这种方式默认安装最新版本的

shell
curl -s https://assets.emqx.com/scripts/install-emqx-deb.sh | sudo bash

2)运行以下命令安装 EMQX:

shell
sudo apt-get install emqx

3)运行以下命令启动 EMQX:

shell
sudo systemctl start emqx

输入地址访问服务器,默认账号:admin,密码:public

如果域名访问则一定需要备案!

点击 websocket 客户端,选择连接

说明已成功安装 emqx

EMQX 安全证书配置

为了能用小程序访问 MQTT 服务器,需要配置安全证书,这个需要申请域名并且进行备案。

以阿里云域名证书配置为例,进入证书管理页面,创建证书

点击证书申请,填写信息,提交审核

审核通过之后,下载证书,选择其他证书类型

解压缩下载好的文件夹,并重命名文件

接着远程登陆服务器,将证书文件拖到目录:/etc/emqx/certs/

接着修改配置文件:/etc/emqx/emqx.conf

修改成自己证书的名字

提供配置好的 emqx.conf 参考

shell
## NOTE:
## Configs in this file might be overridden by:
## 1. Environment variables which start with 'EMQX_' prefix
## 2. File $EMQX_NODE__DATA_DIR/configs/cluster-override.conf
## 3. File $EMQX_NODE__DATA_DIR/configs/local-override.conf
##
## The *-override.conf files are overwritten at runtime when changes
## are made from EMQX dashboard UI, management HTTP API, or CLI.
## All configuration details can be found in emqx.conf.example

node {
  name = "emqx@127.0.0.1"
  cookie = "emqxsecretcookie"
  data_dir = "/var/lib/emqx"
}

log {
  file_handlers.default {
    level = warning
    file = "/var/log/emqx/emqx.log"
  }
}

cluster {
  name = emqxcl
  discovery_strategy = manual
}

listeners.tcp.default {
  bind = "0.0.0.0:1883"
  max_connections = 1024000
}

listeners.ssl.default {
  bind = "0.0.0.0:8883"
  max_connections = 512000
  ssl_options {
    keyfile = "/etc/emqx/certs/esp.icce.top.key"
    certfile = "/etc/emqx/certs/esp.icce.top.pem"
    cacertfile = "/etc/emqx/certs/esp.icce.top.pem"
  }
}

listeners.ws.default {
  bind = "0.0.0.0:8083"
  max_connections = 1024000
  websocket.mqtt_path = "/mqtt"
}

listeners.wss.default {
  bind = "0.0.0.0:8084"
  max_connections = 512000
  websocket.mqtt_path = "/mqtt"
  ssl_options {
    keyfile = "/etc/emqx/certs/esp.icce.top.key"
    certfile = "/etc/emqx/certs/esp.icce.top.pem"
    cacertfile = "/etc/emqx/certs/esp.icce.top.pem"
  }
}

# listeners.quic.default {
#  enabled = true
#  bind = "0.0.0.0:14567"
#  max_connections = 1024000
#  keyfile = "/etc/emqx/certs/esp.icce.top.key"
#  certfile = "/etc/emqx/certs/esp.icce.top.pem"
#}

dashboard {
    listeners.http {
        bind = 18083
    }
    default_username = "admin"
    default_password = "public"
}

authorization {
  deny_action = ignore
  no_match = allow
  sources =  [
    {
      type = file
      enable = true
      # This file is immutable to EMQX.
      # Once new rules are created from dashboard UI or HTTP API,
      # the file 'data/authz/acl.conf' is used instead of this one
      path = "/etc/emqx/acl.conf"
    }
  ]
}

include emqx_enterprise.conf

可以将文件拖动到电脑中进行下载,修改完后再拖动上传回去

接着输入指令重启系统,必须要重启才能使安全证书生效

shell
sudo reboot

接着输入指令重启 emqx

shell
emqx stop

emqx start

返回 websocket 客户端,勾选 TLS,选择连接,若能成功连上,说明安全证书已成功配置

如果需要卸载 emqx,可以输入指令

shell
apt remove emqx

powered by 天人之际工作室