ユーザ用ツール

サイト用ツール


mastodon

差分

このページの2つのバージョン間の差分を表示します。

この比較画面へのリンク

両方とも前のリビジョン前のリビジョン
次のリビジョン
前のリビジョン
mastodon [2021/03/02 11:02] – [更新] arakimastodon [2022/11/16 14:04] (現在) – [更新] araki
行 29: 行 29:
  
 そこで、本サイトは手作業で全てを構築することとした。 そこで、本サイトは手作業で全てを構築することとした。
 +
 +その後、さすがに Vine Linuxを使い続けるのは困難になり Ubuntuへ、また、Raspberry Pi2Bはさすがに非力となったため、Tinker Boardを経て、結局x64の Ubuntuへと移行し、Ubuntu(x64)の二台で、リバースプロキシー+Mastodon とバックエンドのサービスとをそれぞれ担い運用している。
 +
 +なお、今現在も Dockerを利用することなく、構築している。
  
 ===== Nginx  ===== ===== Nginx  =====
行 42: 行 46:
 なので、Nginx.orgのレポジトリを使って導入する。 なので、Nginx.orgのレポジトリを使って導入する。
  
-レポジトリーをaptに追加するに先だち、キーを導入する。+レポジトリーをaptに追加するに先だち、キーを導入する。((キーに対してgpg --dearmorするとしているサイトもあるが、しなくていい。))((apt-keyは非推奨になったので使わない。))
  
 <code> <code>
-wget http://nginx.org/keys/nginx_signing.key +sudo curl -fsSL https://nginx.org/keys/nginx_signing.key -o /usr/share/keyrings/nginx_signing.key
-# apt-key add nginx_signing.key+
 </code> </code>
 +
  
 ARM用のバイナリは提供されていないようなので、sourceのレポジトリだけを追加する。 ARM用のバイナリは提供されていないようなので、sourceのレポジトリだけを追加する。
 +x64環境の場合は普通にバイナリパッケージを取得すればいい。
 /etc/apt/souces.list.d/nginx.list をつくり、次の行を書き込む。 /etc/apt/souces.list.d/nginx.list をつくり、次の行を書き込む。
  
 <code> <code>
-deb-src http://nginx.org/packages/debianjessie nginx+deb [signed-by=/usr/share/keyrings/nginx_signing.key] http://nginx.org/packages/ubuntu/ jammy nginx 
 +deb-src [signed-by=/usr/share/keyrings/nginx_signing.key] http://nginx.org/packages/ubuntujammy nginx
 </code> </code>
  
行 72: 行 78:
 ==== 設定  ==== ==== 設定  ====
  
