MQTT服务(EMQX)安装

2024-04-27 01:38
文章标签 服务 安装 mqtt emqx

本文主要是介绍MQTT服务(EMQX)安装,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

安装及测试EMQ X

  EMQ X R3.0 (Erlang/Enterprise/Elastic MQTT Broker) 是基于 Erlang/OTP 语言平台开发,支持大规模连接和分布式集群,发布订阅模式的开源 MQTT 消息服务器。

  MQTT是一个由IBM主导开发的物联网传输协议,它被设计用于轻量级的发布/订阅式消息传输,旨在为低带宽和不稳定的网络环境中的物联网设备提供可靠的网络服务。它的核心设计思想是开源、可靠、轻巧、简单,具有以下主要的几项特性:
1.非常小的通信开销(最小的消息大小为 2 字节);
2.支持各种流行编程语言(包括C,Java,Ruby,Python 等等)且易于使用的客户端;
3.支持发布 / 预定模型,简化应用程序的开发;
4.提供三种不同消息传递等级,让消息能按需到达目的地,适应在不稳定工作的网络传输需求。

官方网址:https://www.emqx.io/

1. 二进制包安装

1.1. Ubuntu

	download: https://www.emqx.io/downloads/broker?osType=Linux#example bin url: https://www.emqx.io/downloads/broker/v4.0.5/emqx-ubuntu16.04-v4.0.5.zipunzip emqx-ubuntu16.04-v4.0.5.zip && cd emqx# start emqx./bin/emqx start# Check the running status./bin/emqx_ctl status# stop emqx./bin/emqx stopMQTT can connect it though port 1883web console: http://127.0.0.1:18083,default username: admin,password:public

1.2. CentOS

yum install https://www.emqx.io/downloads/broker/v4.0.5/emqx-centos7-v4.0.5.x86_64.rpm
# start emqx
systemctl start emqx
# start emqx when reboot/power-on
systemctl enable emqx

2.源码编译安装

install Erlang
install rebar3: A sophisticated build-tool for Erlang projects that follows OTP principles#Get the source code$ git clone -b v3.2.0 https://github.com/emqx/emqx-rel.git
#Set environment variables$ export EMQX_DEPS_DEFAULT_VSN=v3.2.0
#Compile$ cd emqx-rel && make
#Start EMQ X$ cd _build/emqx/rel/emqx
$ ./bin/emqx start
emqx v3.2.0 is started successfully!$ ./bin/emqx_ctl status
Node 'emqx@127.0.0.1' is started
emqx 3.2.0 is running

3.EMQX消息服务器默认配置

  • TCP端口包括:
	1883	MQTT protocol port8883	MQTT/SSL port8083	MQTT/WebSocket port8080	HTTP API port18083	Dashboard Management Console Port
  • 使用 mosquitto_sub/pub客户端命令行来订阅和发布消息:
//订阅消息并在后台监听
mosquitto_sub -h 127.0.0.1 -p 1883 -t topic1 -q 2 &
//发布消息
mosquitto_pub -h 127.0.0.1 -p 1883 -t topic1 -q 1 -m ‘Hello, MQTT!’
  • 后台管理web端口

  端口18083登录web进入管理端入口,默认用户: admin,密码:public。左侧管理边栏可以对EMQX设置,其中plugins可以管理插件,具体内容自行查看https://developer.emqx.io/docs/emq/v3/cn/plugins.html;可以用./bin/emqx_ctl plugins load 插件名字安装插件。

4.emqx提供了三种消息发布服务质量

  Quality of Service等级是发送与接收端的一种关于保证交付信息的协议。一共有3 个QoS 等级:

  • "至多一次0",消息发布完全依赖底层TCP/IP 网络,会发生消息丢失或者重复,这一级别可用于如下情况,环境,传感器数据,丢失一次度记录无所谓,因为不久之后会有第二次发送;

  • "至少一次1",确保消息到达,但消息重复可能发生;

  • “只有一次2",确保消息到达一次,这一级别可用于如下情况,在计费系统中,消息重复或者丢失导致不正确的结果。

