General configuration
所见即所得,保持默认即可
Default listener
# 设置端口
port 1883
# 设置最大连接数
max_connections -1
# 使用协议,mqtt或者websocket
protocol mqtt
SSL/TLS support
用于 default listerner 的安全设置,暂未设置
Extra listeners
用于 websocket ,暂未设置
SSL/TLS support
用于 Extra listeners 的安全设置,暂未设置
Persistence
持续性设置,即 mosquitto 重启后恢复设置,暂未设置
而且客户端的断线重连机制更加稳妥
Logging
开启服务时重定向 stdout 等信息至文件,这里只设置 type
Security
# 设置前缀
clientid_prefixes guduyl
# 禁止匿名登录
allow_anonymous false
# 设置用户名密码文件
password_file /etc/mosquitto/pwfile
# 设置权限信息文件
acl_file /etc/mosquitto/aclfile
Bridges
用于分布式服务器,暂未设置
SSL/TLS support
分布式服务器安全设置,暂未设置
External config files
rsmb options
仿照 aclfile.example 文件
启动
#! /bin/bash
ps -ef | grep mosquitto | tee /tmp/graduation.tmp
lines=$(awk 'END{print NR}' /tmp/graduation.tmp)
lines=`expr $lines + 1`
for ((i=1; i<$lines; ++i))
do
uid=$(sed -n "$i, 1p" /tmp/graduation.tmp | awk '{print $1}')
if [ $uid == "mosquit+" ] ; then
break
fi
done
if [ $i != $lines ] ; then
echo "the mosquitto1.4.1 had been started already"
else
echo "Starting the mosquitto1.4.1 ..."
mosquitto -d -c /etc/mosquitto/mosquitto.conf > /root/graduation/mosquitto.log 2>&1
echo "the mosquitto1.4.1 has been started"
echo "the log file is /root/graduation/mosquitto.log"
fi
rm -f /tmp/graduation.tmp
停止
#! /bin/bash
ps -ef | grep mosquitto | tee /tmp/graduation.tmp
lines=$(awk 'END{print NR}' /tmp/graduation.tmp)
lines=`expr $lines + 1`
for ((i=1; i<$lines; ++i))
do
uid=$(sed -n "$i, 1p" /tmp/graduation.tmp | awk '{print $1}')
if [ $uid == "mosquit+" ] ; then
break
fi
done
if [ $i != $lines ] ; then
pid=$(sed -n "$i, 1p" /tmp/graduation.tmp | awk '{print $2}')
echo "killing $pid ..."
kill $pid
echo "the mosquitto1.4.1 has been stopped"
else
echo "the mosquitto1.4.1 has not been started yet"
fi
rm -f /tmp/graduation.tmp
重启
#! /bin/bash
/root/graduation/stop.sh
/root/graduation/start.sh
个人智能家居系统 - MQTT服务器搭建(centOS7.3)
原文:https://www.cnblogs.com/guduyl/p/11423028.html