Open10

ConoHa VPSでMisskeyを構築する

栗林健太郎栗林健太郎

VPSにSSHログインすると、Misskeyの設定情報が出てきます。

$ ssh root@160.251.211.12 -i .ssh/conoha.pem

...

================================================
Misskey Apprication

This Misskey template image is configured and running as Developer mode.
When you run Misskey server as production, You should configure domain name and SSL/TLS certification.

Please check official installation guide.
https://misskey-hub.net/docs/install/ubuntu-manual.html

MisskeyURL            : http://160.251.211.12:3000

Misskey Directory     : /home/misskey/misskey/
Misskey db name       : misskey
Misskey user name     : **********
Misskey user password : **********

To delete this message: rm -f /etc/motd
================================================

...
栗林健太郎栗林健太郎

TLS証明書を設定します。ドメインはkentarok.orgを用います(以前使っていたけど使わなくなったものを再利用します)。

まずはcertbotをインストール。

apt install certbot

Misskeyアプリケーションイメージを使う|ConoHa VPSサポート」にある通り実行しましょう。

certbot certonly --manual -d kentarok.org --preferred-challenges dns

メールアドレスなどをきかれるので回答します。さらに、_acme-challenge.kentarok.orgに指定された値でTXTレコードを指定するよう指示されます。

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Please deploy a DNS TXT record under the name
_acme-challenge.kentarok.org with the following value:

K1FVCnQDopt4LgTu0Cpn4P-4Nu_2H_gVUhdgtUtbAYE

Before continuing, verify the record is deployed.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Press Enter to Continue

ムームードメインで以下の通り指定します。

設定したあとにターミナルに戻ってEnterを押します。

Waiting for verification...
Cleaning up challenges

IMPORTANT NOTES:
 - Congratulations! Your certificate and chain have been saved at:
   /etc/letsencrypt/live/kentarok.org/fullchain.pem
   Your key file has been saved at:
   /etc/letsencrypt/live/kentarok.org/privkey.pem
   Your cert will expire on 2024-04-07. To obtain a new or tweaked
   version of this certificate in the future, simply run certbot
   again. To non-interactively renew *all* of your certificates, run
   "certbot renew"
 - 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

認証が完了しました。

証明書を取得できているかどうか、確認します。

ls -la /etc/letsencrypt/live/kentarok.org/
total 12
drwxr-xr-x 2 root root 4096 Jan  8 23:36 .
drwx------ 4 root root 4096 Jan  8 23:36 ..
lrwxrwxrwx 1 root root   36 Jan  8 23:36 cert.pem -> ../../archive/kentarok.org/cert1.pem
lrwxrwxrwx 1 root root   37 Jan  8 23:36 chain.pem -> ../../archive/kentarok.org/chain1.pem
lrwxrwxrwx 1 root root   41 Jan  8 23:36 fullchain.pem -> ../../archive/kentarok.org/fullchain1.pem
lrwxrwxrwx 1 root root   39 Jan  8 23:36 privkey.pem -> ../../archive/kentarok.org/privkey1.pem
-rw-r--r-- 1 root root  692 Jan  8 23:36 README

TXTレコードは消しておきましょう。

栗林健太郎栗林健太郎

ドキュメントにある通り、NginxとMisskeyの設定ファイルを更新します。

ドキュメントでは触れられていませんでしたが、証明書のパスも指定したドメインに合わせて変更しておきましょう。

# To use Let's Encrypt certificate
ssl_certificate     /etc/letsencrypt/live/kentarok.org/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/kentarok.org/privkey.pem;

設定ファイルを編集したら、サービスをリスタートします。

systemctl restart misskey
systemctl restart nginx
栗林健太郎栗林健太郎

ついでにオブジェクトストレージを使ってみる。Cloudflare R2を使う。

10GB/月まで無料とのことで、個人利用なので使い切ることはなさそう。

Pricing · Cloudflare R2 docs

バケットを作成。

APIトークンを作成。上記のバケットの読み書き権限をつける。

ファイルへのアクセス用ドメインは、r2.devを使う。

制限があるようだけど、こちらも個人利用なら問題なさそう。

Limits · Cloudflare R2 docs

Misskeyのオブジェクトストレージの設定画面で、以下の通り設定。

  • Base URL: https://pub-4babc3d0927c485fac6e21e87af5cae6.r2.dev/misskey-kentarokuribayashi-com
  • Bucket: misskey-kentarokuribayashi-com
  • Prefix: files
  • Endpoint: d5c6d3f1021af73c52574f0b912a81f1.r2.cloudflarestorage.com/misskey-kentarokuribayashi-com
  • Region: us-east-1(リージョンはR2が自動的にいい感じにしてくれるが、とりあえず設定しておく必要がある)
  • Access Key: APIトークンページのものを設定
  • Secret Key: 同上

これでノートに画像を添付してみると、こんなURLで参照できるようになった。

https://pub-4babc3d0927c485fac6e21e87af5cae6.r2.dev/misskey-kentarokuribayashi-com/files/abea3072-7bbd-4637-be49-984e83797560.webp

栗林健太郎栗林健太郎

Misskey本体のアップデートをする。

公式ドキュメント「Misskeyのアップデート方法 」に従ってやっていく。

masterのHEADにしたのち、以下のコマンドでエラー。Node.jsのバージョンが古い。しかし、Ubuntuパッケージではこれが最新版。

NODE_ENV=production pnpm install --frozen-lockfile
 ERR_PNPM_UNSUPPORTED_ENGINE  Unsupported environment (bad pnpm and/or Node.js version)

Your Node version is incompatible with "/home/misskey/misskey/packages/backend".

Expected version: >=20.10.0
Got: v20.5.1

This is happening because the package's manifest has an engines.node field specified.
To fix this issue, install the required Node version.

【Mastodon・Misskey・Firefish】Node.jsのアップデート方法をおさらいする | ほしぱそ。」にならってやっていく。

無事更新できた。