このチュートリアルでは、Debian9VPSにMastodonをインストールするプロセスをガイドして説明します。
マストドンは、オープンウェブプロトコルに基づくオープンソースの無料ソーシャルネットワークです。バックエンドにはRubyonRailsを使用し、フロントエンドにはReact.jsとReduxを使用します。このソーシャルメディアプラットフォームはTwitterによく似ており、テキストとメディアの共有に重点を置いています。このプラットフォームはオープンソースであるため、広告なしでプライベートに使用できるプライベートソーシャルネットワークを実行できます。
このガイドは他のLinuxVPSシステムでも機能するはずですが、Debian9VPS用にテストおよび作成されています。インストールプロセスはそれほど長くはかからないはずです。最も長い部分はコンパイルプロセスです。インストールから始めましょう。
前提条件:
- Debian9VPS。
- sudo権限を持つユーザーアカウント、または「root」ユーザー自体へのアクセス。
ステップ1:必要なパッケージをインストールする
rootまたはsudoユーザーとしてSSH経由でVPSにログインします:
ssh userame@IP_Address -p Port_Number
「IP_Address」と「Port_Number」をサーバーのそれぞれのIPアドレスとSSHポート番号に置き換えます。さらに、「username」をrootユーザーの「root」または使用する予定の管理者アカウントの名前に置き換えます。
ログインしたら、次のコマンドを発行して、インストールされているすべてのパッケージを最新の利用可能なバージョンに更新します。
sudo apt-get update sudo apt-get upgrade
次のコマンドを使用して、必要なパッケージをインストールします。
sudo apt-get install curl gcc g++ make \ imagemagick ffmpeg libpq-dev libxml2-dev libxslt1-dev file git-core \ libprotobuf-dev protobuf-compiler pkg-config autoconf \ bison build-essential libssl-dev libyaml-dev libreadline-dev \ zlib1g-dev libncurses5-dev libffi-dev libgdbm-dev \ libidn11-dev libicu-dev libjemalloc-dev
これらのパッケージは、メディア変換からストリーミングサービスまで、Mastodonのすべての要件をカバーしています。
ステップ2:Node.jsとYarnをインストールする
Node.jsとYarnを公式リポジトリからインストールします。
次のcurlコマンドを使用してNodeSourceリポジトリを有効にします。
curl -sL https://deb.nodesource.com/setup_8.x | sudo bash -
Node.js 8.x LTS Carbonとnpmをインストールするには、次のコマンドを実行します:
sudo apt-get install nodejs
Yarn APTリポジトリのGPGキーをインポートし、次のコマンドを実行して有効にします。
curl -sL https://dl.yarnpkg.com/debian/pubkey.gpg | sudo apt-key add - echo "deb https://dl.yarnpkg.com/debian/ stable main" | sudo tee /etc/apt/sources.list.d/yarn.list
次のコマンドを使用してYarnをインストールします。
sudo apt-get update && sudo apt-get install yarn
ステップ3:PostgreSQLをインストールする
Mastodonは、データベースのバックエンドとしてPostgreSQLを使用できます。
PostgreSQLサーバーがサーバーにまだインストールされていない場合は、次のコマンドを実行して最新のPostgreSQLバージョンをインストールできます。
sudo apt-get install postgresql postgresql-contrib
インストールが完了したら、PostgreSQLシェルにログインします。
sudo -u postgres psql
Mastodonインスタンスの新しいユーザーを作成します:
CREATE USER mastodon CREATEDB;
ステップ4:Redisをインストールする
Redisのインストールは非常に簡単です。次のコマンドを実行するだけです:
sudo apt-get install redis-server
ステップ5:新しいシステムユーザーを作成する
Mastodonサーバーを実行する新しいシステムユーザーを作成します。
sudo adduser --home /opt/mastodon --disabled-login --gecos 'Mastodon Application' mastodon
ステップ6:Rubyをインストールする
Rbenvスクリプトを使用してRubyをインストールします。
rbenvリポジトリのクローンを作成する前に、前の手順で作成した新しいマストドンユーザーに切り替えます。
sudo su - mastodon
次のコマンドを使用して「rbenv」と「ruby-build」を設定します。
cd git clone https://github.com/rbenv/rbenv.git ~/.rbenv cd ~/.rbenv && src/configure && make -C src echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bashrc echo 'eval "$(rbenv init -)"' >> ~/.bashrc exec bash git clone https://github.com/rbenv/ruby-build.git ~/.rbenv/plugins/ruby-build
「rbenv」と「ruby-build」の両方を設定したら、次のコマンドを使用して最新のRubyバージョンをインストールします。
RUBY_CONFIGURE_OPTS=--with-jemalloc rbenv install 2.6.1 rbenv global 2.6.1
gemを更新し、bundlerをインストールして、インストールしたばかりのrbenvのバージョンで動作するようにします。:
gem update --system gem install bundler --no-document
すべてが正しく行われたことを確認するには、コマンドruby --version
を使用します 。
出力は次のようになります。
ruby --version ruby 2.6.1p33 (2019-01-30 revision 66950) [x86_64-linux]
ステップ7:マストドンの設定
次のコマンドもマストドンユーザーとして実行されます。
マストドンのgitリポジトリを~/live
に複製します ディレクトリと最新の安定したマストドンブランチへのチェックアウト:
cd git clone https://github.com/tootsuite/mastodon.git ~/live cd ~/live git checkout $(git tag -l | grep -v 'rc[0-9]*$' | sort -V | tail -n 1)
次のコマンドを使用して、rubyの依存関係をインストールします。
bundle install -j$(getconf _NPROCESSORS_ONLN) --deployment --without development test
node.jsの依存関係を次のようにインストールします:
yarn install --pure-lockfile
Mastodonインストールディレクトリに移動し、次のコマンドを実行してセットアップを開始します。
cd ~/live RAILS_ENV=production bundle exec rake mastodon:setup
インストーラーはいくつかの質問をし、新しいアプリシークレットを生成し、データベーススキーマを設定し、アセットをコンパイルします。サーバーのハードウェアによっては、これには時間がかかる場合があります。
Your instance is identified by its domain name. Changing it afterward will break things. Domain name: your-domain.com Single user mode disables registrations and redirects the landing page to your public profile. Do you want to enable single user mode? No Are you using Docker to run Mastodon? no PostgreSQL host: /var/run/postgresql PostgreSQL port: 5432 Name of PostgreSQL database: mastodon_production Name of PostgreSQL user: mastodon Password of PostgreSQL user: Database configuration works! 🎆 Redis host: localhost Redis port: 6379 Redis password: Redis configuration works! 🎆 Do you want to store uploaded files on the cloud? No Do you want to send e-mails from localhost? yes E-mail address to send e-mails "from": Mastodon <[email protected]> Send a test e-mail with this configuration right now? no This configuration will be written to .env.production Save configuration? Yes Now that configuration is saved, the database schema must be loaded. If the database already exists, this will erase its contents. Prepare the database now? Yes Running `RAILS_ENV=production rails db:setup` ... Created database 'mastodon_production' ... Done! The final step is compiling CSS/JS assets. This may take a while and consume a lot of RAM. Compile the assets now? Yes Running `RAILS_ENV=production rails assets:precompile` ... yarn install v1.9.4 ... Using /opt/mastodon/live/config/webpacker.yml file for setting up webpack paths Compiling… Compiled all packs in /opt/mastodon/live/public/packs Rendering errors/500.html.haml within layouts/error Rendered errors/500.html.haml within layouts/error (2596.9ms) Done! All done! You can now power on the Mastodon server 🐘 Do you want to create an admin user straight away? Yes Username: admin E-mail: [email protected] You can login with the password: 7594c5bab89c1f0b0e47438f6074fb02 You can change your password once you login.
完了したら、次を実行してsudoユーザーに戻ります。
exit
ステップ8:Nginxのセットアップ
次のコマンドを使用してNginxとCertbotをインストールします:
sudo apt-get install nginx certbot
Nginxがインストールされたら、MastodonインストールディレクトリからNginx構成テンプレートをコピーします。
sudo cp /opt/mastodon/live/dist/nginx.conf /etc/nginx/sites-available/mastodon.conf sudo ln -s /etc/nginx/sites-available/mastodon.conf /etc/nginx/sites-enabled/mastodon.conf
次のコマンドを実行して、Mastodonインストールディレクトリのパスとドメイン名を変更します。 「your-domain.com」を登録済みのドメイン名に置き換えることを忘れないでください:
sudo sed -i 's/home/opt/g' /etc/nginx/sites-enabled/mastodon.conf sudo sed -i 's/example.com/your-domain.com/g' /etc/nginx/sites-enabled/mastodon.conf
変更を有効にするには、Nginxを再起動します:
sudo systemctl restart nginx
次に、certbotを使用して、Let’sEncryptを使用して無料のSSL証明書を取得します。
sudo certbot --nginx -d your-domain.com
料金は無料のLet'sEncryptSSL証明書を取得し、Nginx構成を再構成します。
ステップ9:systemdサービスの設定
マストドンディレクトリからsystemdユニットファイルをコピーします:
sudo cp /opt/mastodon/live/dist/mastodon-*.service /etc/systemd/system/
次のコマンドを実行して、Mastodonインストールディレクトリのパスを変更します。
sudo sed -i 's/home/opt/g' /etc/systemd/system/mastodon-*.service
最後に、新しいsystemdサービスを開始して有効にします。
for i in mastodon-web mastodon-sidekiq mastodon-streaming; do sudo systemctl start $i sudo systemctl enable $i done
この時点で、ブラウザでドメインを開き、Mastodonのインストールを完了することができます。
それでおしまい。これで、Debian9VPSにMastodonが正常にインストールされました。 Mastodonのインストールを管理する方法の詳細については、Mastodonの公式ドキュメントを参照してください。
もちろん、Linux VPSホスティングサービスのいずれかを使用している場合は、これを行う必要はありません。その場合は、専門のLinux管理者にセットアップを依頼するだけです。 24時間年中無休でご利用いただけます。リクエストはすぐに処理されます。
PS 。この投稿が気に入った場合は、以下の共有ショートカットを使用してソーシャルネットワークで友達と共有するか、コメントセクションにコメントを残してください。ありがとう。