@tateisu •
edit-2 2 năm•
book-open matrix.juggler.jpを設置してみたので、インストール手順をメモしておくよ。
----
## Matrixとは
- https://ja.wikipedia.org/wiki/Matrix_(%E3%83%97%E3%83%AD%E3%83%88%E3%82%B3%E3%83%AB)
- https://wiki.matrix-jp.net/what_is_matrix
-----
## reCAPCHAの申し込み
https://github.com/matrix-org/synapse/blob/develop/docs/CAPTCHA_SETUP.md
- https://www.google.com/recaptcha/admin/create でreCAPCHAのキーを作っておく。
- 種類はv2にすること。
- https://github.com/matrix-org/synapse/pull/7324/files Element-DesktopでreCAPCHAエラーが出る問題を回避したい場合、ドメインに「vector」を追加する必要があります。例えばドメインに `matrix.your.domain` と `vector` (はい、` .im`なし) の2つを設定します。
-----
## フォルダ構成
```
/somewhere/matrix/
db/ (自動的に作成される)
redis/ (自動的に作成される)
data/ (自動的に作成される)
homeserver.yaml (自動生成した後に手動で設定する)
matrix1/ (手動で作る)
docker-compose.yml (手動で作る)
static/ (手動で作る)
element-v1.7.22/
```
フォルダを作っておく。
```
mkdir -p /somewhere/matrix/matrix1
mkdir -p /somewhere/matrix/static
```
-----
## Synapse
- Pythonで書かれたサーバ実装の一つ。
- 今回はdockerイメージで雑に入れる。
- https://github.com/matrix-org/synapse/blob/develop/INSTALL.md
- https://github.com/matrix-org/synapse/blob/develop/docs/federate.md
- https://hub.docker.com/r/matrixdotorg/synapse
### docker-compose.ymlの用意
/somewhere/matrix/matrix1/docker-compose.yml を作る。
```
version: '3'
services:
redis:
restart: always
image: redis:4.0-alpine
volumes:
- ../redis:/data
networks:
- internal_network
db:
restart: always
image: postgres:13.2-alpine
volumes:
- ../db:/var/lib/postgresql/data
networks:
- internal_network
environment:
- POSTGRES_PASSWORD=PLEASE_REPLACE_THIS
- POSTGRES_USER=PLEASE_REPLACE_THIS
- POSTGRES_DB=PLEASE_REPLACE_THIS
- POSTGRES_INITDB_ARGS=--encoding=UTF-8 --locale=C
synapse:
restart: always
image: matrixdotorg/synapse:v1.28.0
volumes:
- ../data:/data
environment:
- SYNAPSE_SERVER_NAME=matrix.juggler.jp
- SYNAPSE_REPORT_STATS=yes
ports:
- "PLEASE_REPLACE_THIS:PLEASE_REPLACE_THIS:8008"
networks:
- external_network
- internal_network
networks:
external_network:
internal_network:
internal: true
```
注意点。
- POSTGRES_INITDB_ARGSでエンコーディングとロケールを指定しないとsynapseはエラーを出す。
- SYNAPSE_SERVER_NAMEはあなたのサーバの名前に置き換える。
- ポート指定はnginxからリバースプロキシされたリクエストを受けるアドレスとポートをコンテナ内部の8008に転送するもの。状況にあわせてどうぞ
### generateの実行
generateコマンドを実行して設定ファイルを生成する。
```
$ cd /somewhere/matrix/matrix1
$ docker-compose run --rm synapse generate
```
出力はこんな感じ。
```
Creating network "matrix1_default" with the default driver
Creating matrix1_matrix_run ... done
Creating log config /data/matrix.juggler.jp.log.config
/usr/local/lib/python3.8/site-packages/twisted/conch/ssh/common.py:15: CryptographyDeprecationWarning: int_from_bytes is deprecated, use int.from_bytes instead
from cryptography.utils import int_from_bytes, int_to_bytes
Generating config file /data/homeserver.yaml
Generating signing key file /data/matrix.juggler.jp.signing.key
A config file has been generated in '/data/homeserver.yaml' for server name 'matrix.juggler.jp'. Please review this file and customise it to your needs.
```
### homeserver.yamlの編集
$ cd /somewhere/matrix/data
$ cp -a homeserver.yaml homeserver.yaml.orig
編集内容。
```
$ diff -Naru0 homeserver.yaml.orig homeserver.yaml
--- homeserver.yaml.orig 2021-03-07 01:18:59.548334869 +0900
+++ homeserver.yaml 2021-03-07 11:03:48.131579966 +0900
@@ -52 +52 @@
-#public_baseurl: https://example.com/
+public_baseurl: https://matrix.juggler.jp/
@@ -83 +83 @@
-#allow_public_rooms_without_auth: true
+allow_public_rooms_without_auth: true
@@ -88 +88 @@
-#allow_public_rooms_over_federation: true
+allow_public_rooms_over_federation: true
@@ -287 +287 @@
-#admin_contact: 'mailto:admin@server.com'
+admin_contact: 'mailto:tateisu@gmail.com'
@@ -759,0 +760,5 @@
- name: sqlite3
- args:
- database: /data/homeserver.db
+ name: psycopg2
+ user: matrix
+ password: PLEASE_REPLACE_THIS
+ database: PLEASE_REPLACE_THIS
+ host: db
+ cp_min: 5
+ cp_max: 10
@@ -1063 +1073 @@
-#recaptcha_public_key: "YOUR_PUBLIC_KEY"
+recaptcha_public_key: "PLEASE_REPLACE_THIS"
@@ -1068 +1078 @@
-#recaptcha_private_key: "YOUR_PRIVATE_KEY"
+recaptcha_private_key: "PLEASE_REPLACE_THIS"
@@ -1074 +1084 @@
-#enable_registration_captcha: true
+enable_registration_captcha: true
@@ -1079 +1089 @@
-#recaptcha_siteverify_api: "https://my.recaptcha.site"
+recaptcha_siteverify_api: "https://www.google.com/recaptcha/api/siteverify"
@@ -1118 +1128 @@
-#enable_registration: false
+enable_registration: true
@@ -2225 +2235 @@
- #smtp_host: mail.server
- #smtp_port: 587
- #smtp_user: "exampleusername"
- #smtp_pass: "examplepassword"
+ smtp_host: PLEASE_REPLACE_THIS
+ smtp_port: PLEASE_REPLACE_THIS
+ smtp_user: "PLEASE_REPLACE_THIS"
+ smtp_pass: "PLEASE_REPLACE_THIS"
@@ -2254 +2264 @@
- #notif_from: "Your Friendly %(app)s homeserver <noreply@example.com>"
+ notif_from: "%(app)s notifications <noreply@juggler.jp>"
@@ -2259 +2269 @@
- #app_name: my_branded_matrix_server
+ app_name: "matrix.juggler.jp"
@@ -2277 +2287 @@
- #client_base_url: "http://localhost/riot"
+ client_base_url: "http://matrix.juggler.jp/"
@@ -2780 +2790 @@
- #enabled: true
+ enabled: true
@@ -2785,2 +2795,2 @@
- #host: localhost
- #port: 6379
+ host: redis
+ port: 6379
@@ -2791 +2800,0 @@
```
- SMTPサーバはお手持ちのものを使う。
- database.psycopg2 の指定はdocker-compose.yml のものと揃える。
### 起動、終了、ログ確認
```
$ docker-compose down
$ docker-compose up -d
$ docker-compose logs --tail=100 -f
```
----
## Element-web
SynapseにはWebUIが含まれないのでElementを入れる。
- https://github.com/vector-im/element-web
上記リポジトリのリリースのAssetsから .tar.gz へのリンクをコピーしておく。
```
cd /somewhere/matrix/static
wget https://github.com/vector-im/element-web/releases/download/v1.7.22/element-v1.7.22.tar.gz
tar xvzf element-v1.7.22.tar.gz
cd element-v1.7.22
cp -a config.sample.json config.json
```
config.jsonを編集する。
```
$ diff -Naru1 config.sample.json config.json
--- config.sample.json 2021-03-01 22:20:42.000000000 +0900
+++ config.json 2021-03-07 13:17:12.223214258 +0900
@@ -3,4 +3,4 @@
"m.homeserver": {
- "base_url": "https://matrix-client.matrix.org",
- "server_name": "matrix.org"
+ "base_url": "https://matrix.juggler.jp",
+ "server_name": "Juggler.jp Matrix サービス"
},
@@ -34,2 +35,6 @@
"servers": [
+ "matrix.fedibird.com",
+ "matrix-jp.net",
+ "matrix.sabakan.industries",
+ "nibbana.jp",
"matrix.org"
```
----
## nginx
- https://github.com/matrix-org/synapse/blob/master/docs/reverse_proxy.md
```
$ cat matrix.juggler.jp.conf
server {
listen 80;
listen [::]:80;
server_name matrix.juggler.jp;
location / {
return 301 https://$host$request_uri;
}
}
server {
listen 443 ssl http2;
listen 8448 ssl http2; # for federation
server_name matrix.juggler.jp;
ssl_certificate /etc/letsencrypt/live/juggler.jp/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/juggler.jp/privkey.pem;
(snip TLS関連のなんやかんや)
# Hide nginx version
server_tokens off;
# Enable compression for JS/CSS/HTML bundle, for improved client load times.
# It might be nice to compress JSON, but leaving that out to protect against potential
# compression+encryption information leak attacks like BREACH.
gzip on;
gzip_types text/css application/javascript image/svg+xml;
gzip_vary on;
# Only connect to this site via HTTPS for the two years
add_header Strict-Transport-Security "max-age=63072000";
add_header X-Frame-Options SAMEORIGIN;
add_header X-Content-Type-Options nosniff;
add_header X-XSS-Protection "1; mode=block";
add_header Content-Security-Policy "frame-ancestors 'none'";
# Client Well-Known URI
location /.well-known/matrix/client {
return 200 '{"m.homeserver": {"base_url": "https://matrix.juggler.jp/"}}';
default_type application/json;
add_header Access-Control-Allow-Origin *;
}
# reverse proxy to synapse
location ~* ^(\/_matrix|\/_synapse\/client) {
proxy_pass http://PLEASE_REPLACE_THIS:PLEASE_REPLACE_THIS;
proxy_set_header X-Forwarded-For $remote_addr;
# Nginx by default only allows file uploads up to 1M in size
# Increase client_max_body_size to match max_upload_size defined in homeserver.yaml
client_max_body_size 50M;
}
root /somewhere/matrix/static/element-v1.7.22;
}
```
----
## 管理ユーザの作成
```
docker-compose exec synapse register_new_matrix_user -c /data/homeserver.yaml http://localhost:8008 -u tateisu -p XXXXXXXXX -a
```
- https://github.com/matrix-org/synapse/blob/develop/debian/register_new_matrix_user.ronn でオプションの説明を読める。
- この手順で作るとアカウントのクロス署名が設定されず暗号化メッセージを読めない状態になる。ログイン後にアカウント設定からセットアップできる。[別記事:「このログインを承認」とクロス署名](https://lemmy.juggler.jp/post/761) を参照のこと
----
## 動作確認
- https://matrix.juggler.jp/_matrix/client/versions をブラウザで開いて、何かJSONぽいものが出力されるか確認する。ダメならnginxのログやsynapseのログを確認する。
- https://matrix.juggler.jp/.well-known/matrix/client をブラウザで開いて、他サーバの同pathの内容と比較する。
- https://matrix.juggler.jp/ を開いてElement-webが表示されるか確認する。
- 管理ユーザとは別にアカウントを作成して、reCAPTCHAやメールアドレス認証が正常に行われるか確認する。
----
# その他
- [VoIP用にturnサーバを設置してみる](https://lemmy.juggler.jp/post/769)