最近需要用到mqtt, 选择安装mosquitto。由于安装mosquitto花了我一点时间,简单记录下。安装环境是linux centos7, 其他像windows、mac或者ubuntu 参考下 https://mosquitto.org/download/ 英文官网,或者别人写的文章。
服务器建立mqtt文件夹
wget https://mosquitto.org/files/source/mosquitto-2.0.18.tar.gz
tar -xvf mosquitto-2.0.18.tar.gz
cd mosquitto-2.0.18/
make && make install
问题:安装mosquitto时报g++:命令未找到
解决方案:
安装编译工具 yum install -y gcc-c++
问题:重新执行make && make install,继续报错config.h:86:12: fatal error: cjson/cJSON.h: No such file or directory
解决方案:那就网上找cJSON包安装下, 在mqtt目录下执行安装
先确认下是否已经安装git,没有的话。yum install git
git clone https://github.com/DaveGamble/cJSON.git
cd cJSON/
make && make install
安装完