LoginSignup
1
1

More than 1 year has passed since last update.

【すごく簡単】FreeBSDにmastodonをインストールする方法

Last updated at Posted at 2023-02-18

マストドンのインストール、難しくて困ったことはありますか?

特に依存関係とかになると大変。

仮想マシンイメージもあるようですが、今後アップデートするのも大変

そこで、FreeBSDのパッケージを利用してインストールします。

パッケージですので、安心してアップデートも可能です

https://wiki.freebsd.org/Ports/net-im/mastodon
こちらを参考にして、一部方法が違う方法を利用しています

この説明によるインストールの前提

  • Apache が入っていないこと
  • 可能な限りFreeBSDが初期状態であること
  • wikiでは acme.sh + zerossl を使用しているが、certbot + Let's encrypt を使用
  • 最新版は入らず、若干古い安定版がインストールされます
  • 2023/2/19現時点でのインストール方法で、将来変わるかもしれません

pkgそのものをインストールする

pkg

一度でもpkgを使用していれば不要です

念のため

pkg update
pkg upgrade

pkg でまずインストールする

pkg install -y nginx py39-certbot-nginx postgresql13-server mastodon

これだけで全部必要なものがインストールされます
依存の関係で若干余計なものが入りますが気にしません。

nginx.confの修正

ee /usr/local/etc/nginx/nginx.conf

http のブロックに下記を追加

include /usr/local/www/mastodon/dist/nginx.conf;

ドメインに合わせて書き換えます

sed -i '' -e 's/example.com/<YOUR DESIRED DOMAIN>/g' /usr/local/www/mastodon/dist/nginx.conf

SSL証明書を取得する

nginxをまだ立ち上げずに証明書を取得します。

certbot certonly

2番のスタンドアロンサーバーを起動する

2: Spin up a temporary webserver (standalone)

この後、メールアドレスの登録や、同意、ドメインの入力をして下さい

nginx.confを書き換える

sed -i '' -e  sed -i '' -e 's/\/usr\/local\/etc\/ssl\//\/usr\/local\/etc\/letsencrypt\/live\//g' /usr/local/www/mastodon/dist/nginx.conf/usr/local/www/mastodon/dist/nginx.conf
sed -i '' -e 's/key.pem;/privkey.pem;/g' /usr/local/www/mastodon/dist/nginx.conf
sed -i '' -e 's/\# listen/listen/g' /usr/local/www/mastodon/dist/nginx.conf
sed -i '' -e 's/\# ssl_certificate/ssl_certificate/g' /usr/local/www/mastodon/dist/nginx.conf

説明

  • acme.shで生成されるzerosslのパスをLet's encryptのパスに変更
  • プライベートキーのファイル名変更
  • コメントアウトすべき listen 2行をコメントアウト
  • コメントアウトすべき ssl_certificate* 2行をコメントアウト

nginxをスタートする

sysrc nginx_enable="YES"
service nginx start

postgresqlの設定

以下のようにして起動します

sysrc postgresql_enable="YES"
service postgresql initdb
service postgresql start

初期DBを設置します

su -l postgres -c 'createuser -d mastodon'

Redisサーバーの設定

sysrc redis_enable="YES"
service redis start

マストドンの設定

su -l mastodon
yarn set version classic
bundle config deployment 'true'
bundle config without 'development test'
bundle install -j$(getconf _NPROCESSORS_ONLN)
yarn install --pure-lockfile

コア数が多くてメモリが少ない場合、下記のように行ってください

su -l mastodon
yarn set version classic
bundle config deployment 'true'
bundle config without 'development test'
bundle install -j1
yarn install --pure-lockfile

初期設定

  • postgresqlのDBサーバーは、127.0.0.1 (localhostよりベター)を指定します
  • Enterだけで入力するとunix socketになりますが、使用できません。
  • Redisサーバーも localhostより127.0.0.1のがベターです
RAILS_ENV=production bundle exec rake mastodon:setup

サンプル入力

Your instance is identified by its domain name. Changing it afterward will break things.
Domain name: あなたのドメイン名

Single user mode disables registrations and redirects the landing page to your public profile.
Do you want to enable single user mode? No (※オレオレマストドンならYes)

Are you using Docker to run Mastodon? no

PostgreSQL host: 127.0.0.1
PostgreSQL port: 5432 (Enterのみ)
Name of PostgreSQL database: mastodon_production (Enterのみ)
Name of PostgreSQL user: mastodon (Enterのみ)
Password of PostgreSQL user: (Enterのみ)
Database configuration works! ?

Redis host: 127.0.0.1
Redis port: 6379 (Enterのみ)
Redis password: (Enterのみ)
Redis configuration works! ?

Do you want to store uploaded files on the cloud? No

Do you want to send e-mails from localhost? No
SMTP server: example.com
SMTP port:  587 (適時修正)
SMTP username: hoge@example.com
SMTP password: password
SMTP authentication: plain (適時選択)
SMTP OpenSSL verify mode: none (適時選択)
Enable STARTTLS: auto (適時選択)
E-mail address to send e-mails "from": (Mastodon <notifications@don.neetcojp.netE-mail address to send e-mails "from": hoge@example.com
Send a test e-mail with this configuration right now? Yes
Send test e-mail to: hoge@example.com

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 (初回のみYes)
Running `RAILS_ENV=production rails db:setup` ...

The final step is compiling CSS/JS assets.
This may take a while and consume a lot of RAM.
Compile the assets now? Yes(再セットアップでなければYes)
Running `RAILS_ENV=production rails assets:precompile` ...

Do you want to create an admin user straight away? Yes (初回のみYes)
Username: あどみんゆーざーの名前を書く
E-mail: hoge@example.com
You can login with the password: ここに初期パスワードが記載される

マストドンのサービスの設定

sysrc mastodon_sidekiq_enable=YES
sysrc mastodon_streaming_enable=YES
sysrc mastodon_web_enable=YES
service mastodon_sidekiq start
service mastodon_streaming start
service mastodon_web start

動作することが確認できたら

この状態で動作しているnginxはHTTP/1.1 です。

ee /usr/local/www/mastodon/dist/nginx.conf

で、SSL関係のコメントをすべてコメントアウトすれば、HTTP/2.0で動作します。

ご注意

全文検索サービス ElasticSearch はうまく動かないようです

運用してみて

pkg もしくは portsにおいて ruby のバージョン不一致の事件が生じました。

その場合、以下のように対処しました

su -l mastodon
mkdir -p /home/mastodon/live
cd /home/mastodon/live
git clone https://github.com/mastodon/mastodon.git
cd mastodon
rm -rf dist
cp -pR * /usr/local/www/mastodon
1
1
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
1
1