原创 NXP iMX8MP ARM 平台 EMQX 部署测试

2025-4-2 11:12 10 0 分类: MCU/ 嵌入式

By Toradex秦海

1). 简介

EMQX 是一款基于 Erlang/OTP 平台开发的开源 MQTT 消息服务器,广泛应用于物联网(IoT)领域,以实现设备到服务器以及服务器到设备的消息传递与控制文本就基于NXP i.MX8M Plus ARM 处理器平台,通过在 Yocto Linux BSP 中集成 Docker 环境来部署测试 EMQX

 

本文所演示的平台来自于 Toradex Verdin i.MX8MP 嵌入式平台

 

 

2. 准备

a). Verdin i.MX8MP ARM核心版配合Dahlia载板,并连接调试串口用于测试

 

 

3). Verdin i.MX8MP Yocto Linux 编译部署

a). 首先参考这里说明创建Yocto/Openembedded 编译框架当前最新版本是对应于Toradex Yocto Linux BSP 7.x 版本的 scarthgap-7.x.y branch

 

b). 增加包含 Docker 支持的 meta-virtualization layer

-------------------------------

### add meta-virtualization ###

$ cd <OE_ROOT_PATH>/layers

$ git clone -b scarthgap git://git.yoctoproject.org/meta-virtualization

 

### add meta-clang layer for PySide6 ###

$ git clone -b kirkstone https://github.com/kraj/meta-clang.git

-------------------------------

 

c). 创建定制化 layer meta-customer-demos ,用于添加 Docker 需要的额外修改和配置,首先添加 layer 配置文件

---------------------------------------

$ mkdir -p ../oe_core/layers/meta-customer-demos/conf

$ cd .../oe_core/layers/meta-customer-demos/conf

### create layer.conf file ###

# We have a conf and classes directory, append to BBPATH

BBPATH .= ":${LAYERDIR}"

 

# We have recipes-* directories, add to BBFILES

BBFILES += "${LAYERDIR}/recipes-*/*/*.bb ${LAYERDIR}/recipes-*/*/*.bbappend"

 

BBFILE_COLLECTIONS += "customer-demos"

BBFILE_PATTERN_customer-demos = "^${LAYERDIR}/"

BBFILE_PRIORITY_customer-demos = "24"

 

# Let us add layer-specific bbappends which are only applied when that

# layer is included in our configuration

BBFILES += "${@' '.join('${LAYERDIR}/%s/recipes*/*/*.bbappend' % layer \

for layer in BBFILE_COLLECTIONS.split())}"

# Add layer-specific bb files too

BBFILES += "${@' '.join('${LAYERDIR}/%s/recipes*/*/*.bb' % layer \

for layer in BBFILE_COLLECTIONS.split())}"

 

LAYERDEPENDS_customer-demos = " \

core \

yocto \

openembedded-layer gnome-layer multimedia-layer networking-layer \

"

LAYERSERIES_COMPAT_customer-demos = "hardknott honister kirkstone scarthgap"

---------------------------------------

 

d). 在定制化 layer meta-customer-demos 下面添加 Docker bbapend 文件,配置 Docker 可以启动自动加载

---------------------------------------

$ cd .../oe_core/layers/meta-customer-demos/

$ mkdir -p recipes-containers/docker

$ cd recipes-containers/docker

### cteate docker-moby_git.bbappend file ###

FILES:${PN} += "${sysconfdir}/systemd/system/docker.service"

 

SYSTEMD_SERVICE:${PN} = "docker.service"

SYSTEMD_AUTO_ENABLE:${PN} = "enable"

---------------------------------------

 

e). Docker daemon 启动需要额外比如 IPSec/Netfilter/NF_table 等网络相关的 Kernel Modules,因此如下增加额外的 Linux Kernel 配置。

---------------------------------------

$ cd .../oe_core/layers/meta-customer-demos/

$ mkdir -p recipes-kernel/linux/

$ cd recipes-kernel/linux

### cteate linux-toradex%.bbappend file ###

SRCREV_meta-custom = "1e293f75e7e5569f0d86d752fbf4180dd3fac6eb"

SRCREV_meta-custom:use-head-next = "${AUTOREV}"

 

KMETABRANCH = "scarthgap-7.x.y"

KMETAVIRTUALITION = "kernel-meta-custom"

 

KMETAREPOSITORY="github.com/toradex/toradex-kernel-cache.git"

KMETAPROTOCOL="https"

 

SRC_URI += "git://${KMETAREPOSITORY};protocol=${KMETAPROTOCOL};type=kmeta;name=meta-custom;branch=${KMETABRANCH};destsuffix=${KMETAVIRTUALITION}"

 

## Compose additional .scc file including docker requirement and include it to our build.

