当前位置: 首页 > news >正文

快速搭建MQTT服务器:5步搞定

第一步安装 mosquitto

apt install mosquitto mosquitto-clients -y

设置开机自启动

systemctl start mosquitto systemctl enable mosquitto systemctl status mosquitto

第二步 编辑配置文件

vim /etc/mosquitto/mosquitto.conf

# Place your local configuration in /etc/mosquitto/conf.d/
#
# A full description of the configuration file is at
# /usr/share/doc/mosquitto/examples/mosquitto.conf.example

pid_file /run/mosquitto/mosquitto.pid

###################################################################

persistence true
persistence_location /var/lib/mosquitto/

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

include_dir /etc/mosquitto/conf.d

##################################################################

# 开启账号校验

allow_anonymous false

# 密码文件路径
password_file /etc/mosquitto/pwfile

# 允许所有网卡外部访问

listener 1883
protocol mqtt

listener 8083
protocol websockets

# 新增:WSS(安全 WebSocket)
listener 8084
protocol websockets
certfile /etc/mosquitto/certs/hvac-lab.cn_bundle.crt
keyfile /etc/mosquitto/certs/hvac-lab.cn.key

第三步 创建 MQTT 登录账号

# 创建用户admin,执行后输入密码

mosquitto_passwd -c /etc/mosquitto/pwfile admin

# 新增第二个用户(不加-c)

mosquitto_passwd /etc/mosquitto/pwfile user2

第四步 放行8083,8084端口

第五步 重启 mqtt 服务

systemctl restart mosquitto

PS: SSL证书方面的操作

# 创建证书目录

mkdir -p /etc/mosquitto/certs

cd /etc/mosquitto/certs

# 权限修改(mosquitto进程需要读取)

chown mosquitto:mosquitto /etc/mosquitto/certs/*

chmod 600 /etc/mosquitto/certs/*.key

http://www.jsqmd.com/news/1078387/

相关文章:

  • 5套AI提问万能框架,同样问题答案质量直接提升40%
  • MeTube:自托管的 yt-dlp 下载管理界面
  • G1 释放物理内存,避免长期无效占用内存
  • 企业级AI落地实操指南:Copilot Studio与Azure AI Search深度集成
  • 想住阳朔遇龙河民宿?这几家凭啥成游客首选,速来揭秘!
  • 被需要的感觉,会上瘾
  • 为什么pandas读Excel日期列全是浮点数字?
  • 2轴舵机控制板
  • LLM Evaluation 论文盘点:从静态榜单到动态、抗污染、任务化评测
  • Linux命令:zsh
  • Roblox帧率解锁终极指南:如何免费突破60FPS限制获得流畅游戏体验
  • MonetaMarkets的账户协同感够不够清楚?
  • 后端工程师转型AI第一课--Ollama与私有化大模型实战
  • 从手动配置到预设即代码
  • 激动的心颤抖的手 真的领到了8元
  • T140 风扇噪音大 竟然电池原因
  • 第5篇:《DC-DC电感啸叫排查:饱和电流选小,满载电流波形畸变》
  • 1.全面理解Mysql架构
  • go: Push Pull Pattern
  • 从任务积压到文件队列:Prometheus业务指标监控与告警指南
  • 2026企业协作网盘推荐:5款企业文档协作平台对比与选型指南
  • 神经算子与GRU-STONe在航空辐射监测中的应用
  • DCU深度技术报告_下篇_性能复盘与研发经验总结
  • PDFSlideshow使用教程,PDF转幻灯片演示工具绿色版下载
  • llamafactory gradient_checkpointing 梯度检查点 通俗完整讲解
  • STM32WB55入门教程(二)
  • 简道云智能助手实测:工单派发→报工→质检→入库,全自动流转到底靠不靠谱?
  • 状态空间模型安全风险剖析:频谱攻击、后门植入与状态饱和的攻防实践
  • NannyML无标签模型监控:实现端到端MLOps性能闭环
  • Docker网络这5种模式,你真的都搞明白了吗?