mqtt 安装

#下载mosquitto安装包
​​​​​​Download | Eclipse Mosquitto
#本地创建mqtt目录
cd /mqtt

#解压mosquitto安装包
tar -xvf mosquitto-2.0.14.tar.gz

#下载cJSON安装包
github或gitee查找cJSON包

#解压cJSON安装包
tar -xvf cJSON-master.zip

#切换到mosquitto-2.0.14目录
cd mosquitto-2.0.14

#创建目录cJSON
mkdir cJSON

#复制cJSON包文件到cJSON目录
cp -r ../cJSON-master/* ./cJSON/

#切换到cJSON目录
cd cJSON

#编译cJSON生成依赖库
make

#安装cJSON库
make install

#切换到mosquitto-2.0.14目录
cd ../

#编译mosquitto
make

#安装mosquitto
make install

#配置mosquitto
vim /etc/mosquitto/mosquitto.conf

#设置监听端口 listener 1883
#设置持久性 persistence true
#设置关闭匿名访问 allow_anonymous false
#设置允许客户端id长度为0 allow_zero_length_clientid true
#查看日志可设置输出到标准输出或指定目录 log_dest stderr
#输出日志类型 all为全部日志 log_type all
#设置用户密码存放位置 password_file /etc/mosquitto/pwdfile
#设置访问用户主题内容 acl_file /etc/mosquitto/aclfile
#引用conf.d目录下所以配置 include_dir /etc/mosquitto/conf.d

#设置用户密码
mosquitto_passwd -c pwdfile 用户名

#修改aclfile,增加用户和关联主题
user 用户名
topic 主题(#代表所有)

#启动mqtt,当前窗口查看mosquitto进程信息
mosquitto -c /etc/mosquitto/mosquitto.conf

#后台启动mqtt
mosquitto -c /etc/mosquitto/mosquitto.conf -d

#运行mosquitto_sub或mosquitto_pub提示找不到libcjson.so.1时,执行生成对应软连接
ln -s /mqtt/mosquitto-2.0.14/cJSON/libcjson.so /usr/lib/libcjson.so.1

以上,Linux环境下mqtt安装大概步骤,关于配置文件参数描述的准确性,还望有大神可以指正或补充。

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值