zoukankan      html  css  js  c++  java
  • 个人智能家居系统

    个人智能家居系统 - MQTT服务器搭建(centOS7.3)

    0x00 参考

    0x01 配置

    • 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

    用户名密码设置

    • mosquitto_passwd 命令,查看帮助即可

    权限文件设置

    • 仿照 aclfile.example 文件

      • test/jh/# 可匹配 test/jh/a/b/c, test/jh/a/b, test/jh/a.test/jh
      • test/jh/+ 可匹配 test/jh/a, test/jh/b, 但是不能匹配 test/jh/a/b

    启动停止

    • 启动

      #! /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
      
      
  • 相关阅读:
    Java(14):面向对象、封装、继承、方法重写、多态、抽象类与接口、内部类
    Java(13):数组、Arrays类、冒泡排序
    Java(12):方法、重载、命令行传参、可变参数、方法调用
    Java(11):switch、dowhile、九九乘法表、打印质数、打印三角形
    Java(10):用户交互Scanner
    Java(9):包
    Java(8):运算符
    Java(7):变量和常量及其规范、作用域
    Mybatis 打印日志
    mysql 更新数据
  • 原文地址:https://www.cnblogs.com/guduyl/p/11423028.html
Copyright © 2011-2022 走看看