折腾笔记[44]-配置matrix聊天服务器
摘要
使用轻量化的continuwuity部署matrix内部聊天服务器(homeserver).
AGENTS.md声明
本文用于投喂龙虾(openclaw).
简介
matrix聊天协议简介
Matrix 是一个开放标准的去中心化实时通信协议,旨在提供安全、去中心化的即时通讯和协作解决方案.
| 组件 | 说明 |
|---|---|
| Homeserver | 存储用户账户、消息历史的主服务器(如 Synapse、Dendrite、Conduit) |
| 客户端 | 用户交互应用(如 Element、FluffyChat) |
| 房间(Room) | 分布式聊天空间,不依赖于单一服务器 |
| 身份服务器 | 可选组件,用于关联 Matrix 账户与第三方身份(如邮箱、手机号) |
mqtt手机客户端
[https://www.openim.io/zh]
[https://matrix.org/ecosystem/clients/element/]
[https://element.io/]
[https://mattermost.com/]
[https://meshtastic.org/]
[https://github.com/eclipse-paho/paho.mqtt.android]
[https://github.com/Reathin/AndMqtt]
[https://github.com/UmerCodez/DroidPad]
MyMQTT, the professional Message Queuing Telemetry Transport client.
Known from the german technology magazines JavaMagazin and Mobile Technology.
OpenIM包括服务端和客户端SDK,实现了高性能、轻量级、易扩展等重要特性。开发者通过集成OpenIM SDK,并私有化部署服务端,可以将即时通讯、实时网络能力快速集成到自身应用中,确保业务数据的安全性和私密性。
matrix聊天协议对比邮箱聊天协议对比MQTT协议
[https://www.process-one.net/blog/xmpp-matrix/]
[https://www.process-one.net/ejabberd/]
[https://github.com/processone/ejabberd]
| 协议 | 定位 | 核心特点 |
|---|---|---|
| Matrix | 现代去中心化即时通讯协议 | 联邦制架构、端到端加密、分布式数据存储 |
| 邮箱协议 (SMTP/IMAP/POP3) | 异步消息传输协议 | 存储转发、非实时、广泛兼容 |
| MQTT | 轻量级物联网消息协议 | 发布订阅、极低开销、QoS保障 |
Matrix
- 端到端加密(E2EE):默认使用 Olm/Megolm 算法
- 加密元数据:隐藏谁与谁通信
- 密钥验证:支持设备间密钥验证
邮箱协议
- 传输加密:TLS/SSL 保护传输过程
- 内容加密:可选 PGP/S-MIME,但配置复杂
- 元数据暴露:邮件头信息(发件人、收件人、时间)明文可见
MQTT
- 传输层安全:支持 TLS/SSL
- 无内置E2EE:应用层需自行实现加密
- 认证简单:基于用户名/密码,需额外安全层
matrix协议适配客户端
- Element
- fluffychat
- SchildiChat
| 特性 | Element | FluffyChat | SchildiChat |
|---|---|---|---|
| 基础 | 官方参考实现 | 独立 Flutter 项目 | Element 分支 |
| 设计哲学 | 功能完整、专业 | 简洁可爱、易用 | 传统 IM 体验 |
| 消息布局 | 线性列表 | 线性列表 | 气泡对话 |
| 聊天列表 | 分离(私聊/群聊) | 统一 | 统一 |
| 性能 | Element X 极快 | 较慢(Flutter) | 与 Element 相当 |
| 多账户 | 支持 | Beta 支持 | 支持 |
| Linux 桌面 | 支持 | 功能最全 | 支持 |
| 端到端加密 | 完整支持 | 完整支持 | 完整支持 |
| 推送通知 | 完整支持 | 支持 | F-Droid 版需权衡 |
| 适合用户 | 专业/企业用户 | 追求美观的个人用户 | 传统 IM 用户 |
matrix的homeserver要素
1. 服务器程序
这是 Matrix 协议的核心实现,有三种主流选择:
| 实现 | 语言 | 特点 | 适用场景 |
|---|---|---|---|
| Synapse | Python | 官方参考实现,功能最完整,生态最成熟 | 生产环境、大型部署(200+用户) |
| Dendrite | Go | 微服务架构,性能优于 Synapse | 中型部署(1000+用户) |
| Conduit | Rust | 极轻量级,单进程架构,资源占用最低 | 个人/小型部署(<100用户)、树莓派 |
2. 数据库
存储用户账户、消息历史、房间状态等所有数据:
支持类型:
- PostgreSQL(推荐):生产环境首选,支持高并发,性能最佳
- SQLite:适合个人测试或小型部署,配置简单
3. 域名
Matrix 身份标识和联邦通信的基础。
关键要求:
- Server Name:用户 ID 的一部分(如
@user:example.com),一旦设置不可更改 - DNS 配置:
- A 记录:指向服务器 IP(如
matrix.example.com) - SRV 记录:
_matrix._tcp.example.com指向 443 端口 - .well-known 委托:可在主域名下放配置文件,指向实际的 Matrix 服务器
- A 记录:指向服务器 IP(如
4. 端口
Matrix 使用多个端口处理不同流量.
| 端口 | 用途 | 说明 |
|---|---|---|
| 8008 | HTTP API(客户端通信)(必须) | 内部端口,通常由反向代理转发 |
| 8448 | HTTPS 联邦通信(可选) | 服务器间加密通信,可共用 443 |
| 443 | 对外服务(可选) | 通过反向代理(Nginx/Caddy)统一入口 |
continuwuity简介
[https://continuwuity.org/]
[https://nexy.blog/guides/Matrix/setting-up-continuwuity/3-continuwuity/#configuring-continuwuity]
Continuwuity(曾用名 Conduit/Conduwuit)是一个用 Rust 编写的社区维护版 Matrix Homeserver,定位为高性能、轻量级、易于部署的联邦式聊天服务器。
Continuwuity 是个人用户或小型组织部署 Matrix Homeserver 的理想选择,其零外部依赖(无需单独数据库)、单二进制文件、资源占用极低的特点,使其成为树莓派、家庭服务器或 VPS 部署的最佳方案。如果您追求简单部署而非企业级功能,Continuwuity 是比 Synapse 更轻量、比 Dendrite 更易用的选择。
配置
## 下载镜像
docker pull forgejo.ellis.link/continuwuation/continuwuity:sha-02b9a3f-maxperf
## 运行
docker run -p 8448:8448 -v /home/qsbye/continuwuation:/var/lib/continuwuity -e CONTINUWUITY_SERVER_NAME="你的域名 your.domain" -e CONTINUWUITY_ALLOW_REGISTRATION=true -e CONTINUWUITY_DATABASE_PATH="/var/lib/continuwuity/continuwuity.db" -e CONTINUWUITY_PORT="8448" -e CONTINUWUITY_ADDRESS="0.0.0.0" --name continuwuity --restart=always -d forgejo.ellis.link/continuwuation/continuwuity:sha-02b9a3f-maxperf
docker logs continuwuity
docker ps
注意看日志输出,会输出一段初始密钥(registration token),需要使用初始密钥去注册,第一个注册的用户为管理员。
2026-02-23T01:43:55.978063Z INFO conduwuit_router::serve::plain: Listening on [127.0.0.1:8008, [::1]:8008]
============
Welcome to Continuwuity 0.5.5 (02b9a3f)!
In order to use your new homeserver, you need to create its first user account.
Open your Matrix client of choice and register an account on your.domain using the registration token 7fvLSaAZPMYwaLLq . Pick your own username and password!
Nobody else will be able to register until you create an account using the token above.
Find a list of Matrix clients here: https://matrix.org/ecosystem/clients/
If you're running the server interactively, you may also create the first user through the admin console using the `users create-user` command. Press Ctrl-C to open the console.
If you need assistance setting up your homeserver, make a Matrix account on another homeserver and join our chatroom: https://matrix.to/#/#continuwuity:continuwuity.org
============
matrix客户端设置服务器[http://your.domain:8448]即可注册.
管理员登陆后可以看到一个默认的管理员专用房间,可以执行例如创建用户之类的命令.
!admin --help
Usage: !admin <COMMAND>
Commands:
appservices Commands for managing appservices
users Commands for managing local users
token Commands for managing registration tokens
rooms Commands for managing rooms
federation Commands for managing federation
server Commands for managing the server
media Commands for managing media
check Commands for checking integrity
debug Commands for debugging things
query Low-level queries for database getters and iterators
help Print this message or the help of the given subcommand(s)
Options:
-h, --help Print help
-V, --version Print version
Commands for managing local users
Usage: !admin users <COMMAND>
Commands:
create-user Create a new user
reset-password Reset user password
deactivate Deactivate a user
deactivate-all Deactivate a list of users
logout Forcefully log a user out of all of their devices
suspend Suspend a user
unsuspend Unsuspend a user
lock Lock a user
unlock Unlock a user
enable-login Enable login for a user
disable-login Disable login for a user
list-users List local users in the database
list-joined-rooms Lists all the rooms (local and remote) that the specified user is joined in
force-join-room Manually join a local user to a room
force-leave-room Manually leave a local user from a room
force-leave-remote-room Manually leave a remote room for a local user
force-demote Forces the specified user to drop their power levels to the room default, if their permissions allow and the auth check permits
make-user-admin Grant server-admin privileges to a user
put-room-tag Puts a room tag for the specified user and room ID
delete-room-tag Deletes the room tag for the specified user and room ID
get-room-tags Gets all the room tags for the specified user and room ID
redact-event Attempts to forcefully redact the specified event ID from the sender user
force-join-list-of-local-users Force joins a specified list of local users to join the specified room
force-join-all-local-users Force joins all local users to the specified room
help Print this message or the help of the given subcommand(s)
Options:
-h, --help Print help
效果
| 聊天界面 |
|---|
![]() |


浙公网安备 33010602011771号