RMQTT 是一款完全开源,高度可伸缩,高可用的分布式 MQTT 消息服务器,适用于 IoT、M2M 和移动应用程序,可以在单个服务节点上处理百万级别的并发客户端。
RMQTT 目前支持的操作系统:
安装分为zip解压安装和源码编译安装,我们分开介绍。
需从 GitHub Release 页面获取相应操作系统的二进制软件包。
$ wget "https://github.com/rmqtt/rmqtt/releases/download/v0.2.3/rmqtt-0.2.3-x86_64-unknown-linux-musl.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
$ 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
以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
可以在$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-dev
on Ubuntu or openssl-devel
on 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
$ cd rmqtt
$ git checkout $(git describe --tags $(git rev-list --tags --max-count=1))
$ cargo build --release
$ 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/
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版本工具链
$ rustup install 1.58
#将当前工具链切换到1.58
$ rustup default 1.58
#重新编译
$ cargo build --release