🗂️ 概要
Mastodonを構築した際、Elasticsearchが正しく動作していなかったり、Web UIからアカウント作成ができないケースがあります。本記事では、以下の手順を解説します。
- Elasticsearchのインストールと設定
- Mastodonのコンソールを使用したユーザー作成方法
- 発生するエラーとその解決方法
✅ 1️⃣ Elasticsearchのインストール
1. Elasticsearchのインストール確認
which elasticsearch
何も表示されない場合は未インストールです。以下の手順でインストールします。
2. 依存パッケージのインストール
sudo apt-get update
sudo apt-get install -y openjdk-11-jdk
3. Elasticsearchの公式リポジトリ追加
wget -qO - https://artifacts.elastic.co/GPG-KEY-elasticsearch | sudo apt-key add -
sudo sh -c 'echo "deb https://artifacts.elastic.co/packages/7.x/apt stable main" > /etc/apt/sources.list.d/elastic-7.x.list'
4. Elasticsearchのインストール
sudo apt-get update
sudo apt-get install -y elasticsearch
5. Elasticsearchの起動と有効化
sudo systemctl start elasticsearch
sudo systemctl enable elasticsearch
6. 起動確認
curl http://localhost:9200
正常に起動していれば、バージョン情報が表示されます。
🚀 2️⃣ Mastodonコンソールからのユーザー作成
1. コンソールの起動
RAILS_ENV=development rails c
2. アカウントの作成
account = Account.create!(
username: 'newuser',
domain: nil, # ローカルユーザーなら nil
display_name: 'New User',
note: 'This is a new account'
)
3. ユーザーの作成
user = User.create!(
email: 'newuser@example.com',
password: 'password123',
confirmed_at: Time.now, # メール確認をスキップ
account_id: account.id
)
⚠️ 3️⃣ 発生したエラーと解決方法
❌ エラー: Service agreement must be accepted
Validation failed: Service agreement must be accepted (ActiveRecord::RecordInvalid)
✅ 解決方法
ユーザー作成時に利用規約への同意が必要です。以下のように agreement
を追加します。
user = User.create!(
email: 'newuser@example.com',
password: 'password123',
confirmed_at: Time.now,
account_id: account.id,
agreement: true # 利用規約への同意
)
これで正常にユーザーが作成されます。