首页 > 其他分享 >mqtt部署

mqtt部署

时间:2022-10-24 11:41:51浏览次数:61  
标签:.- 部署 will -- mqtt client mosquitto .--

一 下载mosquitto镜像

docker pull eclipse-mosquitto:latest

二 创建数据目录

mkdir -pv /data/mosquitto/{config,data,logs}

三 修改mosquitto.conf

listener 1883 0.0.0.0
消息持久存储
persistence true

persistence_location /var/lib/mosquitto/日志文件
log_dest file /mosquitto/log/mosquitto.log其他配置
include_dir /etc/mosquitto/conf.d
禁止匿名访问
allow_anonymous false认证配置
password_file /mosquitto/auth/pwfile权限配置

acl_file /mosquitto/auth/aclfile

四 创建启动脚本

cat start_mqtt.sh 
#!/bin/bash
docker rm -f mosquitto
docker run -d --name=mosquitto --privileged -p 1883:1883 -p 9001:9001 -v /data/mosquitto/:/mosquitto eclipse-mosquitto

五 设置认证

5.1 启动mosquitto


docker run --rm -it --name=mosquitto --privileged -p 1883:1883 -p 9001:9001 -v /data/mosquitto/:/mosquitto eclipse-mosquitto sh

5.2 创建pwfile

touch /mosquitto/auth/pwfile

5.3 创建用户

mosquitto_passwd /mosquitto/auth/pwfile test01
Password:
Reenter password:

5.4 创建权限

cat /mosquitto/auth/aclfile
user test01
topic write #
topic read #

5.5 重启mosquitto

./start_mqtt.sh 

六 mosquitto_pub 命令参数说明

# mosquitto_pub --help
mosquitto_pub is a simple mqtt client that will publish a message on a single topic and exit.
mosquitto_pub version 2.0.14 running on libmosquitto 2.0.14.
Usage: mosquitto_pub {[-h host] [--unix path] [-p port] [-u username] [-P password] -t topic | -L URL}

{-f file | -l | -n | -m message}

[-c] [-k keepalive] [-q qos] [-r] [--repeat N] [--repeat-delay time] [-x session-expiry]

[-A bind_address] [--nodelay]

[-i id] [-I id_prefix]

[-d] [--quiet]

[-M max_inflight]

[-u username [-P password]]

[--will-topic [--will-payload payload] [--will-qos qos] [--will-retain]]

[{--cafile file | --capath dir} [--cert file] [--key file]

[--ciphers ciphers] [--insecure]

[--tls-alpn protocol]

[--tls-engine engine] [--keyform keyform] [--tls-engine-kpass-sha1]]

[--tls-use-os-certs]

[--proxy socks-url]

[--property command identifier value]

[-D command identifier value]

mosquitto_pub --help-A : bind the outgoing socket to this host/ip address. Use to control which interface

the client communicates over.

-d : enable debug messages.

-c : disable clean session/enable persistent client mode

When this argument is used, the broker will be instructed not to clean existing sessions

for the same client id when the client connects, and sessions will never expire when the

client disconnects. MQTT v5 clients can change their session expiry interval with the -x

argument.

-D : Define MQTT v5 properties. See the documentation for more details.

-f : send the contents of a file as the message.

-h : mqtt host to connect to. Defaults to localhost.

-i : id to use for this client. Defaults to mosquitto_pub_ appended with the process id.

-I : define the client id as id_prefix appended with the process id. Useful for when the

broker is using the clientid_prefixes option.

-k : keep alive in seconds for this client. Defaults to 60.

-L : specify user, password, hostname, port and topic as a URL in the form:

mqtt(s)

标签:.-,部署,will,--,mqtt,client,mosquitto,.--
From: https://blog.51cto.com/u_4028786/5789194

相关文章

  • Prometheus之部署blackbox_exporter
    一blackboxexporter介绍GitHub地址:https://github.com/prometheus/blackbox_exporterblackbox_exporter是Prometheuse官方提供的一个exporter,可以通过HTTP、HTTPS、DNS、T......
  • Envoy部署
    部署Envoy的常用方法镜像方式部署Envoy项目为多种平台(例如amd64和arm64等)维护有相应的DockerImage,我们可按需猎取相应镜像后以容器形式运行Envoy,而且它们存在以下几种变化......
  • ubuntu20.04部署keepalived
    一环境准备1.1设置时间同步root@node-01:~#apt-yinstallchronyroot@node-01:~#systemctlenablechrony二在线安装2.1查看keepalived软件版本root@node-01:~#apt-......
  • 部署NFS存储服务器
    部署:(在服务端只需要安装nfs-utils即可,在客户端安装只需安装rpcbind。)yum-yinstallnfs-utilsrpcbind1、配置服务端systemctlstopfirewalld&&setenforce0......
  • 爬虫部署HTTP后工作效率不理想是什么原因
    程序员在日常工作中,爬虫程序为了提高工作效率,经常需要使用HTTP代理。但有时候,爬虫在使用HTTP代理后工作效率不仅没有提升,反而大不如前,这是为什么呢?1、HTTP代理质......
  • 【鸟哥杂谈】三分钟完成腾讯云部署emqx,公网访问自己的mqtt服务器
    忘记过去,超越自己❤️博客主页​​单片机菜鸟哥,一个野生非专业硬件IOT爱好者​​❤️❤️本篇创建记录2022-10-15❤️❤️本篇更新记录2022-10-15❤️......
  • 【鸟哥杂谈】搭建自己的本地mqtt服务器 emqx
    忘记过去,超越自己❤️博客主页​​单片机菜鸟哥,一个野生非专业硬件IOT爱好者​​❤️❤️本篇创建记录2022-10-15❤️❤️本篇更新记录2022-10-15❤️......
  • Ansible部署LNMP
    Ansible部署LNMP目录Ansible部署LNMP基础准备工作管理nginx受管主机部署nginx服务管理mysql受管主机部署mysql服务管理php受管主机部署php服务环境介绍:系统ip主......
  • ubuntu+Django + nginx + uwsgi 部署
    ubuntu+Django+nginx+uwsgi部署0.前期准备注意:以下几件事都必须在激活虚拟环境下完成运行以下命令生成项目所需的依赖列表,会在项目根目录生成一个requirements.......
  • MQTT是什么,优势在哪里?
    MQTT是一个物联网传输协议,它被设计用于轻量级的发布/订阅式消息传输,旨在为低带宽和不稳定的网络环境中的物联网设备提供可靠的网络服务。MQTT是专门针对物联网开发的轻量级......