当前位置:网站首页>MQTT(mosquitto)基础配置
MQTT(mosquitto)基础配置
2022-07-21 05:10:00 【sunny05296】
Mosquitto服务的配置文件为 /etc/mosquitto/mosquitto.conf
关于用户认证方式 & 读写配置都在配置文件中通过相关参数配置指定,主要参数如下:
allow_anonymous 是否允许匿名访问,默认允许匿名访问
password_file 密码文件(/etc/mosquitto/pwdfile)
acl_file 访问控制列表(/etc/mosquitto/aclfile)
三者的组合配置关系如下
allow_anonymous password_file acl_file 结果
True(默认) 不配置 不配置 允许匿名方式访问
False password_file 不配置 开启用户验证机制
False password_file acl_file 开启用户验证机制,但访问控制不起作用
True password_file acl_file 1.用户和密码不为空:将自动进行用户验证 & 会受到访问控制的限制
2.用户和密码若为空:将不进行用户验证 & 会受到访问控制的限制
False 不配置 不配置 无法启动服务
配置操作:
Step1 修改监听IP和端口
# listener port-number [ip address/host name/unix socket path] 如果不修改配置,mosquitto默认监听所有IP的1883默认端口
listener 1883 0.0.0.0
有些情况下如果不修改listener,默认只监听IPv6,不监听IPv4,导致容器外面宿主机网络无法通过宿主机IP和1883远程访问(或者宿主机本地通过IP访问)容器映射出去的端口,去掉注释,明确设置监听端口(1883)和IP(0.0.0.0)后,就能访问了
Step2 修改配置:
vi /etc/mosquitto/mosquitto.conf
allow_anonymous = false
password_file = /etc/mosquitto/pwdfile
Step3 添加用户:
添加用户'test'密码'1q2w3e'
mosquitto_passwd -c /etc/mosquitto/pwdfile test
Step4 添加Topic和用户的关系,我这里就不添加了aclfile了,有需求的按需添加配置
启动服务:
nohup mosquitto -c /etc/mosquitto/mosquitto.conf &
注意:创建pwdfile文件的用户和组权限要正确(mosquitto:mosquitto)、如果未root:root会启动失败
chown -R mosquitto:mosquitto /etc/mosquitto/
启动客户端订阅测试
mosquitto_sub -h 192.168.1.100 -t top01 #会提示拒绝访问
mosquitto_sub -h 192.168.1.100 -t mtopic -u test -P 1q2w3e
边栏推荐
- Redis (vii) - encapsule la classe d'outils redis
- MySQL在线升级方案
- Redis(六) - Redis企业实战之商户查询缓存
- Concurrent programming (XXXI) - principle of reetrantreadwritelock
- 并发编程(二十三)-线程中断机制
- How to use iterative closest point ICP
- Volcano engine & SouFun: wisdom and "recommendation" behind clothing wholesale
- Metaforce: my view on the force meta universe, I will teach you to quickly understand the sliding mechanism
- 并发编程(十九)-JUC之AQS
- Solana project learning (II): Escrow
猜你喜欢
并发编程(二十四) - JMM之happens-before原则
并发编程(二十)-ReentrantLock 加锁、解锁原理
How to use iterative closest point ICP
Oracle connection table
Rust short note: Cargo specifies the dependent version
(Sword finger offer version) string inversion
peopleCode 理解组件缓存的结构和内容
Concurrent programming (30) - ThreadLocal principle and Practice
测试 SQL 的危险 | 切勿掉以轻心
CentOS7 上安装 Postgresql
随机推荐
Solana account details
Concurrent programming (XXII) -reentrantlock condition variable implementation principle
Open3d official website code learning
易语言学习笔记(三)
An implementation of NFT Market
并发编程(三十一) - ReetrantReadWriteLock 读写锁原理
Segmentation based on normal differentiation
Set function based on double array (based on solidity)
解决:未能将管道连接到虚拟机: 所有的管道范例都在使用中
Vs+qt debug is changed to release version to export records
2021-03-04
PeopleSoft概述及开发工具(application desinger)介绍
Rust short notes: solutions to four different quoted variables
基于双数组实现Set功能(基于Solidity)
NFT Market的一种实现
Peoplecode 运算符
并发编程(二十四) - JMM之happens-before原则
并发编程(三十) - ThreadLocal 原理与实践
Sushimaker and sushibar interpretation of sushiswap
在 MySQL 和 PostgreSQL 中存储三元数据