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

liunx CentOs7安装MQTT服务器(mosquitto)

查找 mosquitto 软件包

yum list all | grep mosquitto

在这里插入图片描述

出现以上两个即可进行安装,如果没有出现则需要安装EPEL软件库。

yum install https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm

查看 mosquitto 信息

 yum info mosquitto

在这里插入图片描述

安装 mosquitto 软件包

# 安装mosquittoyum install mosquitto # 查看安装结果
yum list installed | grep mosquitto## 测试mosquitto服务是否正常
# 打开第一个窗口启动服务
mosquitto
# 打开第二窗口,执行"mosquitto_sub -t  主题名称",执行后会一直闪烁,继续下一步
mosquitto_sub -t /test/mqtt
# 打开第三个窗口,向主题发布消息"mosquitto_pub -t 主题名称 -m 消息内容"
mosquitto_pub -t /test/mqtt -m "hello xiaowu"

在这里插入图片描述

在这里插入图片描述
在这里插入图片描述

配置开机自启

# 查看软件开机自启情况
systemctl list-unit-files | grep mosquitto# 使mosquitto开机自启,并再次查看自启情况
systemctl enable mosquitto

在这里插入图片描述

配置mosquitto文件和账号密码

1. 修改配置文件,编辑 /etc/mosquitto/mosquitto.conf 文件
# 编辑 /etc/mosquitto/mosquitto.conf 文件 
vim /etc/mosquitto/mosquitto.conf# 设置不允许匿名登录
allow_anonymous false
# 设置账户密码文件位置绝对路径为/etc/mosquitto/pwfile.example
password_file /etc/mosquitto/pwfile.conf
# 监听1883端口
listener 1883
2. 添加账号和密码
# 可以不使用pwfile.example文件,使用-c会清空密码文件,重新插入用户,最后一位是用户名
mosquitto_passwd -c /etc/mosquitto/pwfile.conf mosquitto
# 不使用-c表示追加用户,最后一位是用户名
mosquitto_passwd -c /etc/mosquitto/pwfile.conf mosquitto

在这里插入图片描述

启动服务

service mosquitto start
# 其他命令
systemctl start mosquitto     # 启动 Mosquitto 服务
systemctl stop mosquitto      # 停止 Mosquitto 服务
systemctl restart mosquitto   # 重新启动 Mosquitto 服务
systemctl status mosquitto    #检查服务器状态

在这里插入图片描述

测试mosquitto服务是否正常

在这里插入图片描述

http://www.lryc.cn/news/474819.html

相关文章:

  • 【银河麒麟高级服务器操作系统】虚拟机lvm分区丢失现象分析及解决建议
  • Android 原子性类型都有哪些
  • MySQL(上)
  • ffplay 实现视频流中音频的延迟
  • CSDN资源变现
  • Rembg模型构建教程
  • 向量的基础知识和矩阵向量的坐标旋转
  • GeoSever发布图层(保姆姬)
  • AI 大模型的发展趋势是怎样的?
  • win10怎么关掉自动更新-小白必看
  • 大学城水电资源管理:Spring Boot解决方案
  • 躺平成长-运营日记-第三天
  • 智慧税务管理:金融企业报税效率与合规性提升
  • linux之网络子系统-用户层接收数据包之同步阻塞方案
  • 【天线&空中农业】花生霉变检测系统源码&数据集全套:改进yolo11-LVMB
  • 全志A133 android10 LVDS幅值调节
  • 弃用 RestTemplate,来了解一下官方推荐的 WebClient !
  • 西圣、倍思、品胜电容笔孰强孰弱?多维度对比测评三款平替电容笔
  • VS2022配置调试Qt源代码
  • Python 的 Pygame 库来开发一个游戏
  • diffusion model 学习笔记
  • 【C++题解】1967. 输出字符的ascii码
  • Java入门9——类和对象+this+构造方法
  • Django目录结构最佳实践
  • npm run dev 报错PS ‘vite‘ 不是内部或外部命令,也不是可运行的程序或批处理文件。
  • 后端:Spring、Spring Boot-实例化Bean依赖注入(DI)
  • C++ 数据结构 静态顺序表、动态顺序表。
  • QML旋转选择器组件Tumbler
  • 在工作中常用到的 Linux 命令总结
  • 反射、枚举和lambda表达式