No.22, No.21, No.20, No.19, No.18, No.17, No.167件]

Icon of naoki
kmyblueにElasticsearchを導入してみた忘備録

 気が付いたら3時間ほど格闘していたので、今後の為に忘備録を!忘れる前に!!
 それなりに文章が長くなるかもしれないので、畳んでおきます。
#わーさんがやってみた

参考サイト・公式系
https://github.com/kmycode/mastodon/wiki/ElasticSearch%E8%A8%AD%E5%AE%9A%E6%96%B9%E6%B3%95 (kmyblue公式wiki)
https://docs.joinmastodon.org/admin/elasticsearch/ (Mastodonのドキュメントサイト・英語)
https://www.elastic.co/guide/en/elasticsearch/reference/7.17/install-elasticsearch.html (Elasticsearchのドキュメントサイト・英語)
https://github.com/WorksApplications/elasticsearch-sudachi (Sudachiプラグインを置いてある場所・英語)
https://github.com/WorksApplications/elasticsearch-sudachi/releases (実際に使用中のElasticsearchに対応したSudachiプラグインを探す先・英語)
https://github.com/WorksApplications/SudachiDict (Sudachiプラグイン用の辞書ファイル・英語)

参考サイト・忘備録系
https://blog.noellabo.jp/entry/2019/04/19/YNUL9UsohRgNKSya (『ElasticsearchをMastodonとは別のサーバに設置する』Fedibird管理人のえるさんによる2019年の忘備録)
https://github.com/felx/mastodon-documentation/blob/master/Running-Mastodon/Elasticsearch-guide.md (2018年の英語記事)
https://www.geekfeed.co.jp/amazonlinux2-elasticsearch7-sudachi#elasticsearch-sudachi (『AmazonLinux2にelasticsearch7と日本語の形態素解析器「Sudachi」プラグインをインストール』2020年の記事)

実際に行った作業手順
0.下調べした結果、別サーバーへの設置を諦める
 主にVPS同士の通信面への知識不足と、VPSの必要スペックがよく分からなかったことなどから、断念。

1.Elasticsearchの推奨スペックを求めて唸る
 普通に検索すると、64GBの物理メモリを準備して半分を割り当て云々……みたいなのが引っかかってきたり、ストレージの必要量もよく分からなかったりしたので、取り敢えず自鯖(RAM 4GB)のメモリ使用量が半分くらいなのを確認の上で、メモリ1GBを割り当てることにしました。
 どうやら、MastodonでのElasticsearchは1GBで止まることあり、2GBあれば普通に動くけれど4GBが安定?という話があるようです(風の噂)
 のちに、のえるさんから、FedibirdのElasticsearchはRAM 4GBのVPSを3台使っているとの情報を得られました。

2.Elasticsearchをインストールする
 基本的にkmyblue公式wikiとMastodonやElasticsearchのドキュメントを見ながら進めていく感じです。
 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の再起動が必要です。

3.Mastodonの設定ファイルを書き換える
 これに関してはMastodonのドキュメントサイト・英語の通りですね。
 .env.productionに最低限これだけでも書き足します。

ES_ENABLED=true
ES_HOST=localhost
ES_PORT=9200

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

4.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/v3.1.1/elasticsearch-7....
sudo /usr/share/elasticsearch/bin/elasticsearch-plugin install file:///home/(ユーザー名)/elasticsearch-7.17.21-analysis-sudachi-3.1.1.zip

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

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

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

wget http://sudachi.s3-website-ap-northeast-1.amazonaws.com/sudachidict/sudachi-dictionary-latest-core.zi...
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

6.kmyblueの再起動と設定
 この辺りはkmyblue公式wikiの手順通りです。

sudo systemctl restart mastodon-*

sudo su - mastodon
cd live
ln -s config/elasticsearch.default-ja-sudachi.yml .elasticsearch.yml

 念のためにもう一度Mastodonの再起動後、いよいよ満を持して

RAILS_ENV=production bin/tootctl search deploy


7.未知の領域・Elasticsearchをアプデするときは
 取り敢えず https://blog.noellabo.jp/entry/2019/04/19/YNUL9UsohRgNKSya (『ElasticsearchをMastodonとは別のサーバに設置する』Fedibird管理人のえるさんによる2019年の忘備録)を読むのが安定でしょう。
  • elasticsearchのプラグインはバージョンチェックが厳密で、本体のバージョンと完全一致したものを使う必要があり、毎回削除して入れ直しが必要
  • なので、本体だけうっかりアップデートすると死ぬので、普段はapt-markでholdしておくこと
  • https://github.com/WorksApplications/elasticsearch-sudachi/releases からanalysis-sudachiの最新リリースをチェックし、対応版がでてから切り替えるのが吉


