Mosquitto 安装、部署

mosquitto 官网

2.0.15版本为例

1.下载

cd /usr/local
wget https://mosquitto.org/files/source/mosquitto-2.0.15.tar.gz

2.解压

tar -zxvf mosquitto-2.0.15.tar.gz

3.安装依赖

apt-get install libssl-dev

安装cjson依赖

git clone https://github.com/DaveGamble/cJSON.git
cd cJSON
make && make install

4.编译安装

cd /usr/local/mosquitto-2.0.15
make && make install

5.配置文件

cp /etc/mosquitto/mosquitto.conf.example /etc/mosquitto/mosquitto.conf 

编辑

vi /etc/mosquitto/mosquitto.conf

6.配置

关闭匿名登录
找到allow_anonymous,取消#号,改为false

allow_anonymous false

配置pwfile文件位置
找到password_file,取消#号,改为pwfile.example(这个文件默认就有)

password_file /etc/mosquitto/pwfile.example

7.创建用户名密码

创建admin用户名、密码

mosquitto_passwd -c /etc/mosquitto/pwfile.example admin

会提示输入两次。

创建mosquitto用户

mosquitto_passwd /etc/mosquitto/pwfile.example mosquitto

会提示输入两次。


8.停止服务器

service mosquitto stop

因为安装完成后会自动启动

9.systemctl管理脚本

vi /usr/lib/systemd/system/Mosquitto.service
[Unit]
Description=Mosquitto
After=network.target
Wants=network.target
 
[Service]
ExecStart=/usr/sbin/mosquitto -c /etc/mosquitto/mosquitto.conf
User=root
LimitNOFILE=65535
[Install]
WantedBy=multi-user.target
systemctl start Mosquitto && systemctl enable Mosquitto

10.测试

使用命令行订阅主题

mosquitto_sub -t 'test/topic' -v

推送消息

mosquitto_pub -t 'test/topic' -m 'hello world'

11.windows下客户端

可以下载安装:
mqttx官网

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

ziqibit

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值