【Mastodon】さくらVPSやConohaばっかりなのでEX-CLOUDでMastodonしてみた
さくらのVPSやConohaでばっかりやられているので、Ex-CLOUD のVPSプランでMastodonを構築してみた。OSはCentOS7。
前提
以下、ドメインをmastodon.ex-cloud.bizで説明する。
Rootに昇格
1 |
sudo -s |
mastodonユーザーを作成
1 |
useradd mastodon |
EPEL追加して必要なパッケージをインストール
1 2 |
rpm -ivh https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm yum install ImageMagick libxml2 libxslt1 git curl ruby openssl-devel readline-devel zlib-devel pidentd gcc-c++ make protobuf-lite-devel |
ffmpegをインストール
1 2 3 |
rpm --import http://li.nux.ro/download/nux/RPM-GPG-KEY-nux.ro rpm -Uvh http://li.nux.ro/download/nux/dextop/el7/x86_64/nux-dextop-release-0-1.el7.nux.noarch.rpm yum -y install ffmpeg ffmpeg-devel |
Node.jsをインストール
1 2 3 |
curl --silent --location https://rpm.nodesource.com/setup_6.x | bash - yum install nodejs --disablerepo=epel npm install -g yarn |
Redisをインストール
1 2 3 |
yum install redis systemctl start redis systemctl enable redis |
PostgreSQLをインストール・設定
1 2 3 4 5 6 7 8 9 10 |
yum install postgresql-server postgresql postgresql-contrib postgresql-devel -y su - postgres initdb exit systemctl start postgresql su - postgres psql CREATE USER mastodon CREATEDB; \q exit |
以下からしばらくmastodonユーザーでの作業
rbenv をインストール
1 2 3 4 5 6 7 |
sudo su - mastodon git clone https://github.com/sstephenson/rbenv.git ~/.rbenv echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bashrc echo 'eval "$(rbenv init -)"' >> ~/.bashrc source ~/.bashrc git clone https://github.com/sstephenson/ruby-build.git ~/.rbenv/plugins/ruby-build cd ~/.rbenv/plugins/ruby-build |
Ruby をインストール
1 2 3 |
rbenv install 2.4.1 rbenv rehash rbenv global 2.4.1 |
Mastodon をインストール・設定
1 2 3 4 5 6 7 8 9 10 11 12 13 |
cd git clone https://github.com/tootsuite/mastodon.git live cd live gem install bundler bundle install --deployment --without development test yarn install cp .env.production.sample .env.production RAILS_ENV=production rake secret abcdefg・・・・・・・・・・・・・・・・xyz # ↑を控えておく vi .env.production |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
# Service dependencies REDIS_HOST=localhost REDIS_PORT=6379 # REDIS_DB=0 DB_HOST=localhost DB_USER=mastodon DB_NAME=mastodon DB_PASS= DB_PORT=5432 # Federation LOCAL_DOMAIN=mastodon.ex-cloud.biz LOCAL_HTTPS=true # Use this only if you need to run mastodon on a different domain than the one used for federation. # Do not use this unless you know exactly what you are doing. # WEB_DOMAIN=mastodon.example.com # Application secrets # Generate each with the `rake secret` task (`docker-compose run --rm web rake secret` if you use docker compose) PAPERCLIP_SECRET= SECRET_KEY_BASE="abcdefg・・・・・・・・・・・・・・・・xyz" #上で控えたキーを""で挟んで貼り付ける |
1 2 3 |
RAILS_ENV=production bundle exec rails db:setup RAILS_ENV=production bundle exec rails assets:precompile exit |
Mastodonの起動ファイルを作成・起動
以下からrootでの作業。
1 |
vi /etc/systemd/system/mastodon-web.service |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
[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 TimeoutSec=15 Restart=always [Install] WantedBy=multi-user.target |
1 |
vi /etc/systemd/system/mastodon-sidekiq.service |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
[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 mailers -q pull -q push TimeoutSec=15 Restart=always [Install] WantedBy=multi-user.target |
1 |
vi /etc/systemd/system/mastodon-streaming.service |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
[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 |
起動。
1 |
systemctl enable /etc/systemd/system/mastodon-*.service |
Nginxをインストール、設定
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
systemctl stop httpd systemctl disable httpd iptables -A INPUT -p tcp -m state --state NEW -m tcp --dport 80 -j ACCEPT iptables -A INPUT -p tcp -m state --state NEW -m tcp --dport 443 -j ACCEPT iptables-save systemctl restart iptables systemctl enable nginx cd git clone https://github.com/certbot/certbot cd certbot/ ./certbot-auto certonly --standalone -d mastodon.ex-cloud.biz #メールアドレス入力したりなんだり sudo vi /etc/nginx/conf.d/mastodon.conf |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
server{ server_name mastodon.ex-cloud.biz; listen 443 ssl; ssl on; ssl_certificate /etc/letsencrypt/live/mastodon.ex-cloud.biz/fullchain.pem; ssl_certificate_key /etc/letsencrypt/live/mastodon.ex-cloud.biz/privkey.pem; location / { 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:3000; } } |
1 |
sudo systemctl start nginx |
ブラウザで Mastodon
https://mastodon.ex-cloud.biz にアクセスできれば成功。