1.安装包下载
2.安装
tar –zxvf mosquitto-1.6.7.tar.gz
yum install gcc cc aclocal autoconf automake autoheader makeinfo gcc-c++ cmake openssl-devel libuuid-devel -y
$ useradd -d /home/mqtt/ -m mosquitto
$ passwd mosquitto #输入密码
$ cd /home/mosquitto-1.6.7/
$ vim config.mk #修改config.mk的配置路径,将前缀prefix?=/usr/local为prefix?=/home/mqtt,保存
$ make && make install
$ mkdir -p /home/mqtt/conf/
$ cp /home/mosquitto-1.6.7/aclfile.example /home/mqtt/conf/aclfile
$ cp /home/mosquitto-1.6.7/mosquitto.conf /home/mqtt/conf/mosquitto.conf
$ cp /home/mosquitto-1.6.7/pskfile.example /home/mqtt/conf/pskfile
$ cp /home/mosquitto-1.6.7/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 文件中的用户名对应密码