0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

🚀 MastodonでElasticsearchとコンソールからアカウントを作成する際のエラーとその解消

Posted at

🗂️ 概要

Mastodonを構築した際、Elasticsearchが正しく動作していなかったり、Web UIからアカウント作成ができないケースがあります。本記事では、以下の手順を解説します。

  1. Elasticsearchのインストールと設定
  2. Mastodonのコンソールを使用したユーザー作成方法
  3. 発生するエラーとその解決方法

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   # 利用規約への同意
)

これで正常にユーザーが作成されます。

0
0
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
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?