-/etc/nginx/conf.d/mastodon.conf を次のように作成する。mastodon本体は /var/www/mastodon/prodに置き、SSL証明書はLet's Encryptで取得することとする。+/etc/nginx/conf.d/mastodon.conf を次のように作成する。mastodon本体は /var/www/mastodon/liveに置き、SSL証明書はLet's Encryptで取得することとする。
  
 なお、minioをMastodon本体と別のサーバ上に構築するのでなければ、証明書はオレオレ証明書でも問題は無い。((詳しくは後述するが、オレオレ証明書で minioとMastodonとを別のサーバ上に構築すると画像へのアクセスのためのSSL証明書が信頼できないため、アバターを含めて一切の画像が表示されないことになる。)) なお、minioをMastodon本体と別のサーバ上に構築するのでなければ、証明書はオレオレ証明書でも問題は無い。((詳しくは後述するが、オレオレ証明書で minioとMastodonとを別のサーバ上に構築すると画像へのアクセスのためのSSL証明書が信頼できないため、アバターを含めて一切の画像が表示されないことになる。))
 +
 +なお、古い実装((3.5より前?))では、mstdn_streaming がなかったので streaming についても、mstdn_handler に渡していたが、現在は変わっているので、古い実装から新しいバージョンへ移行する際には注意が必要である。((本体の置き場所も prodではなくliveになっていたりする。prodのままにすることもできるが。))
  
 <code> <code>
 upstream mstdn_handler { upstream mstdn_handler {
-    server localhost:3000;+    server 127.0.0.1:3000
 +
 + 
 +upstream mstdn_streaming { 
 +    server 127.0.0.1:4000 fail_timeout=0;
 } }
  
行 112: 行 124:
    client_max_body_size 0;    client_max_body_size 0;
  
-   root /var/www/mastodon/prod/public;+   root /var/www/mastodon/live/public;
  
    gzip on;    gzip on;
行 152: 行 164:
        proxy_set_header X-Forwarded-For        $proxy_add_x_forwarded_for;        proxy_set_header X-Forwarded-For        $proxy_add_x_forwarded_for;
        proxy_set_header Proxy "";        proxy_set_header Proxy "";
-       proxy_pass http://mstdn_handler;+       proxy_pass http://mstdn_streaming;
        proxy_buffering off;        proxy_buffering off;
        proxy_redirect off;        proxy_redirect off;
行 225: 行 237:
 <code> <code>
 # su - nginx # su - nginx
-$ git clone https://github.com/sstephenson/rbenv.git ~/.rbenv +$ git clone https://github.com/rbenv/rbenv.git ~/.rbenv 
-$ git clone https://github.com/sstephenson/ruby-build.git ~/.rbenv/plugins/ruby-build+$ mkdir ~/.rbenv/plugins 
 +$ git clone https://github.com/rbenv/ruby-build.git ~/.rbenv/plugins/ruby-build 
 +$ git clone https://github.com/rbenv/rbenv-default-gems.git ~/.rbenv/plugins/rbenv-default-gems 
 +$ echo bundler > ~/.rbenv/default-gems 
 +$ echo byebug >> ~/.rbenv/default-gems
 </code> </code>
  
行 361: 行 377:
 Go言語で記述されているとのこと。 Go言語で記述されているとのこと。
  
 +Github から、ソースを取得して自力で構築することも可能である。
 +その場合、Goのバージョンが問題となるので、goenvなどで、任意のバージョンを利用できる環境を準備しておくべきである。
 +
 +ビルドは、makeするだけである。
 +Goのバージョンに問題があれば、どのバージョン以上が必要かレポートされるので、goenv install <バージョン> し、goenv global <バージョン> するなどしてからビルドをやり直す。
 +
 +<code>
 +$ git clone https://github.com/minio/minio.git
 +$ cd minio
 +$ make
 +$ install -m 0755 minio /usr/local/bin
 +</code>
 ==== インストールと設定  ==== ==== インストールと設定  ====
  
行 565: 行 593:
 # mkdir /var/www/mastodon # mkdir /var/www/mastodon
 # cd mastodon # cd mastodon
-# git clone https://github.com/tootsuite/mastodon.git prod+# git clone https://github.com/mastodon/mastodon.git live
 # chown -R nginx.nginx /var/www/mastodon # chown -R nginx.nginx /var/www/mastodon
 </code> </code>
  
-当サイトでは、/var/www/mastodon/prod に展開して使っている。+当サイトでは、/var/www/mastodon/live に展開して使っている。
 実行権限は nginxにすることにした。 実行権限は nginxにすることにした。
  
行 576: 行 604:
 <code> <code>
 # su - nginx # su - nginx
-$ cd /var/www/mastodon/prod+$ cd /var/www/mastodon/live
 $ gem install bundler $ gem install bundler
 $ bundle install --deployment --without development test $ bundle install --deployment --without development test
行 640: 行 668:
 Type=simple Type=simple
 User=nginx User=nginx
-WorkingDirectory=/var/www/mastodon/prod+WorkingDirectory=/var/www/mastodon/live
 Environment="RAILS_ENV=production" Environment="RAILS_ENV=production"
 Environment="PORT=3000" Environment="PORT=3000"
行 660: 行 688:
 Type=simple Type=simple
 User=nginx User=nginx
-WorkingDirectory=/var/www/mastodon/prod+WorkingDirectory=/var/www/mastodon/live
 Environment="RAILS_ENV=production" Environment="RAILS_ENV=production"
 Environment="DB_POOL=5" Environment="DB_POOL=5"
行 680: 行 708:
 Type=simple Type=simple
 User=nginx User=nginx
-WorkingDirectory=/var/www/mastodon/prod+WorkingDirectory=/var/www/mastodon/live
 Environment="NODE_ENV=production" Environment="NODE_ENV=production"
 Environment="PORT=4000" Environment="PORT=4000"
行 695: 行 723:
 <code> <code>
 # su - nginx # su - nginx
-$ cd /var/www/mastodon/prod+$ cd /var/www/mastodon/live
 $ RAILS_ENV=production bundle exec rails db:setup $ RAILS_ENV=production bundle exec rails db:setup
 $ RAILS_ENV=production bundle exec rails assets:precompile $ RAILS_ENV=production bundle exec rails assets:precompile
行 780: 行 808:
  
 <code> <code>
-$ RAILS_ENV=production bundle exec rails db:migrate+SKIP_POST_DEPLOYMENT_MIGRATION=true RAILS_ENV=production bundle exec rails db:migrate
 </code> </code>
  
行 786: 行 814:
 $ RAILS_ENV=production bundle exec rails assets:precompile $ RAILS_ENV=production bundle exec rails assets:precompile
 </code> </code>
 +
 +DBのマイグレーションは二段階に分けて行うようになっています。
 +プロセスを再起動する前の分と、再起動後の分とをSKIP_POST_DEPLOYMENT_MIGRATIONという環境変数で切り替えて行います。
  
 <code> <code>
行 791: 行 822:
 </code> </code>
  
 +<code>
 +$ RAILS_ENV=production bundle exec rails db:migrate
 +</code>
 ==== メモ  ==== ==== メモ  ====
  
mastodon.1614650566.txt.gz · 最終更新: 2021/03/02 11:02 by araki