centos7 mqtt服务mosquitto搭建记录

1、系统centos7.6,安装默认版本

yum install mosquitto

2、启动运行

systemctl start mosquitto

3、设置自启动

systemctl enable mosquitto

4、修改配置文件 vim /etc/mosquitto/mosquitto.conf

监听端口,默认为1883,需要修改删除前面 # 注释,改为自己的端口

listener 1883

是否启用密码,为true不需要,false需要,默认为false,如果不要用户名和密码可连接时,删除掉前面的 # 注释,后面添加true 

allow_anonymous

需要密码,配置密码文件,删除password_file 前面的 # 注释,后面添加密码配置文件

password_file /etc/mosquitto/passwordFile

拷贝创建密码文件 

cp /etc/mosquitto/pwfile.example  /etc/mosquitto/passwordfile

5、创建用户和密码

mosquitto_passwd -c /etc/mosquitto/passwd username

其中username 需要换成自己的账户名,比如admin,回车执行后,会提示输入密码和输入确认密码,完成后重启服务生效

扩展,重启服务 systemctl restart mosquitto,停止服务systemctl stop mosquitto

到此mqtt服务器搭建完成

  6、连接测试 

下载MQTTX工具进行测试连接可发布消息,https://mqttx.app/zh/downloads

如果 填写名称、IP/域名,端口,账号密码,点击Connect 连接,连接成功左侧状态 会是绿色,失败会提示,连接成功发布消息 test为主题---topic,下面输入消息内容---message,点击发送

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值