MQTT学习记录3 --- 基于CentOS 7的Mosquitto环境搭建

本文介绍如何在Linux环境下通过EPEL仓库安装Mosquitto MQTT Broker,并提供了详细的安装步骤、配置文件位置及基本命令操作。Mosquitto是一个开源的消息代理,支持MQTT v3.1/v3.1.1协议,适用于低功率传感器、手机、嵌入式计算机等设备之间的消息传递。

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

1. 添加epel库

[root@t10 ~]# yum install https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm

[root@t10 ~]# ll /etc/yum.repos.d/epel*
-rw-r--r--. 1 root root 1050 Sep 18  2019 /etc/yum.repos.d/epel.repo
-rw-r--r--. 1 root root 1149 Sep 18  2019 /etc/yum.repos.d/epel-testing.repo

2. Mosquitto描述

# 只支持 MQTT 3协议
[root@t10 ~]# yum info mosquitto 

...
Available Packages
Name        : mosquitto
Arch        : x86_64
Version     : 1.6.10
Release     : 1.el7
Size        : 287 k
Repo        : epel/x86_64
Summary     : An Open Source MQTT v3.1/v3.1.1 Broker
URL         : http://mosquitto.org/
License     : BSD
Description : Mosquitto is an open source message broker that implements the MQ Telemetry
            : Transport protocol version 3.1 and 3.1.1 MQTT provides a lightweight method
            : of carrying out messaging using a publish/subscribe model. This makes it
            : suitable for "machine to machine" messaging such as with low power sensors
            : or mobile devices such as phones, embedded computers or micro-controllers
            : like the Arduino.

3. 安装

[root@t10 ~]# yum install mosquitto
...
Dependencies Resolved

=================================================================================================================================
 Package                           Arch                       Version                             Repository                Size
=================================================================================================================================
Installing:
 mosquitto                         x86_64                     1.6.10-1.el7                        epel                     287 k
Installing for dependencies:
 libuv                             x86_64                     1:1.38.0-2.el7                      epel                     148 k
 libwebsockets                     x86_64                     3.0.1-2.el7                         epel                     118 k

Transaction Summary
=================================================================================================================================
Install  1 Package (+2 Dependent packages)
...

4. 相关命令

[root@t10 ~]# mosquitto
mosquitto         mosquitto_passwd  mosquitto_pub     mosquitto_rr      mosquitto_sub   

5. 启动

[root@t10 ~]# mosquitto
1599633468: mosquitto version 1.6.10 starting
1599633468: Using default config.
1599633468: Opening ipv4 listen socket on port 1883.
1599633468: Opening ipv6 listen socket on port 1883.
...

# 开放的端口
[root@t10 ~]# netstat -ntlp|grep mos
tcp        0      0 0.0.0.0:1883            0.0.0.0:*               LISTEN      1560/mosquitto      
tcp6       0      0 :::1883                 :::*                    LISTEN      1560/mosquitto      

6. 配置文件

      Mosquitto配置文件的绝对路径  /etc/mosquitto/mosquitto.conf

7. 测试

# 订阅端
[root@t10 ~]# mosquitto_sub -t testdemo
this is a message


# 发布端
[root@t10 ~]# mosquitto_pub -t testdemo -h localhost -m "this is a message"

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值