mosquitto集群部署

    项目中用到了mosquitto服务,由于并发量不大,所以也没做成集群的,只做了一个备份服务。

    顺便也研究了一下简单的集群部署。

    准备2台服务器安装好mosquitto服务,选定一台是主服务器。集群的所有配置只需要再主服务器配置。

    192.168.1.100(主)

    192.168.1.101(从)

     进入安装目录,修改config.mk文件WITH_BRIDGE:=yes前面的额#号去掉

     修改mosquitto.conf文件,在Bridges块下面增加如下配置

     connection server1                                    //链接名称

     address 192.168.1.101:1883                   //从服务器地址

     topic print/# both 2 ser/ my/                       //topic 主题;both 服务器质量;ser/本地前缀;my/远程前缀;

     bridge_protocol_version mqttv311            //协议

     notifications true                                        //是否发布桥接状态信息

     cleansession true                                      //桥接断开时,是否清除远程服务器中的消息

     try_private true                                          

     start_type automatic                                  //桥接模式(automatic,lazy,once)

     以上配置好后,2台的集群就配置好了。如果要多台集群只需要增加下面的配置就行了。

     connection server1                                    //链接名称

     address 192.168.1.102:1883                   //从服务器地址

     topic print/# both 2 ser/ my/                       //topic 主题;both 服务器质量;ser/本地前缀;my/远程前缀;

     发布主题my/print/XXX

     订阅主题ser/print/#

猜你喜欢

转载自zhuangtiejun.iteye.com/blog/2404577