Ubuntu 22.04にMatrix Synapseチャットサーバーをインストールする方法
Ubuntu 22.04にMatrix Synapseチャットサーバーをインストールする方法
このチュートリアルはこれらのOSバージョンのために存在します
- Ubuntu 22.04(ジャミー・ジェリーフィッシュ)
- Ubuntu 20.04 (フォーカルフォッサ)
- Ubuntu 18.04 (ビオニックビーバー)
このページで
- 前提条件
- 始めに
- Ubuntu 22.04にMatrix Synapseをインストールする
- マトリックスシナプスを設定する
- Matrix SynapseのためにNginxをリバースプロキシとして構成する
- スーパーユーザーアカウントを作成する
- Let's Encryptでセキュアマトリックスシナプス
- アクセスマトリックスシナプス
- 結論
MatrixはメッセージングおよびVoIPサービス用の無料でオープンソースのウェブベースのソリューションです。これは、音声通話やチャットを通じて異なるサービスプロバイダーの他のユーザーとコミュニケーションを取ることを可能にするオープンスタンダードのVOIPプロトコルです。Matrixは、単一の制御点や故障がない分散型および連邦型チャットサーバーを構築するためのRESTful HTTP JSON APIを提供し、APIに関するすべてのリファレンスを提供します。それはPythonで書かれており、自分のホームサーバーを作成し、すべてのユーザーの個人情報とチャット履歴を保存することを可能にします。
この記事では、Ubuntu 22.04にMatrix Synapseをインストールする方法を紹介します。
前提条件
- Ubuntu 22.04を実行しているサーバー。
- サーバーIPにポイントされた有効なドメイン名。
- サーバーにはルートパスワードが設定されています。
始めに
まず、システムパッケージを最新のバージョンに更新する必要があります。以下のコマンドを使用して行うことができます。
apt update -yすべてのパッケージインデックスが更新されたら、次のコマンドを使用して他の必要な依存関係をインストールします:
apt install curl wget gnupg2 apt-transport-https -yすべての依存関係がインストールされると、次のステップに進むことができます。
Ubuntu 22.04にMatrix Synapseをインストールする
デフォルトでは、Matrix Synapse パッケージは Ubuntu 22.04 のデフォルトリポジトリには含まれていません。したがって、APT に Matrix Synapse の公式リポジトリを追加する必要があります。
まず、次のコマンドを使用してMatrix SynapseのGPGキーをダウンロードし、追加します:
wget -qO /usr/share/keyrings/matrix-org-archive-keyring.gpg https://packages.matrix.org/debian/matrix-org-archive-keyring.gpg次に、次のコマンドを使用してAPTにMatrix Synapseリポジトリを追加します:
echo "deb [signed-by=/usr/share/keyrings/matrix-org-archive-keyring.gpg] https://packages.matrix.org/debian/ $(lsb_release -cs) main" | tee /etc/apt/sources.list.d/matrix-org.list次に、リポジトリを更新し、次のコマンドを使用してMatrix Synapseパッケージをインストールします:
apt-get update -y
apt-get install matrix-synapse-py3 -yインストール中に、以下のようにドメイン名を定義するよう求められます:
ドメイン名を入力し、Enterキーを押してください。匿名統計を報告するように求められます。
はいを選択し、Enterキーを押して続けてください。
インストールが完了したら、Matrixサービスを起動し、以下のコマンドを使用してシステム再起動時に開始できるようにします:
systemctl start matrix-synapse
systemctl enable matrix-synapse
次のコマンドでMatrix Synapseのステータスを確認することもできます:
systemctl status matrix-synapse次の出力が得られます:
? matrix-synapse.service - Synapse Matrix homeserver
Loaded: loaded (/lib/systemd/system/matrix-synapse.service; enabled; vendor preset: enabled)
Active: active (running) since Sat 2022-06-04 08:01:22 UTC; 3s ago
Process: 1916 ExecStartPre=/opt/venvs/matrix-synapse/bin/python -m synapse.app.homeserver --config-path=/etc/matrix-synapse/homeserver.ya>
Main PID: 1923 (python)
Tasks: 8 (limit: 9460)
Memory: 78.6M
CPU: 4.911s
CGroup: /system.slice/matrix-synapse.service
??1923 /opt/venvs/matrix-synapse/bin/python -m synapse.app.homeserver --config-path=/etc/matrix-synapse/homeserver.yaml --config>
Jun 04 08:01:17 ubuntu2204 systemd[1]: Starting Synapse Matrix homeserver...
Jun 04 08:01:22 ubuntu2204 matrix-synapse[1923]: This server is configured to use 'matrix.org' as its trusted key server via the
Jun 04 08:01:22 ubuntu2204 matrix-synapse[1923]: 'trusted_key_servers' config option. 'matrix.org' is a good choice for a key
Jun 04 08:01:22 ubuntu2204 matrix-synapse[1923]: server since it is long-lived, stable and trusted. However, some admins may
Jun 04 08:01:22 ubuntu2204 matrix-synapse[1923]: wish to use another server for this purpose.
Jun 04 08:01:22 ubuntu2204 matrix-synapse[1923]: To suppress this warning and continue using 'matrix.org', admins should set
Jun 04 08:01:22 ubuntu2204 matrix-synapse[1923]: 'suppress_key_server_warning' to 'true' in homeserver.yaml.
Jun 04 08:01:22 ubuntu2204 matrix-synapse[1923]: --------------------------------------------------------------------------------
Jun 04 08:01:22 ubuntu2204 matrix-synapse[1923]: Config is missing macaroon_secret_key
この時点で、Matrix Synapseサービスが起動し、ポート8008で待機しています。以下のコマンドで確認できます。
ss -antpl | grep python次の出力が得られます:
LISTEN 0 50 127.0.0.1:8008 0.0.0.0:* users:(("python",pid=1950,fd=12))
LISTEN 0 50 [::1]:8008 [::]:* users:(("python",pid=1950,fd=11))
マトリックスシナプスを設定する
Matrix Synapseをインストールした後は、それを設定する必要があります。まず、次のコマンドを使用してシークレットを作成します:
cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 32 | head -n 1次の出力が得られます:
R3jvgiDYyhh5XgduDPsgtwxPDiar8q2s
次に、Matrix Synapseのデフォルト設定ファイルを編集します。
nano /etc/matrix-synapse/homeserver.yamlバインドアドレスを定義し、登録を無効にし、以下に示すように秘密情報を定義してください:
bind_addresses: ['127.0.0.1']
enable_registration: false
registration_shared_secret: "R3jvgiDYyhh5XgduDPsgtwxPDiar8q2s"
ファイルを保存して閉じてから、変更を適用するためにMatrix Synapseサービスを再起動してください:
systemctl restart matrix-synapseMatrix SynapseのためにNginxをリバースプロキシとして構成する
Matix SynapseのためにNginxをリバースプロキシとして設定するのは良いアイデアです。まず、次のコマンドでNginxウェブサーバーパッケージをインストールします:
apt-get install nginx -y
Nginxがインストールされたら、Nginxの仮想ホスト設定ファイルを作成します:
nano /etc/nginx/conf.d/matrix.conf次の設定を追加してください:
server {
listen 80;
server_name matrix.linuxbuz.com;
location / {
proxy_pass http://localhost:8008;
proxy_set_header X-Forwarded-For $remote_addr;
}
}
ファイルを保存して閉じて、以下のコマンドを使用してNginxの設定を確認してください:
nginx -t次の出力が得られます:
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
次に、変更を適用するためにNginxサービスを再起動します:
systemctl restart nginx次のコマンドを使用して、Nginxサーバーのステータスを確認することもできます。
systemctl status nginx次の出力が表示されるはずです:
? nginx.service - A high performance web server and a reverse proxy server
Loaded: loaded (/lib/systemd/system/nginx.service; enabled; vendor preset: enabled)
Active: active (running) since Sat 2022-06-04 08:06:22 UTC; 26s ago
Docs: man:nginx(8)
Process: 2433 ExecStartPre=/usr/sbin/nginx -t -q -g daemon on; master_process on; (code=exited, status=0/SUCCESS)
Process: 2434 ExecStart=/usr/sbin/nginx -g daemon on; master_process on; (code=exited, status=0/SUCCESS)
Main PID: 2436 (nginx)
Tasks: 5 (limit: 9460)
Memory: 4.8M
CPU: 58ms
CGroup: /system.slice/nginx.service
??2436 "nginx: master process /usr/sbin/nginx -g daemon on; master_process on;"
??2437 "nginx: worker process" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" ""
??2438 "nginx: worker process" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" ""
??2439 "nginx: worker process" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" ""
??2440 "nginx: worker process" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" ""
Jun 04 08:06:22 ubuntu2204 systemd[1]: Starting A high performance web server and a reverse proxy server...
Jun 04 08:06:22 ubuntu2204 systemd[1]: Started A high performance web server and a reverse proxy server.
スーパーユーザーアカウントを作成する
次に、管理者ユーザーアカウントを作成し、Matrix Synapseにアクセスするためのパスワードを設定する必要があります。
register_new_matrix_user -c /etc/matrix-synapse/homeserver.yaml http://localhost:8008管理者ユーザーアカウントを提供し、以下のようにパスワードを設定してください。
New user localpart [root]: matrixadmin
Password:
Confirm password:
Make admin [no]: yes
Sending registration request...
Success!
Let's Encryptでセキュアマトリックスシナプス
Matrix SynapseをLet's Encrypt SSLで保護することも推奨されます。最初に、以下のコマンドを使用してCertbotクライアントパッケージをインストールしてください:
apt-get install certbot python3-certbot-nginx -yCertbotパッケージがインストールされたら、次のコマンドを実行してLet's Encrypt SSLをインストールします。
certbotメールアドレスを提供し、利用規約に同意するよう求められます:
Saving debug log to /var/log/letsencrypt/letsencrypt.log
Enter email address (used for urgent renewal and security notices)
(Enter 'c' to cancel): [email
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Please read the Terms of Service at
https://letsencrypt.org/documents/LE-SA-v1.2-November-15-2017.pdf. You must
agree in order to register with the ACME server. Do you agree?
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
(Y)es/(N)o: Y
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Would you be willing, once your first certificate is successfully issued, to
share your email address with the Electronic Frontier Foundation, a founding
partner of the Let's Encrypt project and the non-profit organization that
develops Certbot? We'd like to send you email about our work encrypting the web,
EFF news, campaigns, and ways to support digital freedom.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
(Y)es/(N)o: Y
Account registered.
SSLをインストールするウェブサイトを選択するよう求められます。
Which names would you like to activate HTTPS for?
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
1: matrix.linuxbuz.com
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Select the appropriate numbers separated by commas and/or spaces, or leave input
blank to select all options shown (Enter 'c' to cancel): 1
1をタイプしてEnterキーを押すと、あなたのウェブサイトにLet's Encrypt SSLをインストールします。
Requesting a certificate for matrix.linuxbuz.com
Successfully received certificate.
Certificate is saved at: /etc/letsencrypt/live/matrix.linuxbuz.com/fullchain.pem
Key is saved at: /etc/letsencrypt/live/matrix.linuxbuz.com/privkey.pem
This certificate expires on 2022-09-02.
These files will be updated when the certificate renews.
Certbot has set up a scheduled task to automatically renew this certificate in the background.
Deploying certificate
Successfully deployed certificate for matrix.linuxbuz.com to /etc/nginx/conf.d/matrix.conf
Congratulations! You have successfully enabled HTTPS on https://matrix.linuxbuz.com
We were unable to subscribe you the EFF mailing list because your e-mail address appears to be invalid. You can try again later by visiting https://act.eff.org.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
If you like Certbot, please consider supporting our work by:
* Donating to ISRG / Let's Encrypt: https://letsencrypt.org/donate
* Donating to EFF: https://eff.org/donate-le
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
アクセスマトリックスシナプス
ウェブブラウザーでhttps://matrix.linuxbuz.comのURLを使用して、Matrix Synapseのインストールを確認できます。次の画面が表示されるはずです:
Riotのウェブベースのクライアントhttps://riot.im/app/#/loginを使用して、Matrix Synapseを確認することもできます。次の画面が表示されるはずです:
編集ボタンをクリックしてください。次の画面が表示されるはずです:
続けるボタンをクリックし、あなたのMatrixサーバーのURLを入力してください。Matrixのログインページが表示されるはずです:
管理者ユーザー名とパスワードを入力し、サインインボタンをクリックしてください。Matrix Synapseサーバーに接続されると、次の画面が表示されるはずです:
結論
この記事では、Ubuntu 22.04サーバーでNginxをリバースプロキシとして使用してMatrix Synapseをインストールする方法を学びました。また、Riotウェブベースのクライアントを使ってMatrix Synapseを確認しました。これで、Matrix Synapseを使用して独自のVOIPサーバーを構築できます。






