mosquitto安装

Scroll Down

参考:http://www.manongjc.com/detail/26-hhhkaxsvetgelly.html

1.下载源码包

http://mosquitto.org/files/source/

2.解压

tar zxvf mosquitto-2.0.9.tar.gz

3.进入目录编译

cd mosquitto-2.0.9
make && make install

此时可能会碰到缺少cjson文件
报错:fatal error: cjson/cJSON.h: No such file or directory

去github下载
页面:https://github.com/DaveGamble/cJSON/releases/tag/v1.7.14
下载地址:https://github.com/DaveGamble/cJSON/archive/refs/tags/v1.7.14.tar.gz
下载后解压编译

tar -xvf  cJSON-1.7.14.tar.gz
make && make install

4.备份配置文件

cp mosquitto.conf mosquitto.conf.bak
cp pwfile.example pwfile

5.配置文件

#配置允许外部访问的端口设置
listener 1883
#配置不允许匿名访问,需输入账号密码才可订阅或者发布
allow_anonymous false
#配置账号密码存放的路径
password_file /etc/mosquitto/pwfile.example
#数据持久化,默认为false
persistence true
#数据文件名称,默认为mosquitto.db
persistence_file mosquitto.db
#数据文件存放目录,默认为当前目录
persistence_location /opt
会话清除时间,会将超时的会话清除,h d w m y代表小时、天、周、月、年
persistent_client_expiration 2m

6.配置用户名密码

mosquitto_passwd pwfile 用户名

7.启动

mosquitto -d -c mosquitto.conf
  • -d后台启动

8.客户端

mqtt.fx客户端官网:http://mqttfx.jensd.de/
下载列表:http://mqttfx.jensd.de/index.php/download