Matrix 服务端程序 Conduit (Rust实现)

警告
本文最后更新于 2024-02-24,文中内容可能已过时。

自己写了个 Dockerfile 备忘,自己部署用。

Matrix 服务端程序排除过时的应该是有四个 可见 https://matrix.org/ecosystem/servers/.

  • Synapse (Apache-2.0 Python) Matrix.org homeserver
  • Construct (BSD C++) Construct is a C++ Matrix Homeserver
  • Conduit (Apache-2.0 Rust) Conduit is a simple, fast and reliable chat server written in Rust
  • Dendrite (Apache-2.0 Go) Dendrite is a second-generation Matrix homeserver written in Go!

目前只有 Synapse 是 Stable ,其他 Beta 。按照 star 数排序 Synapse (11k+) > Dendrite (5k+) > Conduit (500+) > Construct (300+) .

Conduit 现在是 0.5 版本,目前签名配置我没都找到,正常来说建议使用 Synapse 。签名很重要,不可丢失,例如从旧的如 Synapse ,Dendrite 等服务端迁移需要这个,来和其他服务器联邦创建可信网络。但是如果不能配置,或者重新部署时,使用了新的签名,这个域名在之后的联邦中会出现困难,具体表现为 401 错误。目前重新信任新签名草案似乎几年没有推进了,可见 https://github.com/matrix-org/matrix-spec/issues/234

所以不建议在生产环境使用 Conduit , 目前只是玩玩。使用默认的域名不进行联邦,或者使用一个无关紧要的域名来使用 Conduit 是个不错的主意。

需要准备 conduit, conduit.toml 配置文件

创建 Dockerfile , docker-entrypoint.sh 文件

Dockerfile

FROM ubuntu:latest
LABEL maintainer="恐咖兵糖<0@ftls.xyz>"

ENV VERSION 0.1.0
ENV CONDUIT_CONFIG /app/conduit.toml

WORKDIR /app
COPY conduit .
COPY conduit.toml .
COPY docker-entrypoint.sh .
RUN chmod +x docker-entrypoint.sh 


VOLUME /app/data
EXPOSE 6167
ENTRYPOINT ["/app/docker-entrypoint.sh"]

docker-entrypoint.sh

bash

#!/bin/bash
mkdir /app/data 
/app/conduit

conduit.toml

toml

[global]
# The server_name is the pretty name of this server. It is used as a suffix for user
# and room ids. Examples: matrix.org, conduit.rs

# The Conduit server needs all /_matrix/ requests to be reachable at
# https://your.server.name/ on port 443 (client-server) and 8448 (federation).

# If that's not possible for you, you can create /.well-known files to redirect
# requests. See
# https://matrix.org/docs/spec/client_server/latest#get-well-known-matrix-client
# and
# https://matrix.org/docs/spec/server_server/r0.1.4#get-well-known-matrix-server
# for more information

# YOU NEED TO EDIT THIS
server_name = "example.com"

# This is the only directory where Conduit will save its data
database_path = "/app/data/"
#database_backend = "rocksdb"
database_backend = "sqlite"
# The port Conduit will be running on. You need to set up a reverse proxy in
# your web server (e.g. apache or nginx), so all requests to /_matrix on port
# 443 and 8448 will be forwarded to the Conduit instance running on this port
# Docker users: Don't change this, you'll need to map an external port to this.
port = 6167

# Max size for uploads
max_request_size = 20_000_000 # in bytes

# Enables registration. If set to false, no users can register on this server.
allow_registration = true

allow_federation = true

# Server to get public keys from. You probably shouldn't change this
trusted_servers = ["matrix.org"]

#max_concurrent_requests = 100 # How many requests Conduit sends to other servers at the same time
#log = "warn,state_res=warn,rocket=off,_=off,sled=off"

#address = "127.0.0.1" # This makes sure Conduit can only be reached using the reverse proxy
address = "0.0.0.0" # If Conduit is running in a container, make sure the reverse proxy (ie. Traefik) can reach it.

bash

docker build -t kkbt/matrix_rs . 
docker run -d -p 6167:6167  -v /home/kkbt/app/conduit/data/:/app/data/ --privileged --name conduit  kkbt/matrix_rs 

完成部署后可进行反向代理,然后使用客户端创建第一个账户。第一个账户会默认拉入管理群。不要对这个群进行加密,因为群机器人仅支持无加密房间。@ 群机器加指令可以查看运行情况和配置参数之类的。 如 @conduit:example.com: -h

text

Usage: @conduit:example.com: <COMMAND>

Commands:
register-appservice Register an appservice using its registration YAML
unregister-appservice Unregister an appservice using its ID
list-appservices List all the currently registered appservices
list-rooms List all rooms the server knows about
list-local-users List users in the database
incoming-federation List all rooms we are currently handling an incoming pdu from
deactivate-user Deactivate a user
deactivate-all Deactivate a list of users
get-auth-chain Get the auth_chain of a PDU
parse-pdu Parse and print a PDU from a JSON
get-pdu Retrieve and print a PDU by ID from the Conduit database
database-memory-usage Print database memory usage statistics
show-config Show configuration values
reset-password Reset user password
create-user Create a new user
disable-room Disables incoming federation handling for a room
enable-room Enables incoming federation handling for a room again
help Print this message or the help of the given command(s)

Options:
-h, --help Print help information
-V, --version Print version information

继续配置可以部署语音服务器 ,语音服务需要使用 TURN 协议。可以使用 coturn 。coturn 是一个免费的开源的 TURN/STUN 服务器。coturn 服务器完整的实现了 STUN/TURN/ICE 协议。