LoginSignup
16
18

More than 5 years have passed since last update.

CentOS 7 で ぱおーん

Last updated at Posted at 2017-04-14

CentOS 7 に Docker を使わずに mastodon をインストール

というか、ページタイトルがよくなかったですね。今更変えないんですけどね。

はじめに

この記事では CentOS7 に Docker を使わずに mastodon をインストールします。
Docker を使った手順は別途まとまった記事がありますのでそちらを参照してください。
また、このまま記事の手順のままでインターネットに公開するのは全くお勧めできません。
mastodon を理解するためにローカルで試したいのよ~って方向けと思ってください。

大筋は ubuntu 向けの手順である、以下を参照してます。
https://github.com/tootsuite/documentation/blob/master/Running-Mastodon/Production-guide.md
CentOS 7 自体のインストールは省きますよー。


mastodonユーザーの作成

# useradd mastodon

uid/gid だのパスワードだのは任意で。

epelリポジトリー有効化&必要なパッケージインストール

# 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

curlとかは入ってるかもしれないですけど念のため。

ffmpeg 追加

# 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

nodejs 4.x インストール

# curl --silent --location https://rpm.nodesource.com/setup_4.x | bash -
# yum install nodejs --disablerepo=epel
# npm install -g yarn

Production-guide に倣って 4.x いれますよ~

redis インストール

# yum install redis

別のインスタンスにインストールでもいいですが、ここでは同じインスタンスにインストール。

redis サービス開始&サービス有効化

# systemctl start redis
# systemctl enable redis

PostgreSQL関連 インストール

# yum install  postgresql-server postgresql postgresql-contrib postgresql-devel -y

DBはPostgreSQLらしいです。
こちらも別のインスタンスにインストールでもいいですが、ここでは同じインスタンスにインストール。

PostgreSQL initdb 実行

# su - postgres
$ initdb
$ exit

Production-guide に倣って initdb です。

PostgreSQL サービス開始&サービス有効化

# systemctl start postgresql
# systemctl enable postgresql
PostgreSQL mastodon ユーザ 作成
# su - postgres
$ psql
# CREATE USER mastodon CREATEDB;
# ¥q
$ exit

ここではpg_hba.conf でアクセス制限とか、すっとばしてるので注意。
特に別のインスタンスにインストールした場合は要注意。
pg_hba.confを いじった場合は PostgreSQL サービス再起動

# systemctl restart postgresql

rbenv インストール

# git clone https://github.com/sstephenson/rbenv.git ~/.rbenv
# echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bash_profile
# echo 'eval "$(rbenv init -)"' >> ~/.bash_profile
# source ~/.bash_profile
# git clone https://github.com/sstephenson/ruby-build.git ~/.rbenv/plugins/ruby-build
# cd ~/.rbenv/plugins/ruby-build
# ./install.sh
# rbenv -v

次でruby 2.4.1 インストールしたいので rbenv をインストールです。
ここまでが準備でした。お疲れさまでした。

mastodon インストール

ここからがやっと本題!
mastodon インストールですよ。

mastodon ユーザにチェンジ

# su - mastodon

ruby 2.4.1 インストール

$ rbenv install 2.4.1
$ rbenv rehash
$ rbenv global 2.4.1
$ rbenv global

github から clone して mastodon インストール

$ 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
$ vi .env.production

以下、設定箇所サンプル。ここは設定をあまり詰められていないので、要注意です。

# Service dependencies
REDIS_HOST=localhost #←REDISサーバが同じホスト上なら localhost
REDIS_PORT=6379
DB_HOST=localhost    #←PostgreSQL のDBサーバが同じホスト上なら localhost
DB_USER=mastodon     #←PostgreSQL のDBユーザはここまでの流れ通りなら mastodon
DB_NAME=mastodon     #←PostgreSQL のDB名はここまでの流れ通りなら mastodon
DB_PASS=             #←ここは空っぽでOK!
DB_PORT=5432

# Federation
LOCAL_DOMAIN=mstdn.local  #← ここは自分が使うマストドンサーバ用のドメイン名に変更 ローカルでテストしたのでこんなの入れてました。
LOCAL_HTTPS=false         #← ローカルでテストしたいだけなのでfalseにしてるけどほんとはtrueのままで。nginx 側でSSLの処理やってもいい気がしてきた。

PAPERCLIP_SECRET=               #←KEYを入れるべきだけど、無くても怒られない。ローカルでテストなら別になくてもよい?
SECRET_KEY_BASE='*************' #←何もいれずに実行したら怒られるぞ。ちゃんとしたKEYを入力だ。
OTP_SECRET=                     #←KEYを入れるべきだけど、無くても怒られない。ローカルでテストなら別になくてもよい?



KEYは以下で生成。事前にやっとくとよいです。

$ rake secret

セットアップ

$ RAILS_ENV=production bundle exec rails db:setup
$ RAILS_ENV=production bundle exec rails assets:precompile

ずらずらと実行結果出るはずです。
db:setup 失敗したときは psql で

psql# drop database mastodon;

とかやってやり直してた気がする。

ということで、セットアップ完了のはず。

systemd でのサービスの起動とサービスの有効化

まぁ Production-guide そのままです。
内容がわかる方、ここまでの手順を変更した方は色々いじるとよいです。

/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
TimeoutSec=15
Restart=always

[Install]
WantedBy=multi-user.target

/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 mailers -q pull -q push
TimeoutSec=15
Restart=always

[Install]
WantedBy=multi-user.target

/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

サービス有効化

# systemctl enable /etc/systemd/system/mastodon-*.service 

サービス起動

# systemctl start mastodon-web.service mastodon-sidekiq.service mastodon-streaming.service

お疲れさまでした。
これで、 http://[ipアドレス]:3000 でアクセスできます。
最初にも書きましたが、このままでインターネットに公開するのはお勧めできません。
最低でも nginx などでリバースプロキシ立てるといいんじゃないですかね。
あとは firewalled でアクセス絞るだのとかAWS 上ならsecuritygroupでアクセス絞るだのあると思います。
自分の場合、ssh portforward つかって動作確認してます。
このあたりは別の記事を探していただけるとよいかと思います。
(mastodon タグでもいっぱい投稿されてますね。)

追記


自分のやりたかったこと以上のことが以下のページで綺麗にまとまってます。
Mastodon を CentOS にインストールする (Docker未使用)

16
18
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
16
18