1. 安装mosquitto

    sudo apt install mosquitto
    sudo apt install libmosquitto-dev
    sudo apt install mosquitto-clients
    
  2. 启动mosquitto
    默认安装mosquitto后就会自动启动mosquitto进程,其配置文件在/etc/mosquitto下,默认监听端口为1883
    /usr/sbin/mosquitto -c /etc/mosquitto/mosquitto.conf
    查看mosquitto的启动命令

    # mosquitto -h
    mosquitto version 1.4.15 (build date Tue, 18 Jun 2019 11:42:22 -0300)mosquitto is an MQTT v3.1.1/v3.1 broker.Usage: mosquitto [-c config_file] [-d] [-h] [-p port]-c : specify the broker config file.   (配置文件路径)-d : put the broker into the background after starting. (后台运行)-h : display this help. (显示帮助)-p : start the broker listening on the specified port.Not recommended in conjunction with the -c option. (指定端口)-v : verbose mode - enable all logging types. This overridesany logging options given in the config file. (打印日志)See http://mosquitto.org/ for more information.
    

    执行:mosquitto -p 5678 -v,在本地端口5678上启动mosquitto服务,并在前台运行打印日志

  3. 订阅
    使用mosquitto_sub命令启动订阅,查看mosquitto_sub的启动命令

    # mosquitto_sub --help
    mosquitto_sub is a simple mqtt client that will subscribe to a single topic and print all messages it receives.
    mosquitto_sub version 1.4.15 running on libmosquitto 1.4.15.Usage: mosquitto_sub [-c] [-h host] [-k keepalive] [-p port] [-q qos] [-R] -t topic ...[-C msg_count] [-T filter_out][-A bind_address] [-S][-i id] [-I id_prefix][-d] [-N] [--quiet] [-v][-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]][--psk hex-key --psk-identity identity [--ciphers ciphers]][--proxy socks-url]mosquitto_sub --help-A : bind the outgoing socket to this host/ip address. Use to control which interfacethe client communicates over.-c : disable 'clean session' (store subscription and pending messages when client disconnects).-C : disconnect and exit after receiving the 'msg_count' messages.-d : enable debug messages.-h : mqtt host to connect to. Defaults to localhost.-i : id to use for this client. Defaults to mosquitto_sub_ appended with the process id.-I : define the client id as id_prefix appended with the process id. Useful for when thebroker is using the clientid_prefixes option.-k : keep alive in seconds for this client. Defaults to 60.-N : do not add an end of line character when printing the payload.-p : network port to connect to. Defaults to 1883.-P : provide a password (requires MQTT 3.1 broker)-q : quality of service level to use for the subscription. Defaults to 0.-R : do not print stale messages (those with retain set).-S : use SRV lookups to determine which host to connect to.-t : mqtt topic to subscribe to. May be repeated multiple times.-T : topic string to filter out of results. May be repeated.-u : provide a username (requires MQTT 3.1 broker)-v : print published messages verbosely.-V : specify the version of the MQTT protocol to use when connecting.Can be mqttv31 or mqttv311. Defaults to mqttv31.--help : display this message.--quiet : don't print error messages.--will-payload : payload for the client Will, which is sent by the broker in case ofunexpected disconnection. If not given and will-topic is set, a zerolength message will be sent.--will-qos : QoS level for the client Will.--will-retain : if given, make the client Will retained.--will-topic : the topic on which to publish the client Will.--cafile : path to a file containing trusted CA certificates to enable encryptedcertificate based communication.--capath : path to a directory containing trusted CA certificates to enable encryptedcommunication.--cert : client certificate for authentication, if required by server.--key : client private key for authentication, if required by server.--ciphers : openssl compatible list of TLS ciphers to support.--tls-version : TLS protocol version, can be one of tlsv1.2 tlsv1.1 or tlsv1.Defaults to tlsv1.2 if available.--insecure : do not check that the server certificate hostname matches the remotehostname. Using this option means that you cannot be sure that theremote host is the server you wish to connect to and so is insecure.Do not use this option in a production environment.--psk : pre-shared-key in hexadecimal (no leading 0x) to enable TLS-PSK mode.--psk-identity : client identity string for TLS-PSK mode.--proxy : SOCKS5 proxy URL of the form:socks5h://[username[:password]@]hostname[:port]Only "none" and "username" authentication is supported.See http://mosquitto.org/ for more information.
    

    重要的选项:
    -h 指定连接mqtt服务的ip地址,默认为localhost
    -p 指定连接mqtt服务的端口
    -t 指定订阅主题(主题:mqtt中的最重要的概念)

    执行命令: mosquitto_sub -v -p 5678 -t topic, 订阅topic主题

  4. 发布
    使用mosquitto_pub命令发布,查看该命令的帮助与mosquitto_sub基本类似,使用同样的选项指定mqtt服务的ip地址,端口,以及发布主题等。
    -m 选项: 发布消息的内容
    执行命令: mosquitto_pub -p 5678 -t topic -m hello

  5. 运行结果
    执行发布命令后,在订阅窗口中打印接收到hello消息

