翻訳機能

 MisskeyではDeepL、MastodonやkmyblueではDeepLに加えてLibreTranslateと連携することで、翻訳機能を導入することができます。

 DeepL( https://www.deepl.com/ )については、APIページで登録すると、APIキーを発行できます。

Mastodon、kmyblueでの設定方法

 .env.productionに以下の環境変数を設定します。

DeepLなら


DEEPL_API_KEY

DEEPL_PLAN

LibreTranslateなら


LIBRE_TRANSLATE_ENDPOINT

LIBRE_TRANSLATE_API_KEY

 DeepLの場合、API_KEYは”DeepL-Auth-Key “の後ろの文字列(ハッシュから :fx まで)、PLANには”free”なら”free”と入力することが必要です。ここが”free”でなければ有償版のエンドポイントが使われます。

Misskeyでの設定方法

 コントロールパネルからAPIキーを登録できます。

検索機能

 Mastodon、kmyblueは全文検索を行うためにElasticSearchサーバーが必要です。また、もしkmyblueで日本語での検索をカバーするならば、kmyblueのwikiに従ってSudachiプラグインを追加する必要もあります。

 ElasticSearchにはかなりのリソースが使われるようで、本家MastodonでElasticSearchを使いたい場合はHostdonでオプションとして申し込むのが最も安上がりという説を見たことがあります。また、ハッシュタグの検索、加えてkmyblueの場合はアンテナにもElasticSearchが必要ないことから、それらを上手く活用する方法を考えた方が安定かもしれません。

 ElasticSearchの導入方法はMastodonの公式ドキュメントに掲載されています。特にSudachiプラグインなども導入する場合は手順がやや煩雑です。

ElasticSearchサーバーに必要なスペック

 どうやら、MastodonでのElasticsearchは1GBで止まることあり、2GBあれば普通に動くけれど4GBが安定?という話があるようです。のちに、Fedibird(Mastodonのフォークでかなりの大手鯖)の管理者のえるさんから、FedibirdのElasticsearchはRAM 4GBのVPSを3台使っているとの情報を得られました。

 筆者の場合、取り敢えずkmyblue自鯖(RAM 4GB)のメモリ使用量が半分くらいなのを確認の上で、メモリ1GBを割り当てることにしましたが、おひとりさまであることも相まって、止まったことはありません。

実際の設置手順

1.Elasticsearchをインストールします。

 基本的にkmyblue公式wiki、MastodonのドキュメントサイトやElasticsearchのドキュメントを見ながら進めていく感じです。

https://github.com/kmycode/mastodon/wiki/ElasticSearch設定方法

https://docs.joinmastodon.org/admin/elasticsearch/

https://www.elastic.co/guide/en/elasticsearch/reference/7.17/install-elasticsearch.html

 2024年5月作業時、Mastodonはバージョン7のElasticsearchを使用すること前提でしたので、バージョン7.17のElasticsearchを入れました。

 非DockerのUbuntuの場合、以下のような感じです。


sudo apt install openjdk-17-jre-headless

  

wget -qO - https://artifacts.elastic.co/GPG-KEY-elasticsearch | sudo apt-key add -

  

sudo apt install apt-transport-https

  

echo "deb https://artifacts.elastic.co/packages/7.x/apt stable main" | sudo tee -a /etc/apt/sources.list.d/elastic-7.x.list

  

sudo apt update

  

sudo apt install elasticsearch

  

systemctl daemon-reload

  

systemctl enable --now elasticsearch

  

sudo apt-mark hold elasticsearch

 最後の行はSudachiプラグインを使用する際に必要です。

 というのも、Sudachiプラグインは厳密にElasticsearchのバージョンに依存するので、勝手にアプデされると使えなくなってしまうからです。

 なお、 /etc/elasticsearch/jvm.options を編集することで、割り当てるメモリを定義することができるようです。

 詳細な設定方法は https://github.com/felx/mastodon-documentation/blob/master/Running-Mastodon/Elasticsearch-guide.md (2018年の英語記事)の中ほどにありますが、今回は1GBだけ割り振りたかったので、以下を設定しました。


-Xms256m

-Xmx256m

 なお、設定後はElasticsearchの再起動が必要です。


sudo systemctl restart elasticsearch

2.Mastodonの設定ファイルを書き換えます。

 これに関してはMastodonのドキュメントサイトの通りですね。

 .env.production に最低限これだけでも書き足します。


ES_ENABLED=true

ES_HOST=localhost

ES_PORT=9200

 なお、まだMastodonの再起動は行いません。

3.Sudachiプラグインを導入します。

 https://github.com/WorksApplications/elasticsearch-sudachi/releases (実際に使用中のElasticsearchに対応したSudachiプラグインを探す先・英語)から、Elasticsearch 7.17.何かしらの数字に対応した最新版のSudachiプラグインのアドレスを取ってきて、 /etc/elasticsearch/ に導入します。以下のコマンドの数値などは適宜、最新版の数値や自分の環境に合わせて変更してください。


wget https://github.com/WorksApplications/elasticsearch-sudachi/releases/download/Sudachiのバージョンの数値/analysis-sudachi-elasticsearch7.何かしらの数字-次のバージョンの数値.zip←バージョンにより数字は変わります

  

sudo /usr/share/elasticsearch/bin/elasticsearch-plugin install file:///home/(自分の作業ユーザー名)/analysis-sudachi-elasticsearch7.何かしらの数字-次のバージョンの数値.zip←同上

 無事にインストールできたかの確認は、以下のコマンドで可能です。


sudo /usr/share/elasticsearch/bin/elasticsearch-plugin list

4.Sudachiプラグイン用の辞書ファイルをダウンロード・展開します。

  https://github.com/WorksApplications/SudachiDict (Sudachiプラグイン用の辞書ファイル・英語)からリンクを辿って最新版の辞書を取ってきます。


wget http://sudachi.s3-website-ap-northeast-1.amazonaws.com/sudachidict/sudachi-dictionary-latest-core.zip

  

sudo apt install unzip

  

unzip sudachi-dictionary-latest-core.zip

  

mkdir /etc/elasticsearch/sudachi/

  

cp sudachi-dictionary-latest-core/system_core.dic /etc/elasticsearch/sudachi/system_core.dic

 辞書までインストールできたら、追加で /etc/elasticsearch/sudachi/config.json に下記を記述して保存します。


{

  "systemDict": "system_core.dic"

}

 念のためにElasticsearchを再起動しました。


sudo systemctl restart elasticsearch

5.Mastodon,kmyblueの再起動と設定を行います。

 Mastodon,kmyblueを再起動し、検索を行うためのコマンドを打ちます。


sudo systemctl restart mastodon-*

  

sudo su - mastodon

  

cd live

 kmyblueの場合は、ここでこの手順を挟んでください。また、筆者は念の為にもう一度kmyblueを再起動しました。


ln -s config/elasticsearch.default-ja-sudachi.yml .elasticsearch.yml

 この後、いよいよ満を持して


RAILS_ENV=production bin/tootctl search deploy

04-01・バックアップの方法

03-05-02・SMTPサーバーについて