LoginSignup
2
2

More than 3 years have passed since last update.

マストドン構築3日目 on AWS

Last updated at Posted at 2020-01-28

経緯

前回書いた マストドン構築2日目 on AWS の続きです。

半年ほど前に AWS & Docker ド素人の状態から
なんとかインスタンスをたてて運用していました。

EC2の上にDockerで本番運用していましたが、だんだん辛くなってきたのでDockerから降ろすことにしました。
その作業ログです。

環境 / ツール

macOS Mojavi 10.14.6
AWS

参考にしたもの

マストドンGitHub
https://github.com/tootsuite/mastodon
公式ドキュメント
https://docs.joinmastodon.org/admin/install/

サーバー内での作業

まずサーバーにsshログインします。

$ ssh ubuntu@3.112.***.*** -i ~/.ssh/hoge.pem

作業に入る前に、とりあえずrootユーザーになります。

sudo su -

Nginxのセットアップ

マストドンにあるサンプルをコピーします。

$ cp /home/mastodon/live/dist/nginx.conf /etc/nginx/sites-available/mastodon

シンボリックリンクを書き換えます。

$ ln -s /etc/nginx/sites-available/mastodon /etc/nginx/sites-enabled/mastodon
$ vi /etc/nginx/sites-available/mastodon

server_nameなどを編集し、ファイル名を自身のドメイン名にします。

$ mv mastodon don.suwa3.me

nginxをリロードしたら、エラーが出ました。

$ service nginx reload
Job for nginx.service failed because the control process exited with error code.
See "systemctl status nginx.service" and "journalctl -xe" for details.

serviceコマンドでconfig testをしてみます。

$ service nginx configtest
 * Testing nginx configuration                                                                                       [fail] 

nginxコマンドで原因究明です。
No such file or directoryとのことです。

$ nginx -t
nginx: [emerg] open() "/etc/nginx/sites-enabled/mastodon" failed (2: No such file or directory) in /etc/nginx/nginx.conf:62
nginx: configuration file /etc/nginx/nginx.conf test failed

移動して

$ cd ../sites-enabled/

シンボリックリンクの向き先を確認します。

$ ls -l
total 0
lrwxrwxrwx 1 root root 34 Jan 13 10:03 default -> /etc/nginx/sites-available/default
lrwxrwxrwx 1 root root 35 Jan 28 05:22 mastodon -> /etc/nginx/sites-available/mastodon

mastodon部分をdon.suwa3.meに書き換えます。

$ ln -sf /etc/nginx/sites-available/don.suwa3.me mastodon

リロードできました。

$ service nginx reload

念の為ステータスの確認をします。
Active: active (running)になっているのでOKです。

$ service nginx status
● 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) (Result: exit-code) since Tue 2020-01-28 05:16:57 CET; 31min ago
(略)

SSL証明書の取得

Let's Encryptを使用して、無料のSSL証明書を取得します。
example.comは自身のドメイン名に書き換えます。

$ certbot --nginx -d example.com

systemdサービスのセットアップ

systemdサービステンプレートをMastodonディレクトリからコピーします。

$ cp /home/mastodon/live/dist/mastodon-*.service /etc/systemd/system/

念の為、ユーザー名とパスが正しいことを確認します。

  • /etc/systemd/system/mastodon-web.service
  • /etc/systemd/system/mastodon-sidekiq.service
  • /etc/systemd/system/mastodon-streaming.service

新しいsystemdサービスを開始して有効にします。

$ systemctl daemon-reload
$ systemctl start mastodon-web mastodon-sidekiq mastodon-streaming
$ systemctl enable mastodon-*

次回予告

4日目はDBの引っ越しやメディアサーバーなどの接続です。
作業が進み次第、Qiitaに作業ログを残したいと思います。

2
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
2