当前位置:网站首页>【一起学Rust | 进阶篇 | RMQTT库】RMQTT消息服务器——安装与集群配置
【一起学Rust | 进阶篇 | RMQTT库】RMQTT消息服务器——安装与集群配置
2022-08-10 08:01:00 【广龙宇】
文章目录
RMQTT Broker 简介
RMQTT 是一款完全开源,高度可伸缩,高可用的分布式 MQTT 消息服务器,适用于 IoT、M2M 和移动应用程序,可以在单个服务节点上处理百万级别的并发客户端。
RMQTT 目前支持的操作系统:
- Linux
- macOS
- Windows Server
安装
安装分为zip解压安装和源码编译安装,我们分开介绍。
ZIP 压缩包安装(Linux、MacOS、Windows)
需从 GitHub Release 页面获取相应操作系统的二进制软件包。
- 从GitHub Release 下载zip包。
$ wget "https://github.com/rmqtt/rmqtt/releases/download/v0.2.3/rmqtt-0.2.3-x86_64-unknown-linux-musl.zip"
- 解压从GitHub Release 下载的zip包。
$ unzip rmqtt-0.2.3-x86_64-unknown-linux-musl.zip -d /app/
- 修改权限
$ cd /app/rmqtt
$ chmod +x bin/rmqttd
- 启动服务
$ cd /app/rmqtt
$ sh start.sh
- 查看服务
$ netstat -tlnp|grep 1883
tcp 0 0 0.0.0.0:1883 0.0.0.0:* LISTEN 3312/./bin/rmqttd
tcp 0 0 0.0.0.0:11883 0.0.0.0:* LISTEN 3312/./bin/rmqttd
创建static集群
基于RAFT分布式一致性算法的集群
- 准备三个服务节点,将压缩包解压到程序目录,比如:/app/rmqtt
- 修改配置文件(rmqtt.toml)
- 设置节点ID, node.id值设置为:1、2或3
- 配置RPC服务端监听端口,rpc.server_addr = “0.0.0.0:5363”
- 服务启动时同时启动"rmqtt-cluster-raft"插件
$ cd /app/rmqtt
$ vi etc/rmqtt.toml
##--------------------------------------------------------------------
## Node
##--------------------------------------------------------------------
#Node id
node.id = 1
##--------------------------------------------------------------------
## RPC
##--------------------------------------------------------------------
rpc.server_addr = "0.0.0.0:5363"
##--------------------------------------------------------------------
## Plugins
##--------------------------------------------------------------------
#Plug in configuration file directory
plugins.dir = "./etc/plugins"
#Plug in started by default, when the mqtt server is started
plugins.default_startups = [
"rmqtt-cluster-raft"
# "rmqtt-auth-http",
# "rmqtt-web-hook"
]
- 修改插件配置
$ vi etc/plugins/rmqtt-cluster-raft.toml
##--------------------------------------------------------------------
## rmqtt-cluster-raft
##--------------------------------------------------------------------
#grpc message type
message_type = 198
#Node GRPC service address list
node_grpc_addrs = ["[email protected]:5363", "[email protected]:5363", "[email protected]:5363"]
#Raft peer address list
raft_peer_addrs = ["[email protected]:6363", "[email protected]:6363", "[email protected]:6363"]
- 修改权限&启动服务
$ cd /app/rmqtt
$ chmod +x bin/rmqttd
$ sh start.sh
源码编译安装
安装rust编译环境
以Centos7为例,如果编译环境已经存在跳过此过程。注意:工具链需要1.56及之后版本,1.59及之后版本如果报连接错误需要升级系统开发环境。
安装 Rustup
先打开 Rustup 的官网:https://rustup.rs ,然后根据提示下载或运行命令。
Linux 下执行:
$ curl https://sh.rustup.rs -sSf | sh
执行source $HOME/.cargo/env 让环境变量生效
$ source $HOME/.cargo/env
- 配置crate.io镜像
可以在$HOME/.cargo/下建立一个config文件,加入如下配置:
$ vi $HOME/.cargo/config
[source.crates-io]
registry = "https://github.com/rust-lang/crates.io-index"
replace-with = 'tuna'
[source.tuna]
registry = "https://mirrors.tuna.tsinghua.edu.cn/git/crates.io-index.git"
[source.ustc]
registry = "git://mirrors.ustc.edu.cn/crates.io-index"
[source.sjtu]
registry = "https://mirrors.sjtug.sjtu.edu.cn/git/crates.io-index"
[source.rustcc]
registry = "git://crates.rustcc.cn/crates.io-index"
[net]
git-fetch-with-cli = true
如果tuna也太慢可以使用sjtu或ustc替换重试
安装openssl开发包
确保已经安装了openssl的开发包,如果已经安装跳过
For example,
libssl-devon Ubuntu oropenssl-develon Fedora.
CentOS:
$ yum install openssl-devel -y
Ubuntu:
$ apt install pkg-config -y
$ apt-get install libssl-dev -y
编译
- 获取源码
$ git clone https://github.com/rmqtt/rmqtt.git
- 切换到最近的 Tag
$ cd rmqtt
$ git checkout $(git describe --tags $(git rev-list --tags --max-count=1))
- 构建
$ cargo build --release
启动RMQTT Broker
- 复制程序和配置文件
$ mkdir -p /app/rmqtt/bin && mkdir -p /app/rmqtt/etc/plugins
$ cp target/release/rmqttd /app/rmqtt/bin/
$ cp rmqtt.toml /app/rmqtt/etc/
$ cp rmqtt-plugins/*.toml /app/rmqtt/etc/plugins/
$ cp rmqtt-bin/rmqtt.pem /app/rmqtt/etc/
$ cp rmqtt-bin/rmqtt.key /app/rmqtt/etc/
- 修改配置(rmqtt.toml)
- 将plugins.dir = “rmqtt-plugins/” 改为 plugins.dir = “/app/rmqtt/etc/plugins”
- 根据需要打开插件,如果启用插件,可在/etc/plugins/下修改插件配置
- 如果需要启动TLS,可修改listener.tls.external配置
vi /app/rmqtt/etc/rmqtt.toml
##--------------------------------------------------------------------
## Plugins
##--------------------------------------------------------------------
#Plug in configuration file directory
plugins.dir = "/app/rmqtt/etc/plugins"
#Plug in started by default, when the mqtt server is started
plugins.default_startups = [
# "rmqtt-cluster-raft"
# "rmqtt-cluster-broadcast",
# "rmqtt-auth-http",
# "rmqtt-web-hook"
]
##--------------------------------------------------------------------
## MQTT/TLS - External TLS Listener for MQTT Protocol
listener.tls.external.addr = "0.0.0.0:8883"
listener.tls.external.cert = "/app/rmqtt/etc/rmqtt.pem"
listener.tls.external.key = "/app/rmqtt/etc/rmqtt.key"
- 启动服务
$ cd /app/rmqtt
./bin/rmqttd "./etc/rmqtt.toml"
解决编译失败问题
如果使用1.59版及之后工具链,可能会存在依赖库版本太低导致链接失败问题,解决办法:
- 使用1.58版工具链
#安装1.58版本工具链
$ rustup install 1.58
#将当前工具链切换到1.58
$ rustup default 1.58
#重新编译
$ cargo build --release
边栏推荐
- 【Unity入门计划】制作RubyAdventure03-使用碰撞体&触发器实现世界交互
- Introduction to the C language to realize bubble sort
- 什么是长轮询
- 关于数据库中的中文模糊检索探讨
- IDLE development wordCount program (5)
- phpstudy开机自启
- IDLE开发wordCount程序(第五弹)
- Solve the problem that the win10win7win8 system cannot find the specified module and cannot register the desert plug-in
- 【Unity入门计划】Collision2D类&Collider2D类
- Obtain - 65 [chances] : "soldiers, subtlety also - 7-36 meter reading - defeat
猜你喜欢

Solve the problem that the win10win7win8 system cannot find the specified module and cannot register the desert plug-in

Relaxation class: the boss will martial arts, who also can not hold up against!The charm of six sigma training

机器人控制器编程实践指导书旧版-实践一 LED灯(数字量)

时序动作定位 | ASM-Loc:弱监督时序动作定位的动作感知片段建模(CVPR 2022)

SCS【2】单细胞转录组 之 cellranger

iwemeta元宇宙:一个娃娃卖9999元,泡泡玛特认为一点也不贵

WooCommerce installation and rest api usage

DGIOT 30 million meters set pressure reading

时序动作定位 | ACGNet:弱监督时序动作定位的动作补充图网络(AAAI 2022)

本地生活商家如何通过短视频赛道,提升销量曝光量?
随机推荐
自动化测试框架Pytest(二)——前后置处理
delta method 介绍
CV+Deep Learning - network architecture Pytorch recurrence series - classification (3: MobileNet, ShuffleNet)
Obtain - 65 [chances] : "soldiers, subtlety also - 7-36 meter reading - defeat
30条实用MySQL优化法则
本地生活商家如何通过短视频赛道,提升销量曝光量?
In the SQL SERVER database, if the data of the table is added, deleted, or modified, will the index of the table be recorded in the ldf log?
FFT模板
占位占位1
短视频同城流量宣传小魔推有何优势?如何给实体商家带来销量?
机器人控制器编程实践指导书旧版-实践一 LED灯(数字量)
CV+Deep Learning——网络架构Pytorch复现系列——classification(三:MobileNet,ShuffleNet)
Rust学习:6.1_复合类型之切片
深度剖析“八大排序”(上)_ 探寻一些不为人知的细节
明明加了唯一索引,为什么还是产生重复数据?
IDLE development wordCount program (5)
初使jest 单元测试
颜色选择器的使用
JS reduce
34. Talk about why you want to split the database?What methods are there?