5.EMQ离线消息

  1. 保留消息 MQTT客户端向服务器发布(PUBLISH)消息时,可以设置保留消息(Retained Message)标志。保留消息(Retained Message)会驻留在消息服务器,后来的订阅者订阅主题时仍可以接收该消息。 例如mosquitto命令行发布一条保留消息到主题’a/b/c’: mosquitto_pub -r -q 1 -t a/b/c -m ‘hello’ 之后连接上来的MQTT客户端订阅主题’a/b/c’时候,仍可收到该消息: $ mosquitto_sub -t a/b/c -q 1 hello 保留消息(Retained Message)有两种清除方式: 客户端向有保留消息的主题发布一个空消息: mosquitto_pub -r -q 1 -t a/b/c -m ‘’ 消息服务器设置保留消息的超期时间。

  2. cleanSession 清理回话 MQTT客户端向服务器发起CONNECT请求时,可以通过’Clean Session’标志设置会话。 ‘Clean Session’设置为0,表示创建一个持久会话,在客户端断开连接时,会话仍然保持并保存离线消息,直到会话超时注销。 ‘Clean Session’设置为1,表示创建一个新的临时会话,在客户端断开时,会话自动销毁。

6.测试Username

cd /home/x/work/emqx-rel/_build/emqx/rel/emqxadd a user./bin/emqx_ctl users add ElonMusk passwordvim ./etc/emqx.confallow_anonymous = false
enable plugins./bin/emqx_ctl plugins list./bin/emqx_ctl plugins load emqx_auth_username
restart emqx./bin/emqx restart./bin/emqx --helpUsage: emqx {start|start_boot <file>|ertspath|foreground|stop|restart|reboot|pid|ping|console|console_clean|console_boot <file>|attach|remote_console|upgrade|escript|rpc|rpcterms|eval}mosquitto_sub -h 127.0.0.1 -p 1883 -d -t topic -q 2 -u ElonMusk -P password
mosquitto_pub -h 127.0.0.1 -p 1883 -d -t topic -q 2 -m "Hello, Username!" -u ElonMusk -P password

7.测试TLS

mosquitto_sub -h 127.0.0.1 -p 8883 -d -t topic -q 2 -u ElonMusk -P password --psk 1234 --psk-identity client1
mosquitto_pub -h 127.0.0.1 -p 8883 -d -t topic -q 2 -m "Hello TLS" -u Sender -P password --psk 1234 --psk-identity client1

8.认证

authetication is provided by a seriers of authentication plugins
supports authentication by username, password, ClientID or anonymous
anonymous is default
Multiple auth plug-ins can be started at the same time. The plug-in that starts first checks first.Username Auth -> ClientID Auth -> Anonymous AuthModify etc/emqx.conf enable anonymous authentication:allow_anonymous = trueAccess Control List:acl_nomatch = allowacl_file = etc/acl.confetc/acl.conf%% Aallows 'dashboard' users to subscribe to '$SYS/#'{allow, {user, "dashboard"}, subscribe, ["$SYS/#"]}.%% Allows local user to publish and subscribe to all topics{allow, {ipaddr, "127.0.0.1"}, pubsub, ["$SYS/#", "#"]}.%% Deny all the users to subscribe to '$SYS/#' and '#' topics except local users{deny, all, subscribe, ["$SYS/#", {eq, "#"}]}.%% Allows any situation other than the above rules{allow, all}.The authentication plugins provided by EMQ X include:plugins				description
emqx_auth_clientid	ClientId authentication plugin
emqx_auth_username	username and password authentication plugin
emqx_auth_jwt	JWT authentication plugin
emqx_auth_ldap	LDAP authentication plugin
emqx_auth_http	HTTP authentication plugin
emqx_auth_mysql	MySQ Lauthentication plugin
emqx_auth_pgsql	Postgre authentication plugin
emqx_auth_redis	Redis authentication plugin
emqx_auth_mongo	MongoDB authentication plugin

9. 网桥

RPC bridge
MQTT bridgeconfigure:etc/plugins/emqx_bridge_mqtt.conf

10. HTTP发布API接口

through which an application server or web server can publish MQTT messages

11. MQTT网络socket链接

web browsers or applications can connect directly to the broker via WebSocket

12. 配置

