linux下MQTT订阅发布验证-mosquitto安装测试流程

本文详细介绍了,如何在linux环境搭建一个MQTT server, 并同时安装 了客户端 ,进行了mqtt消息发布、订阅验证。

mosquitto 服务端安装(ubuntu)

复制代码
#添加源
sudo apt-add-repository ppa:mosquitto-dev/mosquitto-ppa

sudo apt update 

# install mosquitto
sudo apt-get -y install  mosquitto



#修改配置文件
cat  /etc/mosquitto/mosquitto.conf
persistence true
persistence_location /var/lib/mosquitto/

log_dest file /var/log/mosquitto/mosquitto.log

include_dir /etc/mosquitto/conf.d

# start
sudo /etc/init.d/mosquitto start

mosquitto 客户端安装

复制代码
(base) WuGTech@WuGTech:~$ sudo apt-get install mosquitto-clients

验证安装效果

订阅消息

复制代码
mosquitto_sub -t 5g
#或者
mosquitto_sub -u xxx -P xxx -t 5g

#或者
mosquitto_sub -h localhost -t "5g/#" -i "client1"  -u xxx -P xxx

发布消息

复制代码
mosquitto_pub -t 5g
#或者
mosquitto_pub -u xxx -P xxx -t 5g

#或者
mosquitto_pub -h localhost -t "5g/test" -i "client2" -m "How are you?" -u xxx -P xxx

验证

复制代码
^C(base) WuGTech@WuGTech:~$ mosquitto_sub -h localhost -t "5g/#" -i "client1"  -u xxx -P xxx
How are you?

(base) WuGTech@WuGTech:~$ mosquitto_pub -h localhost -t "5g/test" -i "client3" -m "How are you?" -u xxx -P xxx
(base) WuGTech@WuGTech:~$ 

日志

复制代码
(base) WuGTech@WuGTech:~$ sudo cat /var/log/mosquitto/mosquitto.log

1750320791: New connection from ::1:40694 on port 1883.
1750320791: New client connected from ::1:40694 as client1 (p2, c1, k60, u'bruce').
1750320875: Client client1 disconnected.
1750320878: New connection from ::1:52248 on port 1883.
1750320878: New client connected from ::1:52248 as auto-0C77BCD5-EDD7-7913-D5BE-B4D5F5655632 (p2, c1, k60).
1750320895: Client auto-0C77BCD5-EDD7-7913-D5BE-B4D5F5655632 disconnected.
1750320896: New connection from ::1:36050 on port 1883.
1750320896: New client connected from ::1:36050 as auto-16E03451-D46A-55FE-BFFA-3AB710949EE2 (p2, c1, k60, u'yang').
相关推荐
我才是一卓9 分钟前
linux 安装简易 git 服务端并使用
linux·运维·git
Wanliang Li19 分钟前
AArch64虚拟化——virtio-mmio实现
linux·虚拟化·virtio·hypervisor·mmio
嵌入式-老费1 小时前
vivado hls的应用(第一个axi接口的ip)
linux·服务器·tcp/ip
旺仔.2911 小时前
Linux系统基础详解(二)
linux·开发语言·网络
x***r1511 小时前
Notepad++ 8.6 安装教程:详细步骤+自定义安装路径(附注意事项)
linux·前端·javascript
big_rabbit05021 小时前
JVM堆内存查看命令
java·linux·算法
王小义笔记2 小时前
WSL(Linux)如何安装conda
linux·运维·conda
偷懒下载原神2 小时前
【linux操作系统】信号
linux·运维·服务器·开发语言·c++·git·后端
源远流长jerry2 小时前
RDMA 传输服务详解:可靠性与连接模式的深度剖析
linux·运维·网络·tcp/ip·架构
AMoon丶2 小时前
Golang--垃圾回收
java·linux·开发语言·jvm·后端·算法·golang