マストドンは、オープンWebプロトコルに基づくオープンソースの無料ソーシャルネットワークです。バックエンドにはRubyonRailsを使用し、フロントエンドにはReact.jsとReduxを使用しました。このチュートリアルでは、CentOS7サーバーにMastodonをインストールする方法を説明します。
1。 CentOS 7サーバーを更新し、必要なパッケージをインストールします
sudoユーザーとしてSSH経由でVPSにログインします:
ssh userame@IP_Address
ログインしたら、次のコマンドを発行して、インストールされているすべてのパッケージが最新であることを確認します。
sudo yum update
次に、次のコマンドを使用して、Mastodonのビルドに必要な前提条件のパッケージをインストールします。
sudo yum install curl git gpg gcc git-core zlib zlib-devel gcc-c++ patch readline readline-devel libyaml-devel libffi-devel openssl-devel make autoconf automake libtool bison curl sqlite-devel ImageMagick libxml2-devel libxslt-devel gdbm-devel ncurses-devel glibc-headers glibc-devel libicu-devel libidn-devel protobuf-devel protobuf
2。 Node.jsとYarnをインストールします
有効になっているEPELリポジトリに依存するNodeSourceリポジトリからNode.jsv8LTSをインストールします。
CentOS 7 VPSでEPELリポジトリを有効にするには、次のコマンドを発行します。
sudo yum install epel-release curl
EPELリポジトリを有効にしたら、次のコマンドを実行してNode.jsv8LTSリポジトリを追加します。
curl --silent --location https://rpm.nodesource.com/setup_8.x | sudo bash -
NodeSourceリポジトリが有効になったら、次のコマンドを使用してNode.jsをインストールします。
sudo yum install nodejs
次のコマンドでYarnRPMリポジトリを有効にします:
curl --silent --location https://dl.yarnpkg.com/rpm/yarn.repo | sudo tee /etc/yum.repos.d/yarn.repo
次のコマンドで最新のYarnバージョンをインストールします:
sudo yum install yarn
3。 PostgreSQLをインストールする
PostgreSQLリポジトリを有効にします:
sudo rpm -Uvh https://download.postgresql.org/pub/repos/yum/9.6/redhat/rhel-7-x86_64/pgdg-centos96-9.6-3.noarch.rpm
PostgreSQLサーバーをインストールするには、次のコマンドを実行します。
sudo yum install postgresql96-server postgresql96-contrib postgresql96-devel
インストールが完了したら、次のコマンドを使用して新しいデータベースクラスタを作成します。
sudo /usr/pgsql-9.6/bin/postgresql96-setup initdb
PostgreSQLサービスを開始し、起動時に開始できるようにします:
sudo systemctl enable postgresql-9.6 sudo systemctl start postgresql-9.6
PostgreSQLシェルにログインします:
sudo -u postgres psql
Mastodonインスタンスの新しいユーザーを作成します:
CREATE USER mastodon CREATEDB;
4。 Redisをインストールする
Redisのインストールは非常に簡単です。次のコマンドを実行するだけです:
sudo yum install redis
5。新しいシステムユーザーを作成する
Mastodonの新しいシステムユーザーを作成するには、次のコマンドを実行します。
sudo adduser mastodon
6。 Rubyをインストールする
Rbenvスクリプトを使用してRubyをインストールします。
rbenvリポジトリのクローンを作成する前に、新しいマストドンユーザーに切り替えてください:
sudo su - mastodon
次のコマンドを使用してrbenvとruby-buildを設定します。
cd git clone git://github.com/sstephenson/rbenv.git .rbenv echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bash_profile echo 'eval "$(rbenv init -)"' >> ~/.bash_profile exec $SHELL git clone git://github.com/sstephenson/ruby-build.git ~/.rbenv/plugins/ruby-build echo 'export PATH="$HOME/.rbenv/plugins/ruby-build/bin:$PATH"' >> ~/.bash_profile exec $SHELL
rbenvとruby-buildの両方がセットアップされたら、「
」を使用して最新のRubyバージョンをインストールします。rbenv install 2.5.1 rbenv global 2.5.1
すべてが正しく行われたことを確認するには、コマンドruby --version
を使用します 。
出力は次のようになります。
ruby --version ruby 2.5.1p57 (2018-03-29 revision 63029) [x86_64-linux]
7。 Mastodongitリポジトリのクローンを作成して依存関係をインストールします
次のコマンドもマストドンユーザーとして実行されます。
マストドンの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)
次のコマンドを使用して、bundlerとrubyの依存関係をインストールします。
gem install bundler bundle install -j$(getconf _NPROCESSORS_ONLN) --deployment --without development test
node.jsの依存関係を次のようにインストールします:
yarn install --pure-lockfile
8。マストドンを設定する
次のコマンドはマストドンユーザーとして実行されます。
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 /home/mastodon/live/config/webpacker.yml file for setting up webpack paths Compiling… Compiled all packs in /home/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: 80b4aA233adaeS86d095Scbf79302f81 You can change your password once you login.
9。マストドンsystemdユニットを作成する
次のコマンドは、rootまたはsudoユーザーとして実行されます。
テキストエディタを開き、次のsystemdユニットファイルを作成します。
sudo nano /etc/systemd/system/mastodon-web.service
[Unit] Description=mastodon-web After=network.target [Service] Type=simple User=mastodon WorkingDirectory=/home/mastodon/live Environment="RAILS_ENV=production" Environment="PORT=3000" ExecStart=/home/mastodon/.rbenv/shims/bundle exec puma -C config/puma.rb ExecReload=/bin/kill -SIGUSR1 $MAINPID TimeoutSec=15 Restart=always [Install] WantedBy=multi-user.target
sudo nano /etc/systemd/system/mastodon-sidekiq.service
[Unit] Description=mastodon-sidekiq After=network.target [Service] Type=simple User=mastodon WorkingDirectory=/home/mastodon/live Environment="RAILS_ENV=production" Environment="DB_POOL=5" ExecStart=/home/mastodon/.rbenv/shims/bundle exec sidekiq -c 5 -q default -q push -q mailers -q pull TimeoutSec=15 Restart=always [Install] WantedBy=multi-user.target
sudo nano /etc/systemd/system/mastodon-streaming.service
[Unit] Description=mastodon-streaming After=network.target [Service] Type=simple User=mastodon WorkingDirectory=/home/mastodon/live Environment="NODE_ENV=production" Environment="PORT=4000" ExecStart=/usr/bin/npm run start TimeoutSec=15 Restart=always [Install] WantedBy=multi-user.target
すべてのサービスを有効にして開始します:
sudo systemctl enable mastodon-web.service sudo systemctl enable mastodon-sidekiq.service sudo systemctl enable mastodon-streaming.service sudo systemctl start mastodon-web.service sudo systemctl start mastodon-sidekiq.service sudo systemctl start mastodon-streaming.service
10。 Nginxをインストールして構成する
Nginxをインストールするには、次のコマンドを実行します:
sudo yum install nginx
nginxをインストールしたら、ドメインのサーバーブロックを作成します。 SSL証明書と秘密鍵への正しいパスを設定することを忘れないでください。
sudo nano /etc/nginx/conf.d/your-domain.com.conf
map $http_upgrade $connection_upgrade { default upgrade; '' close; } server { listen 80; listen [::]:80; server_name your-domain.com; root /home/mastodon/live/public; # Useful for Let's Encrypt location /.well-known/acme-challenge/ { allow all; } location / { return 301 https://$host$request_uri; } } server { listen 443 ssl http2; listen [::]:443 ssl http2; server_name your-domain.com; ssl_protocols TLSv1.2; ssl_ciphers HIGH:!MEDIUM:!LOW:!aNULL:!NULL:!SHA; ssl_prefer_server_ciphers on; ssl_session_cache shared:SSL:10m; ssl_certificate /etc/ssl/certs/certificate.crt; ssl_certificate_key /etc/ssl/private/certificate.key; keepalive_timeout 70; sendfile on; client_max_body_size 80m; root /home/mastodon/live/public; gzip on; gzip_disable "msie6"; gzip_vary on; gzip_proxied any; gzip_comp_level 6; gzip_buffers 16 8k; gzip_http_version 1.1; gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript; add_header Strict-Transport-Security "max-age=31536000"; location / { try_files $uri @proxy; } location ~ ^/(emoji|packs|system/accounts/avatars|system/media_attachments/files) { add_header Cache-Control "public, max-age=31536000, immutable"; try_files $uri @proxy; } location /sw.js { add_header Cache-Control "public, max-age=0"; try_files $uri @proxy; } location @proxy { proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Forwarded-Proto https; proxy_set_header Proxy ""; proxy_pass_header Server; proxy_pass http://127.0.0.1:3000; proxy_buffering off; proxy_redirect off; proxy_http_version 1.1; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection $connection_upgrade; tcp_nodelay on; } location /api/v1/streaming { proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Forwarded-Proto https; proxy_set_header Proxy ""; proxy_pass http://127.0.0.1:4000; proxy_buffering off; proxy_redirect off; proxy_http_version 1.1; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection $connection_upgrade; tcp_nodelay on; } error_page 500 501 502 503 504 /500.html; }
ファイルを保存してnginxサービスを再起動します:
sudo systemctl restart nginx
これでブラウザを開いてドメインを入力すると、Mastodonログインフォームが表示されます。
もちろん、当社のマネージドホスティングサービスのいずれかを使用している場合は、CentOS 7にMastodonをインストールする必要はありません。その場合は、専門のLinux管理者にMastodonのインストールを依頼するだけです。 24時間年中無休でご利用いただけます。リクエストはすぐに処理されます。
PS 。この投稿が気に入った場合は、CentOS7にMastodonをインストールする方法をご覧ください。 左側のボタンを使用してソーシャルネットワークで友達と共有するか、下に返信を残してください。ありがとう。