File	Description
etc/emqx.conf	EMQ X 3.0 Configuration File
etc/acl.conf	The default ACL File
etc/plugins/*.conf	Config Files of PluginsConfiguration file processing flow during EMQ X start-up::

---------------------- 3.0/schema/.schema -------------------
| etc/emqx.conf | ----------------- |/ | data/app.config |
| + | --> mergeconf --> | data/app.conf | --> cuttlefish generate --> | |
| etc/plugins/
.conf | ----------------- | data/vm.args |


EMQ X Node Connection Method:##  Specify the Erlang Distributed Communication Protocol: inet_tcp | inet6_tcp | inet_tlsnode.proto_dist = inet_tcpFiles for storing SSL/TLS options when Erlang distributed using TLS:node.ssl_dist_optfile = etc/ssl_dist.confMQTT/SSL Listener - 8883SSL listening port:listener.ssl.external = 8883Path of the file containing the user’s private key:listener.ssl.external.keyfile = etc/certs/key.pemPath of the file containing the user certificate:listener.ssl.external.certfile = etc/certs/cert.pemPath of the file containing the CA certificate:## listener.ssl.external.cacertfile = etc/certs/cacert.pem

这篇关于MQTT服务(EMQX)安装的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/939211

相关文章

mac安装nvm(node.js)多版本管理实践步骤

《mac安装nvm(node.js)多版本管理实践步骤》:本文主要介绍mac安装nvm(node.js)多版本管理的相关资料,NVM是一个用于管理多个Node.js版本的命令行工具,它允许开发者在... 目录NVM功能简介MAC安装实践一、下载nvm二、安装nvm三、安装node.js总结NVM功能简介N

python安装whl包并解决依赖关系的实现

《python安装whl包并解决依赖关系的实现》本文主要介绍了python安装whl包并解决依赖关系的实现,文中通过图文示例介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面... 目录一、什么是whl文件?二、我们为什么需要使用whl文件来安装python库?三、我们应该去哪儿下

MySQL安装时initializing database失败的问题解决

《MySQL安装时initializingdatabase失败的问题解决》本文主要介绍了MySQL安装时initializingdatabase失败的问题解决,文中通过图文介绍的非常详细,对大家的学... 目录问题页面:解决方法:问题页面:解决方法:1.勾选红框中的选项:2.将下图红框中全部改为英

MySQL9.0默认路径安装下重置root密码

《MySQL9.0默认路径安装下重置root密码》本文主要介绍了MySQL9.0默认路径安装下重置root密码,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们... 目录问题描述环境描述解决方法正常模式下修改密码报错原因问题描述mysqlChina编程采用默认安装路径,

springboot的调度服务与异步服务使用详解

《springboot的调度服务与异步服务使用详解》本文主要介绍了Java的ScheduledExecutorService接口和SpringBoot中如何使用调度线程池,包括核心参数、创建方式、自定... 目录1.调度服务1.1.JDK之ScheduledExecutorService1.2.spring

Qt 中集成mqtt协议的使用方法

《Qt中集成mqtt协议的使用方法》文章介绍了如何在工程中引入qmqtt库,并通过声明一个单例类来暴露订阅到的主题数据,本文通过实例代码给大家介绍的非常详细,感兴趣的朋友一起看看吧... 目录一,引入qmqtt 库二,使用一,引入qmqtt 库我是将整个头文件/源文件都添加到了工程中进行编译,这样 跨平台

Python使用国内镜像加速pip安装的方法讲解

《Python使用国内镜像加速pip安装的方法讲解》在Python开发中,pip是一个非常重要的工具,用于安装和管理Python的第三方库,然而,在国内使用pip安装依赖时,往往会因为网络问题而导致速... 目录一、pip 工具简介1. 什么是 pip?2. 什么是 -i 参数?二、国内镜像源的选择三、如何

Android 悬浮窗开发示例((动态权限请求 | 前台服务和通知 | 悬浮窗创建 )

《Android悬浮窗开发示例((动态权限请求|前台服务和通知|悬浮窗创建)》本文介绍了Android悬浮窗的实现效果,包括动态权限请求、前台服务和通知的使用,悬浮窗权限需要动态申请并引导... 目录一、悬浮窗 动态权限请求1、动态请求权限2、悬浮窗权限说明3、检查动态权限4、申请动态权限5、权限设置完毕后

Python安装时常见报错以及解决方案

《Python安装时常见报错以及解决方案》:本文主要介绍在安装Python、配置环境变量、使用pip以及运行Python脚本时常见的错误及其解决方案,文中介绍的非常详细,需要的朋友可以参考下... 目录一、安装 python 时常见报错及解决方案(一)安装包下载失败(二)权限不足二、配置环境变量时常见报错及

TP-Link PDDNS服将于务6月30日正式停运:用户需转向第三方DDNS服务

《TP-LinkPDDNS服将于务6月30日正式停运:用户需转向第三方DDNS服务》近期,路由器制造巨头普联(TP-Link)在用户群体中引发了一系列重要变动,上个月,公司发出了一则通知,明确要求所... 路由器厂商普联(TP-Link)上个月发布公告要求所有用户必须完成实名认证后才能继续使用普联提供的 D