sudo /usr/share/elasticsearch/bin/elasticsearch-plugin remove analysis-sudachi
sudo apt-mark unhold elasticsearch
sudo apt install elasticsearch
sudo apt-mark hold elasticsearch
wget https://github.com/WorksApplications/elasticsearch-sudachi/releases/download/次のバージョンの数値/analysis-sudachi-elasticsearch7.何かしらの数字-次のバージョンの数値.zip←バージョンにより数字は変わります
sudo /usr/share/elasticsearch/bin/elasticsearch-plugin install file:///home/(ユーザー名)/analysis-sudachi-elasticsearch7.何かしらの数字-次のバージョンの数値.zip←同上
sudo systemctl restart elasticsearch
畳む
Icon of naoki
取り敢えず、参考サイトだけ貼り付けまくっておくか……(次のnote記事の下準備) #セキュリティ忘備録

https://note.com/lovely_daphne590/n/nfe6be1e5b79f
https://note.com/lovely_daphne590/n/n26c915c04856
↑ユーザ作成からのルート封じからのポート制限まで

https://zenn.dev/xurenjun/articles/a4a744c55a7085
↑モズさん情報(ConoHaでの設定方法、上記に加え、Fail2banまで)

https://manual.sakura.ad.jp/vps/support/security/firstsecurity.html
↑モズさん情報その2(サクラさんのマニュアル)

https://blog.naskya.net/post/6kic0tebueju/
↑なすきゃさんによるFirefishの建て方、ただしArch Linux
Icon of naoki
 自鯖系記事をnoteにアップしてて、ふと振り返ると記事数の多さにちょっと眩暈(めまい)がするよね。
 noteと自サイトだと、まあnoteの方が記事への流入は多そうだし末長く記事が残ってそうだとは思うけれど、noteは色んな方の記事がありすぎて、いざという時に過去に読んだ記事を探すのちょっと手間取る時があるような気がして、実際に流入があるかはさておき、自サイトの整備もやった方が良いのだろうなって思ってしまう。
 とは言いつつ、ヘルプ記事候補ってやっぱりアレか。
  • ハウツー自鯖
  • FediverseのSNS系プラットフォーム紹介(鯖缶目線はどうせ自鯖系で書くだろうから、一般目線とか前提知識とか)
  • Mastodonの初心者向け解説

 どの項目を見ても、それなり以上の分量が約束されているので、気長な作業だろうなと思うやつー。
Icon of naoki
 Mastodon系ですら、のえるさんが「生きている」初心者向け記事を探すくらいに初心者向け記事が枯渇しているんだなと思うと、ひょわーって思う。
 まぁ、Misskey系はもしかしたらあるのかもしれないけれど。Sharkeyのは、わーさん途中までやりかけて頓挫してるけど。

 自鯖系記事も続き書かなきゃって思うけれど、初心者向け記事も書いた方がFediverseの輪は広がるのだろうなと、いやしかし記事メンテの労力……(悩
Icon of naoki
Let's EncryptとCloudflare関連(大雑把)
 どうやらLet's Encryptが2024年9月30日までに証明書の発行方法的なのを変更する?らしく、Cloudflareも対応して5月15日から、旧方式での証明書への対応を取りやめるそうな。
 この旧方式での証明書でないとサイトを閲覧できない端末は一部(具体的にはAndroid7.0以前のAndroid端末)に限られるらしく、Android端末の93.9%は新方式での証明書にも対応しているそう。旧端末に配慮するならば証明書の発行場所(?)を変えるように、Cloudflareからメールが届いているよ。

 なお、Let's Encryptのサイト内情報では、こんな感じのスケジュールの模様。
  • 2024年2月8日:新規発行についてのデフォルトを新方式に移行
  • 2024年6月6日:旧方式での証明書発行を停止
  • 2024年9月30日:旧方式での証明書が全て無効に
Icon of naoki
 いいかげんにWordPress製なのに放置中のHostdon私的まとめを何とかしないとなぁと思って、移転させました。
 そうしたら、まさかのCSS記載あったから、コード部分を表現するCSSも結局考えることになった。

 そんなわけで、もうnote記事とかもその気になったら引っ張って来れそうな気がするようなしないような。
 単純に記事数が多いので、さっくりと持って来られることはないと思うけれど。
Icon of naoki
ヘルプ系記事という項目作成
 当面は過去のヘルプ系記事の再録を中心に、ヘルプ系記事もまとめていくことにしました。取り敢えずは、WordPressを畳みたいHostdon私的まとめから手を着けています。
 最新のヘルプ系記事はnoteを見ていただいた方が早いかと思われます。
#ヘルプ系記事 #Hostdon私的まとめ

■Share

MaMiShare

■旅空ノ夢(Misskey):

編集

■複合検索:

  • 投稿者名:
  • 投稿年月:
  • #タグ:
  • カテゴリ:
  • 出力順序:

■新着画像リスト:

全1個 (総容量 119.9KB)

■日付検索:

■カレンダー:

2024年5月
1234
567891011
12131415161718
19202122232425
262728293031

■カテゴリ:

■最近の投稿:

最終更新日時:
2025年10月12日(日) 06時41分26秒〔103日前〕