お知らせ

現在サイトのリニューアル作業中のため、全体的にページの表示が乱れています。

公式のドキュメントには書かれていない気がするがDockerだけあればセットアップ可能。WSL2でのセットアップが面倒なVargantは不要

本記事ではWSL2内のUbuntuの中でDockerとDocker Composeを使った構築法について記述する。Windows向けのDocker Desktopは使用しない

前提

  • WSL2のUbuntuにVSCodeで接続して作業
  • 起動してログイン、トゥート、設定と言った最低限の画面操作が可能な程度まで

確認環境

Env ver
Mastodon v3.5.3
Docker 20.10.21, build baeda1f
Docker Compose v2.12.2
Ubuntu 20.04.5 LTS
WSL2 1.0.3.0
DevContainer v0.266.1
VSCode 1.73.0

手順

  1. git clone https://github.com/mastodon/mastodon.git
    1. 最新版などバージョン指定が必要な場合は追加でtagをチェックアウトする
  2. VSCodeでClone先を開く
  3. Reopen Containerする
  4. セットアップが走るので暫く待つ
  5. foreman startを流す
  6. http://localhost:3000/ へアクセス

操作方法

ユーザーを作ったりしたい場合、Using the admin CLIが参考になる

一例としてユーザー作成は次の書式で行ける

./bin/tootctl accounts create foo --emaill foo@example.com --confirmed

トラブルシュート

DB接続エラーが出る

ActiveRecord::ConnectionNotEstablished at /
could not connect to server: No such file or directory
Is the server running locally and accepting
connections on Unix domain socket "/var/run/postgresql//.s.PGSQL.5432"?

上記のエラーが出る場合、ビルドしたDockerイメージが壊れてるので以下のコマンドで全て消して作り直すとうまく行く

docker rm -f `docker ps -a -q`
docker rmi `docker images -q`
docker system prune

他のMastodonインスタンスが動かない

複数のMastodonインスタンスのDocker環境を同居させると多分コンフリクトする

フルスクラッチで組むやつ

確認環境

Env Ver
Ubuntu 20.04.4 LTS
nginx 1.18.0 (Ubuntu)
MariaDB 15.1 Distrib 10.3.34-MariaDB
grafana-server Version 9.2.5 (commit: 042e4d216b, branch: HEAD)

前提

  • Windows側からhttp://grafana.test/としてアクセスする
  • DBにはMariaDBを使用

hostsの編集

Windows側のhostsに以下を追記

127.0.0.1 grafana.test

各種環境のインストール

sudo apt update
sudo apt install -y nginx mariadb-server

sudo apt-get install -y apt-transport-https software-properties-common wget
sudo wget -q -O /usr/share/keyrings/grafana.key https://apt.grafana.com/gpg.key
echo "deb [signed-by=/usr/share/keyrings/grafana.key] https://apt.grafana.com stable main" | sudo tee -a /etc/apt/sources.list.d/grafana.list
sudo apt-get update
sudo apt-get install grafana

nginxの設定

cat <<'EOF' | sudo tee /etc/nginx/conf.d/granafa.conf
map $http_upgrade $connection_upgrade {
  default upgrade;
  '' close;
}

upstream grafana {
  server localhost:4000;
}

server {
  listen       80;
  server_name  grafana.test;
  access_log   /var/log/nginx/grafana.access.log;
  error_log    /var/log/nginx/grafana.error.log;


  location / {
    proxy_set_header Host $http_host;
    proxy_pass  http://grafana;
  }

  location /api/live/ {
    proxy_http_version 1.1;
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection $connection_upgrade;
    proxy_set_header Host $http_host;
    proxy_pass http://grafana;
  }
}
EOF

sudo service nginx start

MariaDBの設定

ユーザー作成

idpwの部分は適当に変える

sudo service mysql start
sudo mysql
CREATE USER 'id'@'%' IDENTIFIED BY 'pw';
GRANT ALL PRIVILEGES ON *.* TO 'id'@'%' WITH GRANT OPTION;
quit

外部接続テスト

適当なRDBクライアントから繋げればOK

grafanaの設定

  1. sudo nano /etc/grafana/grafana.iniで適当にいじる
# The http port  to use
http_port = 4000

# The public facing domain name used to access grafana from a browser
domain = grafana.test
  1. sudo service grafana-server start
  2. http://grafana.test/ へアクセス
    1. IDPW共にadminが初期

DBの読み込み

  1. MariaDBに適当なDBとテーブルを作る
  2. Grafanaにログインする
  3. サイドバーからConfiguration -> Data sources
  4. DBの情報を入れて接続
  5. 後はよしなにやる