mosquitto安装、配置、测试、paho.mqtt-spy安装

本文介绍如何在 Ubuntu 上安装和配置 Mosquitto 消息代理软件,包括安全配置、用户管理及通过终端和图形界面进行测试的方法。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

mosquitto是一款实现了消息推送协议 MQTT v3.1 的开源消息代理软件,提供轻量级的,支持可发布/可订阅的的消息推送模式,使设备对设备之间的短消息通信变得简单,比如现在应用广泛的低功耗传感器,手机、嵌入式计算机、微型控制器等移动设备。

(一) Ubuntu 安装 mosquitto

apt-add-repository ppa:mosquitto-dev/mosquitto-ppa
apt-get update
apt-get install mosquitto
apt-get install mosquitto-clients

(二) 修改/etc/mosquitto/mosquitto.conf

pid_file /var/run/mosquitto.pid

persistence true
persistence_location /var/lib/mosquitto/

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

# 将其他配置配置到此处方便管理
include_dir /etc/mosquitto/conf.d

(三) mosquitto配置文件[详细参考]

安全配置 (/etc/mosquitto/conf.d/security.conf)

# =================================================================
# Security
# =================================================================
# 禁止匿名用户访问
allow_anonymous false

# 用户密码配置文件,路径为绝对路径
password_file /etc/mosquitto/pwdfile.example

# 访问规则列表
acl_file /etc/mosquitto/aclfile.example

acl_file (/etc/mosquitto/aclfile.example)

# 用户限制
user <username>
# 用户可以访问的topic和权限
topic [read|write] <topic>

(四) 新建用户

# 用户格式为<username>:<password>
# 第一次创建用户,再次创建会覆盖原文件
mosquitto_passwd -c /etc/mosquitto/pwdfile.example <userName>
# 新增用户
mosquitto_passwd -U /etc/mosquitto/pwdfile.example <userName>

(五) 启动服务

service mosquitto start
or
mosquitto -c /etc/mosquitto/mosquitto.conf -d

(六) 终端测试

订阅 mosquitto_sub -t <topic> -u <username> -P <password>

mosquitto_sub -t mqtt   -u hao -P 123456

发布 mosquitto_pub -t <topic> -m <message> -u <username> -P <password>

mosquitto_pub -t mqtt -m message  -u hao -P 123456

(七) paho.mqtt-spy图形化界面测试

下载连接 https://github.com/eclipse/paho.mqtt-spy/releases/download/1.0.1-beta5/mqtt-spy-1.0.1-beta-b5-jar-with-dependencies.jar

启动paho.mqtt-spy

java -jar mqtt-spy-1.0.1-beta-b5-jar-with-dependencies.jar

paho.mqtt-spy

paho.mqtt-spy

(八) 创建paho.mqtt-spy桌面图标

vim ~/.local/share/applications/mqtt-spy.desktop
# 添加以下内容
[Desktop Entry]
Version=1.0
Name=mqtt-spy
Comment=mqtt-spy
Type=Application
Categories=Development;
Exec=java -jar 安装目录/paho.mqtt-spy/jar/mqtt-spy-1.0.1-beta-b5-jar-with-dependencies.jar
Terminal=false
Icon=安装目录/paho.mqtt-spy/mqtt-spy/src/main/resources/ui/images/mqtt-spy-logo.png

转载于:https://my.oschina.net/hhjian/blog/1550460

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值