MQTT最新版本1.6.9 主从安装配置

1.安装包下载

wget https://mosquitto.org/files/source/mosquitto-1.6.9.tar.gz
备注:最新版本 https://mosquitto.org/files/source/mosquitto-2.0.18.tar.gz 资源地址 https://mosquitto.org/files/source/

2.安装

tar -zxvf mosquitto-1.6.9.tar.gz  
yum install gcc cc aclocal autoconf automake autoheader makeinfo gcc-c++ cmake openssl-devel libuuid-devel libxml2-devel.x86_64 libxslt-devel.x86_64 json-c-devel -y  

$ useradd -d /home/mqtt/ -m mosquitto
$ passwd mosquitto #输入密码
$ cd /home/mosquitto-1.6.9/  
$ vim config.mk #修改config.mk的配置路径,将前缀prefix?=/usr/local为prefix?=/home/mqtt,保存  
$ make && make install  
$ mkdir -p /home/mqtt/conf/  
$ cp /home/mosquitto-1.6.9/aclfile.example /home/mqtt/conf/aclfile  
$ cp /home/mosquitto-1.6.9/mosquitto.conf /home/mqtt/conf/mosquitto.conf  
$ cp /home/mosquitto-1.6.9/pskfile.example /home/mqtt/conf/pskfile  
$ cp /home/mosquitto-1.6.9/pwfile.example /home/mqtt/conf/pwfile
$ chown -R mosquitto:mosquitto /home/mqtt  
$ cd /home/mqtt/bin  
$ ./mosquitto_passwd -c /home/mqtt/conf/pwfile 用户名 #输入密码   
配置修改
vim /home/mqtt/conf/aclfile
user 用户名
topic write #
user 用户名
topic read #
主从配置 举例
1.MQTT配置
vim /home/mqtt/conf/mosquitto.conf  #修改mosquitto.conf文件加入以下内容

user mosquitto
port 3701
max_connections -1
allow_anonymous false
pid_file /home/mqtt/mosquitto.pid
password_file /home/mqtt/conf/pwfile
acl_file /home/mqtt/conf/aclfile

有从服务器的时候在主服务器配置中加入以下内容,此处为1主3从配置举例,从服务器就是没有下面这一段 

connection broker1
address 127.0.0.1:10201
topic # both 2 "" ""
remote_username careyes
remote_password careyes123

connection broker2
address 127.0.0.1:10202
topic # both 2 "" ""
remote_username careyes
remote_password careyes123

connection broker3
address 127.0.0.1:10203
topic # both 2 "" ""
remote_username careyes
remote_password careyes123

bridge_protocol_version mqttv311
notifications true
cleansession true
try_private true
start_type automatic  

启动
$ cd /home/mqtt/sbin  
$ ./mosquitto -c /home/mqtt/conf/mosquitto.conf -d #启动命令 

mqtt 连接举例(4个参数)
服务器地址:tcp://IP:端口
客户机标识:paho1573025005029000000
用户名:aclfile 文件中的用户名
密码:aclfile 文件中的用户名对应密码

如果出现 缺少cJSON 库 如:mosquitto 2.0.18 版本
# 从github下载cJSON代码
git clone https://github.com/DaveGamble/cJSON.git
cd cJSON
make
make install
posted @ 2019-11-06 15:30  王子健  阅读(1182)  评论(0编辑  收藏  举报