KERNEL_FEATURES += "bsp/${MACHINE}-${LINUX_KERNEL_TYPE}-torizon.scc"

---------------------------------------

 

f). 最终完整 meta-customer-demos layer 文件结构如下

meta-customer-demos

├── conf

│   └── layer.conf

├── recipes-containers

│   └── docker

│       └── docker-moby_git.bbappend

└── recipes-kernel

└── linux

└── linux-toradex%.bbappend

 

 

g). 修改 bblayers.conf local.conf 文件

-------------------------------

### modify bblayer.conf###

--- a/build/conf/bblayers.conf  

+++ b/build/conf/bblayers.conf  

@@ -34,7 +34,7 @@

${TOPDIR}/../layers/meta-openembedded/meta-python \

${TOPDIR}/../layers/meta-freescale-distro \

${TOPDIR}/../layers/meta-toradex-demos \

+  ${TOPDIR}/../layers/meta-virtualization\

+  ${TOPDIR}/../layers/meta-customer-demos\

\

\

${TOPDIR}/../layers/meta-toradex-distro \

 

### add below to local.conf ###

# enable meta-virtualization

DISTRO_FEATURES:append = " virtualization"

 

# enable docker support

IMAGE_INSTALL:append = " docker docker-compose"

 

# add Freescale EULA

ACCEPT_FSL_EULA = "1"

-------------------------------

 

h). 编译Yocto Linux image

-------------------------------

### compile Reference-Multimedia image###

$ MACHINE="verdin-imx8mp" bitbake tdx-reference-multimedia-image

-------------------------------

 

i). Yocto Linux image部署

参考这里通过Toradex Easy installer将上面编译好的image更新部署到模块

 

 

4). EMQX 部署测试

a). 关于EMQX 的更多说明和介绍可以参考如下

https://docs.emqx.com/en/emqx/latest/getting-started/getting-started.html

 

b). Verdin i.MX8MP 设备上面通过如下命令确认 Docker daemon 已经成功运行

-------------------------------

root@verdin-imx8mp-06849028:~# systemctl is-enabled docker.service

enabled

root@verdin-imx8mp-06849028:~# systemctl status docker.service                                

* docker.service - Docker Application Container Engine

Loaded: loaded (/usr/lib/systemd/system/docker.service; enabled; preset: enabled)

Active: active (running) since Fri 2025-03-28 01:54:37 UTC; 5h 16min ago

TriggeredBy: * docker.socket

Docs: https://docs.docker.com

Main PID: 685 (dockerd)

Tasks: 19

Memory: 99.6M (peak: 146.5M)

CPU: 14.376s

CGroup: /system.slice/docker.service

`-685 /usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock

 

...

Mar 28 01:54:37 verdin-imx8mp-06849028 dockerd[685]: time="2025-03-28T01:54:37.583078000Z" level=info msg="Daemon has completed initialization"

Mar 28 01:54:37 verdin-imx8mp-06849028 dockerd[685]: time="2025-03-28T01:54:37.684308375Z" level=info msg="API listen on /run/docker.sock"

Mar 28 01:54:37 verdin-imx8mp-06849028 systemd[1]: Started Docker Application Container Engine.

-------------------------------

 

c). 参考这里通过如下命令安装并运行EMQX ARM64 Docker Image,本文采用 offline 方式,如果网络条件允许也可以 online 方式安装。

-------------------------------

### download

$ wget https://www.emqx.com/en/downloads/broker/5.8.6/emqx-5.8.6-docker-arm64.tar.gz

### install

$ docker load < emqx-5.8.6-docker-arm64.tar.gz

###

$ docker run -d --name emqx -p 1883:1883 -p 8083:8083 -p 8084:8084 -p 8883:8883 -p 18083:18083 emqx/emqx:5.8.6

-------------------------------

 

d). 此时在开发主机,通过浏览器通过如下网址可以查看已经运行的EMQX 控制台页面,默认登录信息为 admin/public,可以后续自行更改密码。

-------------------------------

http://<verdin_imx8mp_ip_address>:18083/

-------------------------------

 

 

e). 通过如下自带的基于Websocket MQTT 客户端进行测试

 

./ 进入客户端后,首先连接 Verdin i.MX8MP 核心节点设备

 

./ 然后再订阅默认的 testtopic主题

 

./ 最后可以修改 payload 内容后,点击发布,可以看到核心节点可以正常接收数据

 

5). 总结

本文基于NXP i.MX8MP 处理器简单演示了通过 Docker 环境部署运行 EMQX MQTT 消息服务器。

PARTNER CONTENT

文章评论0条评论)

登录后参与讨论
我要评论
0
0
关闭 站长推荐上一条 /3 下一条