emqx 编译

EMQX源码前后端编译

下载端源码

后端: https://github.com/emqx/emqx.git (tag 6.1.0)

Docker编译

Dockerfile

FROM erlang:27.3.4.6

# 安装 Debian 依赖
RUN apt-get update && apt-get install -y \
    git build-essential bash curl unzip ca-certificates \
    libssl-dev libncurses5-dev zlib1g-dev \
    autoconf automake libtool pkg-config \
    libkrb5-dev libsasl2-dev \
    protobuf-compiler cmake build-essential  mosquitto-clients\
 && rm -rf /var/lib/apt/lists/*


# 安装最新 Rust
RUN curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y
ENV PATH="/root/.cargo/bin:${PATH}"

# 安装 rebar3
RUN curl -fsSL https://s3.amazonaws.com/rebar3/rebar3 -o /usr/local/bin/rebar3 && chmod +x /usr/local/bin/rebar3

# 安装 Elixir
ENV ELIXIR_VERSION=1.16.1
ENV OTP_VERSION=26
RUN curl -fsSL https://github.com/elixir-lang/elixir/releases/download/v${ELIXIR_VERSION}/elixir-otp-${OTP_VERSION}.zip \
    -o /tmp/elixir.zip \
 && unzip /tmp/elixir.zip -d /usr/local \
 && rm -f /tmp/elixir.zip
ENV PATH="/usr/local/elixir/bin:$PATH"

WORKDIR /workspace

RUN git config --global --add safe.directory /workspace
CMD ["bash"]

不同的 emqx 版本依赖的 erlang 镜像版本可能不同(编译时需要的内核依赖库有所不同),注意区分

The master branch tracks the latest version 5.

  • EMQX 5.4 and newer can be built with OTP 25 or 26
  • EMQX 5.9+ can be built with OTP 27

构建镜像

docker build -t emqx-build:1.0 .

运行容器

docker run -itd --name emqx-env -p 18083:18083 -p 1883:1883 -v /home/laihz/emqx/emqx:/workspace emqx-build:1.0 tail -f /dev/null

编译

cd workspace
make

编译结果

image-20231114155112689

运行

cd _build/emqx-enterprise/rel/emqx/bin
./mqx console

浏览器

http://localhost:18083/

验证

使用mosquitto客户端来进行订阅和发布测试

发布

mosquitto_pub -h 127.0.0.1 -p 1883 -t "test/topic" -m "Hello EMQX!" -u emqx -P public

image-20231114155112689

订阅和接收

mosquitto_sub -h 127.0.0.1 -p 1883 -t "test/topic" -u emqx -P public

image-20231114155112689