编译nanomq
https://github.com/nanomq/nanomq
准备工作
gcc
sudo apt update
sudo apt install build-essential
gcc --version
cmake
# 安装依赖工具
sudo apt install ca-certificates curl gnupg
# 下载并添加 Kitware 的 GPG 密钥
curl -fsSL https://apt.kitware.com/keys/kitware-archive-latest.asc | sudo gpg --dearmor -o /usr/share/keyrings/kitware-archive-keyring.gpg
# 添加仓库到源列表
echo "deb [signed-by=/usr/share/keyrings/kitware-archive-keyring.gpg] https://apt.kitware.com/ubuntu/ $(lsb_release -cs) main" | sudo tee /etc/apt/sources.list.d/kitware.list
# 更新包列表
sudo apt update
sudo apt install cmake
cmake --version
下载编译
git clone https://github.com/emqx/nanomq.git
cd nanomq
git submodule update --init --recursive
mkdir build && cd build
cmake -DNNG_ENABLE_QUIC=ON \
-DNANOMQ_TESTS=ON \
-DNNG_ENABLE_TLS=ON \
-DBUILD_ZMQ_GATEWAY=OFF \
-DBUILD_NFTP=OFF \
-DBUILD_DDS_PROXY=OFF \
-DENABLE_JWT=ON \
-DNNG_ENABLE_SQLITE=ON \
-DDEBUG=ON \
-DASAN=ON \
-DDEBUG_TRACE=ON \
..
编译
make
make install
nng依赖
安装依赖
sudo apt update
sudo apt install -y cmake gcc git make
从源码编译安装 NNG
git clone https://github.com/nanomsg/nng.git
cd nng
mkdir build && cd build
cmake ..
make -j$(nproc)
sudo make install
sudo ldconfig # 更新动态链接库缓存
开机启动
vi /etc/systemd/system/nanomq.service
[Unit]
Description=NanoMQ MQTT Broker
After=network.target
[Service]
Type=simple
ExecStart=/data/nanomq/build/nanomq/nanomq start --conf /data/nanomq/etc/nanomq.conf
Restart=on-failure
User=root
Group=root
WorkingDirectory=/data/nanomq/build/nanomq
[Install]
WantedBy=multi-user.target
sudo systemctl daemon-reload
sudo systemctl enable nanomq
sudo systemctl start nanomq
sudo systemctl status nanomq
journalctl -u nanomq.service -b
配置
- 3个端口 tpc ws http
- http的账号密码
-
mqtt的账号和主题设置
auth { allow_anonymous = false no_match = allow deny_action = ignore cache = { max_size = 32 ttl = 1m } password = {include "/etc/nanomq_pwd.conf"} acl = {include "/etc/nanomq_acl.conf"} }
{"permit": "allow", "username": "#", "action": "pubsub", "topics": ["up"]}
{"permit": "allow", "username": "#", "action": "pubsub", "topics": ["down"]}
{"permit": "deny"}
]