mosquitto的安装与部署

安装

依赖cJSON安装

$ git clone https://github.com/DaveGamble/cJSON
$ cd cJSON
$ make
$ sudo 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

编译mosquitto

$ git clone https://github.com/eclipse/mosquitto
$ cd mosquitto
$ make

部署

$ mosquitto -h
mosquitto version 2.0.0

mosquitto is an MQTT v5.0/v3.1.1/v3.1 broker.

Usage: mosquitto [-c config_file] [-d] [-h] [-p port]

 -c : specify the broker config file.
        配置文件
 -d : put the broker into the background after starting.
        后台运行
 -h : display this help.
 -p : start the broker listening on the specified port.
      Not recommended in conjunction with the -c option.
        指定侦听端口,不建议与-c共用
 -v : verbose mode - enable all logging types. This overrides
      any logging options given in the config file.
        开启所有日志类型

See https://mosquitto.org/ for more information.

方案

mosquitto采用的是桥接的方式实现的伪集群,以一个主服务对多个从服务进行数据转发。 所以一但主服务异常整个群集即失效。

配置

运行