欢迎来到尧图网

客户服务 关于我们

您的位置:首页 > 健康 > 养生 > liunx CentOs7安装MQTT服务器(mosquitto)

liunx CentOs7安装MQTT服务器(mosquitto)

2025/2/2 14:13:27 来源:https://blog.csdn.net/qq_23564667/article/details/143391611  浏览:    关键词: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服务是否正常

在这里插入图片描述

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com