ubuntu搭建mqtt服务器及验证相关推荐

  1. Ubuntu搭建Mqtt服务器

    快速上手mosquitto在ubuntu18.04下的安装及测试_小刀_的博客-CSDN博客 0.基本认识 每个机器可以订阅,发布.谁订阅了某个topic,消息就会发给谁. 比如机器0订阅了msg1, ...

  2. linux如何搭建mqtt服务器,【MQTT】在Ubuntu下搭建MQTT服务器

    前言 博主之前写了一篇<在Windows下搭建MQTT服务器>,这次要尝试在Ubuntu下搭建MQTT服务器.实际上,下载好源码包后,后面的都和那篇文章差不多了. 开发环境 虚拟机 Ubu ...

  3. Ubuntu搭建Anki服务器

    Ubuntu搭建Anki服务器 第一步安装Anki 阿里云的服务器,xshell远程登录上 1 #以root用户进行操作 2 3 #安装Akni服务 4 easy_install AnkiServer ...

  4. Ubuntu16.04LTS环境下搭建MQTT服务器以及QT实现MQTT客户端

    MQTT服务器搭建 使用EMQX搭建MQTT服务器,EMQX 4.2.14 for Ubuntu 16.04下载 下载zip包,选择安装方式为zip,cpu架构选择x86_64 按照网页的指示进行下载 ...

  5. UbuntuServer搭建MQTT服务器

    一.MQTT协议简介 MQTT 是一个基于发布/订阅模式的消息传输协议.它具有轻量级.开放.简单,易于实现,通信带宽要求低等特点.这些特点使得它对机器与机器的通信(M2M)以及物联网应用(IoT)来说 ...

  6. nodejs快速搭建MQTT服务器

    简介 MQTT(消息队列遥测传输)是ISO 标准(ISO/IEC PRF 20922)下基于发布/订阅范式的消息协议.它工作在TCP/IP协议族上,是为硬件性能低下的远程设备以及网络状况糟糕的情况下而 ...

  7. Windows下搭建MQTT服务器

    Windows下搭建MQTT服务器 1.MQTT服务器软件筛选 2.MQTT服务器软件mosquitto下载 3.修改mosquitto配置,并启动mosquitto服务 4.利用mosquitto工 ...

  8. Windows搭建MQTT服务器

    Win10下搭建MQTT服务器 一.获取软件包 链接:https://pan.baidu.com/s/1sKsL3ninhpwiawm69cOQ9w 提取码:9vhm mqtt服务器安装包为apach ...

  9. Ubuntu搭建NFS服务器,NFS协议详细分析

    目录 1. Ubuntu搭建NFS服务器 2. NFS协议分析 2.1 实验拓扑: 2.2 在kali抓包分析 1. Ubuntu搭建NFS服务器 ​ NFS(Network FileSystem,网 ...

最新文章

  1. c语言x在二进制表示下1的个数,算法:计算十进制数字在二进制表示1的个数,...
  2. 破4!《我想进大厂》之Java基础夺命连环16问
  3. 一名算法工程师,对流量和时代红利的思考
  4. oracle log block size,案例:Oracle无法启动报错ORA-00218: block size 0 重建控制文件
  5. 武安高中计算机学院那个好,河北邯郸最好的5所高中,前两所学霸如云,看看有你的母校没?...
  6. 使用CSS预处理器Less
  7. python语言属于哪一种语言_Python与Java:你应该学习哪种语言,他们有什么区别?...
  8. 【转】ASPxGridView 日期范围过滤扩展
  9. 利用计算机语言实现ID3算法,机器学习之决策树学习-id3算法-原理分析及c语言代码实现.pdf...
  10. SDUT 2766 小明传奇2
  11. 在Unity3D中实现安卓平台的本地通知推送
  12. 软件工程的迷途与沉思
  13. 【Codeforces 1426 D】Non-zero Segments,贪心,前缀和,数组子段统计
  14. 莫烦python学习笔记之全局,局部变量
  15. 对文式编程的一些误解
  16. 固态硬盘启动计算机时间,固态硬盘如何做到10秒快速开机
  17. WPS上配置使用Endnote软件
  18. Android ViewBinding和DataBinding的区别
  19. 用GPOPS2解最优控制问题
  20. mysql mysqldumpslow 如何配置_详解 慢查询 之 mysqldumpslow

热门文章

  1. 网站怎么启动GZIP压缩方法(DZ,WP,php网站开启)
  2. 记录两段杀鸡用的牛刀——分钱和算日子……
  3. 奥特曼传奇英雄存档丢了怎么找回_奥特曼传奇英雄存档
  4. 贴吧顶贴php脚步,贴吧干货:利用代码无限顶贴
  5. 自动化测试软件费用,计费引擎资费自动化测试
  6. 百度云盘构建svn服务器
  7. 用devc++表白_想谈一场甜甜的姐弟恋了 | 肇院表白墙716期
  8. 【在线支付】在线支付的方式
  9. UE4 如何解决使用WebUI插件时 没法输入中文的问题
  10. 微信小程序的开发之城市json数据