ubuntu搭建mqtt服务器及验证

本文介绍了如何在Ubuntu系统中安装并启动mosquitto MQTT服务器,包括查看启动命令、在特定端口运行服务。同时,详细说明了使用mosquitto_sub进行订阅以及mosquitto_pub发布消息的过程,强调了主题在MQTT中的重要性,并提供了相关命令的实际操作示例。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

  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 overrides
          any 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 pr
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

togolife

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值