Conduit:基于Matrix的轻量级开源聊天服务器

conduit是用rust写的,目标是打造一个高效且易于部署的matrix服务器。conduit的官网:https://conduit.rs/

部署conduit,安装需要用到的软件包:

apt -y update
apt -y install curl nginx python3-certbot-nginx

下载conduit:

curl -L "https://gitlab.com/famedly/conduit/-/jobs/artifacts/master/raw/conduit-aarch64-unknown-linux-musl?job=build:release:cargo:aarch64-unknown-linux-musl" -o /usr/local/bin/matrix-conduit

给执行权限:

chmod +x /usr/local/bin/matrix-conduit

创建conduit用户:

adduser --system conduit --no-create-home

新建systemd服务:

nano /etc/systemd/system/conduit.service

写入如下配置:

[Unit]
Description=Conduit Matrix Server
After=network.target

[Service]
Environment="CONDUIT_CONFIG=/etc/matrix-conduit/conduit.toml"
User=conduit
Group=nogroup
Restart=always
ExecStart=/usr/local/bin/matrix-conduit

[Install]
WantedBy=multi-user.target

创建配置文件存放目录以及新建配置文件:

mkdir /etc/matrix-conduit && nano /etc/matrix-conduit/conduit.toml

写入如下配置:

[global]
server_name = "conduit.example.com" # 换成你的域名
database_path = "/var/lib/matrix-conduit/"
database_backend = "rocksdb"
port = 6167
max_request_size = 20_000_000 # 最大文件上传大小单位字节
allow_registration = true
allow_federation = true
trusted_servers = ["matrix.org"]
max_concurrent_requests = 500
#log = "info,state_res=warn,rocket=off,_=off,sled=off"
address = "127.0.0.1"

给予正确的权限:

chown -R root:root /etc/matrix-conduit
chmod 755 /etc/matrix-conduit

创建数据库文件存放目录以及给予正确的权限:

mkdir -p /var/lib/matrix-conduit/
chown -R conduit:nogroup /var/lib/matrix-conduit/
chmod 700 /var/lib/matrix-conduit/

启动conduit并设置开机自启:

systemctl enable --now conduit

配置反向代理,新建nginx站点配置文件:

nano /etc/nginx/conf.d/conduit.conf

写入如下配置:

server {
    listen 80;
    server_name conduit.example.com;
    merge_slashes off;
    client_max_body_size 0;

    location /_matrix/ {
        proxy_pass http://127.0.0.1:6167$request_uri;
        proxy_set_header Host $http_host;
        proxy_buffering off;
        proxy_connect_timeout 600;
        proxy_read_timeout 600;
        proxy_send_timeout 600;
    }

    location /.well-known/matrix/server {
        return 200 '{ "m.server": "conduit.example.com:443" }';
    }

    location /.well-known/matrix/client {
        add_header Access-Control-Allow-Origin '*';
        return 200 '{ "m.homeserver": { "base_url": "https://conduit.example.com" } }';
    }
}

签发ssl证书:

certbot --nginx

之后还需要修改一下之前新建的nginx站点配置文件:

nano /etc/nginx/conf.d/conduit.conf

在原本的基础上额外添加一个8448端口的监听,以及启用http2:

listen 8448 ssl http2;
listen 443 ssl http2; # managed by Certbot

重载nginx使配置生效:

systemctl reload nginx

至此conduit就搭建完成了,测试你搭建的服务是否正常:

curl https://conduit.example.com/_matrix/client/versions
curl https://conduit.example.com:8448/_matrix/client/versions

如果正常会有类似回显:

{"versions":["r0.5.0","r0.6.0","v1.1","v1.2"],"unstable_features":{"org.matrix.e2e_cross_signing":true}}

也可以使用这个网站测试:https://federationtester.matrix.org/

检测全部都没问题的话,如下图所示:

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注