安装

EMQX 目前支持的操作系统:

  • CentOS 7 (EL7)
  • CentOS 8 (EL8)
  • Raspbian 10
  • Debian 9
  • Debian 10
  • Ubuntu 16.04
  • Ubuntu 18.04
  • Ubuntu 20.04
  • macOS 10
  • Windows Server 2019

RPM/DEB包安装 (Linux)

  1. 访问 emqx.com安装 - 图1 (opens new window)Github安装 - 图2 (opens new window) 下载EMQX 版本的二进制包。

  2. 安装 EMQX Broker,将下面的路径更改为您下载 EMQX 软件包的路径。

    • RPM 包:

      1. $ sudo yum install emqx-cenots7-v4.0.0.x86_64.rpm
    • DEB 包:

      1. # for ubuntu/debian
      2. $ sudo apt install ./emqx-ubuntu18.04-v4.0.0_amd64.deb
      3. $ sudo apt install ./emqx-debian10-v4.0.0_amd64.deb
  3. 启动 EMQX Broker

    • 直接启动

      1. $ emqx start
      2. emqx 4.0.0 is started successfully!
      3. $ emqx_ctl status
      4. Node 'emqx@127.0.0.1' is started
      5. emqx v4.0.0 is running
    • systemctl 启动

      1. $ sudo systemctl start emqx
    • service 启动

      1. $ sudo service emqx start
  4. 停止 EMQX Broker

    1. $ emqx stop
    2. ok
  5. 卸载 EMQX Broker

    • DEB 包:

      1. $ sudo apt remove --purge emqx
    • RPM 包:

      1. $ sudo yum remove emqx

ZIP 压缩包安装 (Linux、MacOS、Windows)

注意

ZIP包适用于测试和热更,如果不知道如何手动安装所有可能的运行时依赖,请勿在生产环境中使用

  1. 访问 emqx.com安装 - 图3 (opens new window)Github安装 - 图4 (opens new window) 下载要安装的 EMQX 版本的 zip 包。

  2. 解压程序包

    1. $ unzip emqx-ubuntu18.04-v4.0.0.zip
  3. 启动 EMQX Broker

    1. $ cd ./emqx
    2. $ ./bin/emqx start
    3. emqx 4.0.0 is started successfully!
    4. $ ./bin/emqx_ctl status
    5. Node 'emqx@127.0.0.1' is started
    6. emqx v4.0.0 is running
  4. 停止 EMQX Broker

    1. $ ./bin/emqx stop
    2. ok
  5. 卸载 EMQX Broker

    直接删除 EMQX 目录即可

通过 Docker 运行 (包含简单的 docker-compose 集群)

运行单个容器

  1. 获取 docker 镜像

  2. 启动 docker 容器

    1. $ docker run -d --name emqx -p 1883:1883 -p 8081:8081 -p 8083:8083 -p 8883:8883 -p 8084:8084 -p 18083:18083 emqx/emqx:v4.0.0

使用 docker-compose 创建简单的 static 集群

  1. 创建 docker-compose.yaml 文件

    1. version: '3'
    2. services:
    3. emqx1:
    4. image: emqx/emqx:v4.0.0
    5. environment:
    6. - "EMQX_NAME=emqx"
    7. - "EMQX_HOST=node1.emqx.io"
    8. - "EMQX_CLUSTER__DISCOVERY=static"
    9. - "EMQX_CLUSTER__STATIC__SEEDS=emqx@node1.emqx.io, emqx@node2.emqx.io"
    10. healthcheck:
    11. test: ["CMD", "/opt/emqx/bin/emqx_ctl", "status"]
    12. interval: 5s
    13. timeout: 25s
    14. retries: 5
    15. networks:
    16. emqx-bridge:
    17. aliases:
    18. - node1.emqx.io
    19. emqx2:
    20. image: emqx/emqx:v4.0.0
    21. environment:
    22. - "EMQX_NAME=emqx"
    23. - "EMQX_HOST=node2.emqx.io"
    24. - "EMQX_CLUSTER__DISCOVERY=static"
    25. - "EMQX_CLUSTER__STATIC__SEEDS=emqx@node1.emqx.io, emqx@node2.emqx.io"
    26. healthcheck:
    27. test: ["CMD", "/opt/emqx/bin/emqx_ctl", "status"]
    28. interval: 5s
    29. timeout: 25s
    30. retries: 5
    31. networks:
    32. emqx-bridge:
    33. aliases:
    34. - node2.emqx.io
    35. networks:
    36. emqx-bridge:
    37. driver: bridge
  2. 启动 docker-compose 集群

    1. $ docker-compose -p my_emqx up -d
  3. 查看集群

    1. $ docker exec -it my_emqx_emqx1_1 sh -c "emqx_ctl cluster status"
    2. Cluster status: #{running_nodes => ['emqx@node1.emqx.io','emqx@node2.emqx.io'],
    3. stopped_nodes => []}

更多关于 EMQX Docker 的信息请查看 Docker Hub安装 - 图6 (opens new window)Github安装 - 图7 (opens new window)

通过 Helm 安装并集群 (K8S、K3S)

  1. 添加 helm 仓库
  1. $ helm repo add emqx https://repos.emqx.io/charts
  2. $ helm repo update
  1. 查询 EMQX Broker
  1. helm search repo emqx
  2. NAME CHART VERSION APP VERSION DESCRIPTION
  3. emqx/emqx v4.0.0 v4.0.0 A Helm chart for EMQX
  4. emqx/emqx-ee v4.0.0 v4.0.0 A Helm chart for EMQX
  5. emqx/kuiper 0.1.1 0.1.1 A lightweight IoT edge analytic software
  1. 启动 EMQX 集群
  1. $ helm install my-emqx emqx/emqx
  1. 查看 EMQX 集群情况
  1. $ kubectl get pods
  2. NAME READY STATUS RESTARTS AGE
  3. my-emqx-0 1/1 Running 0 56s
  4. my-emqx-1 1/1 Running 0 40s
  5. my-emqx-2 1/1 Running 0 21s
  6. $ kubectl exec -it my-emqx-0 -- emqx_ctl cluster status
  7. Cluster status: #{running_nodes =>
  8. ['my-emqx@my-emqx-0.my-emqx-headless.default.svc.cluster.local',
  9. 'my-emqx@my-emqx-1.my-emqx-headless.default.svc.cluster.local',
  10. 'my-emqx@my-emqx-2.my-emqx-headless.default.svc.cluster.local'],
  11. stopped_nodes => []}

源码编译安装

  1. 获取源码
  1. $ git clone https://github.com/emqx/emqx.git
  1. 切换到最近的 Tag
  1. $ cd emqx
  2. $ git checkout $(git describe --abbrev=0 --tags)
  1. 编译
  1. $ make
  1. 启动 EMQX Broker
  1. $ cd _build/emqx/rel/emqx
  2. $ ./bin/emqx start
  3. EMQX Broker 4.3-beta.1 is started successfully!
  4. $ ./bin/emqx_ctl status
  5. Node 'emqx@127.0.0.1' is started
  6. emqx 4.3-beta.1 is running