Linux(centos7)mosquitto(MQTT Broker)安装与配置

1.查找 mosquitto 软件包
yum list all | grep mosquitto

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

yum install https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
2.查看 mosquitto 信息
 yum info mosquitto

1)未安装时会显示如下

2)已安装后会显示如下

 3.安装 mosquitto 软件包
 yum install mosquitto

 安装后会有一次确认操作,输入"y"即可

4.查看安装结果
yum list installed | grep mosquitto

 5.测试mosquitto服务是否正常
1)打开第一个窗口启动服务
mosquitto

 2)打开第二窗口,执行"mosquitto_sub -t  主题名称",执行后会一直闪烁,继续下一步
mosquitto_sub -t /test/mqtt
3)打开第三个窗口,向主题发布消息"mosquitto_pub -t 主题名称 -m 消息内容"
mosquitto_pub -t /test/mqtt -m "hello word"
4)回到第二个窗口,会收到如下内容

 5)回到第一个窗口,会看到连接日志

 6.配置开机自启
1)查看软件开机自启情况
systemctl list-unit-files | grep mosquitto

2)使mosquitto开机自启,并再次查看自启情况
systemctl enable mosquitto

7.配置mosquitto账号密码
1)添加账号和密码
// 可以不使用pwfile.example文件,使用-c会清空密码文件,重新插入用户,最后一位是用户名
mosquitto_passwd -c /etc/mosquitto/pwfile.example mosquitto
// 不使用-c表示追加用户,最后一位是用户名
mosquitto_passwd -c /etc/mosquitto/pwfile.example mosquitto

 本人还使用的是原本的密码文件,添加的用户名是admin,回车后会输入密码,不会显示,需要盲打,回车再次确认密码。

 2)修改配置文件,编辑 /etc/mosquitto/mosquitto.conf 文件
# 设置不允许匿名登录
allow_anonymous false
# 设置账户密码文件位置绝对路径为/etc/mosquitto/pwfile.example
password_file /etc/mosquitto/pwfile.example
# 监听1883端口
listener 1883
 3)启动服务
service mosquitto start
8.远程连接(注意启用了防火墙的话需要打开1883端口),以MQTTX为例

  • 9
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值