当前位置: 首页 > 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.gsyq.cn/news/1590320.html

相关文章:

  • 2轴舵机控制板
  • 被需要的感觉,会上瘾
  • 为什么pandas读Excel日期列全是浮点数字?
  • 企业级AI落地实操指南:Copilot Studio与Azure AI Search深度集成
  • 想住阳朔遇龙河民宿?这几家凭啥成游客首选,速来揭秘!
  • go: Push Pull Pattern
  • T140 风扇噪音大 竟然电池原因
  • 第5篇:《DC-DC电感啸叫排查:饱和电流选小,满载电流波形畸变》
  • 激动的心颤抖的手 真的领到了8元
  • DCU深度技术报告_下篇_性能复盘与研发经验总结
  • PDFSlideshow使用教程,PDF转幻灯片演示工具绿色版下载
  • NannyML无标签模型监控:实现端到端MLOps性能闭环
  • 5分钟打造万能启动盘:Ventoy彻底告别重复格式化时代
  • P89LPC92x1中断与I/O配置实战:从原理到避坑指南
  • 2026命理软件付费前怎么看?八字排盘App要看使用频率和可替代成本
  • DonkeyCar存储系统深度解析:SD卡选型、ext4优化与路径陷阱
  • SaaS和低代码厂商的智能体转型路径:两场范式级转型的路线图
  • JSON Schema验证实际应用场景案例
  • HDFS javaAPI-windows的IDEA中java文件在linux中的hadoop平台运行
  • HTTPS 性能优化完全指南:从原理、硬件到架构的全链路调优实战
  • 【题解】WebGoC绘图题目精选整合集
  • OpenCloudOS Server 9 安装 Nginx 完整指南
  • 如何在老旧硬件上安装Windows 11:FlyOOBE完整技术指南与实战方案
  • 假面真贷:一场信贷伪冒申请的“全链路“围剿
  • 2026实测:高性价比AI编程工具替代方案全梳理
  • AI培训行业变化:必火AI与传统机构对比
  • 2026年车规芯片产业交流平台实力盘点:TOP5车规级半导体展会精选分析
  • 2026亚洲EMBA客观测评:科学选型与优质项目解析
  • 2026必看|AI编程软件功能深度实测:从权限踩坑到全链路开发
  • Momentum1