Linux 编译安装 Mosquitto
参考:https://www.cnblogs.com/chen1-kerr/p/7258487.html
1、下载源码
https://github.com/eclipse/mosquitto.git
2、编译源码
# 1、进入 mosquitto 文件夹
[root@localhost C++]# cd mosquitto-2.0.12
# 2、编译
[root@localhost mosquitto-2.0.12]# make && make instal
## 注: 报错
In file included from mosquitto_ctrl.c:19:0:
../../config.h:86:27: 致命错误:cjson/cJSON.h:没有那个文件或目录
# include <cjson/cJSON.h>
^
编译中断。
# 3、编译安装cJSON
[root@localhost C++]# cd cJSON
[root@localhost cJSON]# make all
[root@localhost cJSON]# make install
mkdir -p /usr/local/lib /usr/local/include/cjson
cp -a cJSON.h /usr/local/include/cjson
cp -a libcjson.so libcjson.so.1 libcjson.so.1.7.14 /usr/local/lib
cp -a cJSON_Utils.h /usr/local/include/cjson
cp -a libcjson_utils.so libcjson_utils.so.1 libcjson_utils.so.1.7.14 /usr/local/lib
3、使用
[root@localhost sbin]# pwd
/usr/local/sbin
[root@localhost sbin]# ls
mosquitto
[root@localhost sbin]#
[root@localhost local]# cd bin/
[root@localhost bin]# pwd
/usr/local/bin
[root@localhost bin]#
[root@localhost bin]# ls
mosquitto_ctrl mosquitto_passwd mosquitto_pub mosquitto_rr mosquitto_sub opencv_annotation opencv_interactive-calibration opencv_version opencv_visualisation opencv_waldboost_detector setup_vars_opencv4.sh
[root@localhost bin]#
4、问题
[root@localhost data]# mosquitto -p 1883 -c /etc/mosquitto/mosquitto.conf
1635314924: mosquitto version 2.0.12 starting
1635314924: Config loaded from /etc/mosquitto/mosquitto.conf.
1635314924: Starting in local only mode. Connections will only be possible from clients running on this machine.`
## 注意上一行信息
1635314924: Create a configuration file which defines a listener to allow remote access.
1635314924: For more details see https://mosquitto.org/documentation/authentication-methods/
1635314924: Opening ipv4 listen socket on port 1883.
1635314924: Opening ipv6 listen socket on port 1883.
1635314924: mosquitto version 2.0.12 running
修改配置文件
listener 1883
allow_anonymous true // 允许匿名访问
[root@localhost mosquitto]# mosquitto -c /etc/mosquitto/mosquitto.conf
1635315915: mosquitto version 2.0.12 starting
1635315915: Config loaded from /etc/mosquitto/mosquitto.conf.
1635315915: Opening ipv4 listen socket on port 1883.
1635315915: Opening ipv6 listen socket on port 1883.
1635315915: mosquitto version 2.0.12 running
1635315919: New connection from 192.168.16.126:58821 on port 1883.
1635315919: New client connected from 192.168.16.126:58821 as MQTT_FX_Client (p2, c1, k60).
==============================================================================
1、安装
# 1、添加 EPEL 软件库
yum install https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
# 2、查看结果
yum repolist all | grep enabled
# 3、安装mosquitto
yum list all | grep mosquitto
yum info mosquitto
yum install mosquitto
# 4、查看安装结果
yum list installed | grep mosquitto
# 5、启动
mosquitto
# 6、查看服务列表
systemctl list-unit-files --type=service