[fs2es-indexer] インデックスを実行する → Spotlight検索ができるようになった?

Spotlight検索の効くSambaの構築をする
https://blog.tndl.net/2021/12/14/1121/spotlight%E6%A4%9C%E7%B4%A2%E3%81%AE%E5%8A%B9%E3%81%8Fsamba%E3%81%AE%E6%A7%8B%E7%AF%89%E3%82%92%E3%81%99%E3%82%8B/
を参考に、

・前提条件として、Sambaは既に稼働しているとする。

・Elasticsearchをインストールする。

https://www.elastic.co/guide/en/elasticsearch/reference/current/rpm.html
を参考に、

$ rpm –import https://artifacts.elastic.co/GPG-KEY-elasticsearch

/etc/yum.repos.d/にelasticsearch.repoを作り、
[elasticsearch]
name=Elasticsearch repository for 7.x packages
baseurl=https://artifacts.elastic.co/packages/7.x/yum
gpgcheck=1
gpgkey=https://artifacts.elastic.co/GPG-KEY-elasticsearch
enabled=1
autorefresh=1
type=rpm-md
を記入。

ちなみに、
上記の https://www.elastic.co/guide/en/elasticsearch/reference/current/rpm.html では、
/etc/yum.repos.d/にelasticsearch.repo
[elasticsearch]
name=Elasticsearch repository for 8.x packages
baseurl=https://artifacts.elastic.co/packages/8.x/yum
gpgcheck=1
gpgkey=https://artifacts.elastic.co/GPG-KEY-elasticsearch
enabled=0
autorefresh=1
type=rpm-md
と、少し上のバージョンを指定している。

$ sudo dnf install –enablerepo=elasticsearch elasticsearch

/etc/elasticsearch/elasticsearch.yml
に、次の追加
xpack.security.enabled: false
discovery.type: single-node

※ちなみに、私のelasticsearch.ymlの設定は、こちら

$ sudo /bin/systemctl daemon-reload
$ sudo /bin/systemctl enable elasticsearch.service(システム起動時に自動起動)
$ sudo systemctl start elasticsearch.service(起動)

ちなみに、止める時は、
$ sudo systemctl stop elasticsearch.service

/etc/samba/smb.conf に次のような内容が含まれるようにする。
※ちなみに、私のsmb.confの設定は、こちら

[global]
workgroup = WORKGROUP
unix extensions = no
spotlight backend = elasticsearch
elasticsearch:index = files

# support macOS
vfs objects = acl_xattr catia fruit streams_xattr
fruit:locking = netatalk
fruit:encoding = native
fruit:wipe_intentionally_left_blank_rfork = yes
fruit:delete_empty_adfiles = yes
veto files = /._*/.DS_Store/
delete veto files = yes

[share]
path = /PATH_TO_SHARE(自分の共有ディレクトリ)
writable = yes
wide links = yes
follow symlinks = yes
spotlight = yes

・Sambaを再起動
$ systemctl restart smb nmb

 

続いて、fs2es-indexer をインストールする。

Dependencies:
PyYAML (python3-yaml in Debian)
Python-ElasticSearch (python-elasticsearch)

Poetryをインストール
curl -sSL https://install.python-poetry.org | python3 –

$ git clone https://github.com/eru/fs2es-indexer.git
$ cd fs2es-indexer
$ poetry install(なぜ、Poetryを使用しているか不明。いずれにせよ、setup.pyはなく、pyproject.tomlが入っている)

当方では、下記のエラーが出たので、python3.10をソースからコンパイルしてインストールした。すると3.10が使用されたようだ。
The currently activated Python version 3.6.8 is not supported by the project (^3.10).
Trying to find and use a compatible version.
Using python3.10 (3.10.1)
ちなみに、Red Hat Enterprise Linux 8(Rocky Linux 8も?)では、Python 3 は、AppStream リポジトリーの python36、python38、および python39 モジュールにより提供されるバージョン 3.6、3.8、および 3.9 で配布されます、とのこと。

$ mkdir -p /etc/fs2es-indexer
$ cp config.dist.yml /etc/fs2es-indexer/config.yml
$ cp setting.json mapping.json /etc/fs2es-indexer/(「Spotlight検索の効くSambaの構築をする」で書いてあるsetting.jsonは/etc/fs2es-indexerの中に入っていないので、入っているmapping.jsonをコピーする)

———————————————————————————————————————————-

ちなみに、本家のGitのリポジトリはこちら。
$ git clone https://github.com/Ellerhold/fs2es-indexer

Dependencies:はこちら。
Python3 (Debian package: python3)
PyYAML (Debian package: python3-yaml)
SetupTools (python-setuptools, Debian package:python3-setuptools)
Python-ElasticSearch (python-elasticsearch)
a running ElasticSearch instance v8 or higher (see ElasticSearch installation)

本家Gitリポジトリの場合、fs2es-indexerのインストールは、
$ python3 setup.py install
とするようだ。

※私はよくわからなかったので、本家のgitをインストール後、「Spotlight検索の効くSambaの構築をする」のgitでもインストールした。(fs2es-indexerはmvでリネーム後)

※よくわからないが、rootのホームフォルダ “~” と、/etc/ に fs2es-indexer がインストールされてしまったようだ。「Spotlight検索の効くSambaの構築をする」と本家Gitでは、インストール先が異なる??要検証。

サイト「Spotlight検索の効くSambaの構築をする」による
etc/fs2es-indexer/config.yml の変更内容は以下の通り

— config.dist.yml 2021-12-14 03:04:46.849276941 +0900
+++ /etc/fs2es-indexer/config.yml 2021-12-14 03:11:11.902831085 +0900
@@ -5,6 +5,7 @@

# The directories which should be indexed
directories:
+ – “/PATH_TO_SHARE”
# – “/my-storage-directory”

@@ -12,13 +13,14 @@
# TODO Papierkorb

# (Optional) Exclude directories / files from the index
-#exclusions:
+exclusions:
# Exclusion via a simple string search in the full path of the file / directory.
# If any of the given strings are found in the full path, it wont be added to the index.
# Usually faster than a regular expression!
-# partial_paths:
-# – “.DS_Store”
-# – “._.DS_Store”
+ partial_paths:
+ – “.DS_Store”
+ – “._.DS_Store”
+ – “lost+found”

# Exclusion via testing if a regular expression matches the full path of the file / directory.
# If any of the regular expression matches, it wont be added to the index.

上記をベースに自分用に、config.ymlを書き替える。
例えば、私の場合は、共有ディレクトリは次の2つ。
– “/home2/A3-linux-doc/A3-Linux”
– “/home2/A3-linux-doc/A3-MacWin”

※私の、/etc/fs2es-indexer/config.ymlの設定は、こちら

あとは、コマンドを実行でインデックスが作成される。

コマンドはここにある。
/usr/local/bin/fs2es-indexer

# Index the configured directories once
$ fs2es-indexer index →このコマンドでインデックスが作られるようだ。これを定期的に自動実行したいところ。

=======================================

なお、バックアップ用のA4のマシンでも設定していたところ時、
fs2es-indexer index の実行時に、下記のエラーが。

/usr/lib/python3.6/site-packages/requests/__init__.py:91: RequestsDependencyWarning: urllib3 (1.26.9) or chardet (3.0.4) doesn’t match a supported version!
RequestsDependencyWarning)
2022-06-16

下記のサイトから
Python (pip) – RequestsDependencyWarning: urllib3 (1.9.1) or chardet (2.3.0) doesn’t match a supported version

https://stackoverflow.com/questions/50202238/python-pip-requestsdependencywarning-urllib3-1-9-1-or-chardet-2-3-0-doe

これを実行。

$ pip uninstall urllib3
$ pip uninstall chardet
$ pip install requests

すると、エラーが出なくなったようだ。

=====================================================

その他のコマンド

# Index the configured directories, wait for the specified amount of time and index again
# Continously
$ fs2es-indexer daemon

$ nohup fs2es-indexer daemon &

パスが通ってない時はこうかな?
$ nohup /usr/local/bin/fs2es-indexer daemon &

↑こうすると、/etc/fs2es-indexer/config.yml の

# The wait time between indexing runs
# Allowed suffixes: s (seconds), m (minutes), h (hours), d (days)
wait_time: “30m”

で設定した間を経て、またインデックスをしてくれるようだ(?)
上の例なら、30分。

※nohup.outはカレントディレクトリに作られるようだ。要検証。

ちなみに、2023/2/19現在、nohup.outは次の3カ所にあった。

# find / -type f -name “nohup.out”
/home/p210059/nohup.out
/etc/yum.repos.d/nohup.out
/etc/fs2es-indexer/nohup.out

————————————————————————————————–

# Deletes all documents in the elasticsearch index
$ fs2es-indexer clear

# You can test the Spotlight search with this indexer!

# Shows the first 100 elasticsearch documents
$ fs2es-indexer search –search-path /srv/samba

# Searches elasticsearch documents with a match on all attributes:
$ fs2es-indexer search –search-path /srv/samba –search-term “my-doc.pdf”

# Searches elasticsearch documents with a match on the filename:
$ fs2es-indexer search –search-path /srv/samba –search-filename “my-doc.pdf”

# Displays some help texts
$ fs2es-indexer –help

=========================================================================================

自動起動の設定(検証中)

/etc/systemd/system の下にサービスファイルを作成します。

sudo vi /etc/systemd/system/fs2es-indexer.service

■書く内容

[Unit]
Description=start fs2es-indexer
After=network.target

[Service]
ExecStart=/usr/local/bin/fs2es-indexer daemon
WorkingDirectory=/etc/fs2es-indexer/

[Install]
WantedBy=multi-user.target

 

■サービス起動
sudo systemctl start fs2es-indexer.service

■サービス停止
sudo systemctl stop fs2es-indexer.service

■サービス自動起動を有効に
sudo systemctl enable fs2es-indexer.service

■サービス自動起動を無効化
sudo systemctl disable fs2es-indexer.service

■サービスステータス表示
sudo systemctl status fs2es-indexer.service


うーむ。エラーになっています。要検証です。

[root@AMULET3 ~]# systemctl status fs2es-indexer.service
● fs2es-indexer.service – start fs2es-indexer
Loaded: loaded (/etc/systemd/system/fs2es-indexer.service; enabled; vendor preset: disabled)
Active: failed (Result: exit-code) since Fri 2022-06-24 17:41:09 JST; 4min 13s ago
Process: 1130 ExecStart=/usr/bin/nohup /usr/local/bin/fs2es-indexer daemon & (code=exited, status=2)
Main PID: 1130 (code=exited, status=2)

6月 24 17:41:09 AMULET3 systemd[1]: Started start fs2es-indexer.
6月 24 17:41:09 AMULET3 nohup[1130]: usage: fs2es-indexer [-h] [–search-term SEARCH_TERM]
6月 24 17:41:09 AMULET3 nohup[1130]: [–search-filename SEARCH_FILENAME]
6月 24 17:41:09 AMULET3 nohup[1130]: [–search-path SEARCH_PATH] [–config CONFIGFILE]
6月 24 17:41:09 AMULET3 nohup[1130]: [–log-level-es LOGLEVELES]
6月 24 17:41:09 AMULET3 nohup[1130]: [action]
6月 24 17:41:09 AMULET3 nohup[1130]: fs2es-indexer: error: unrecognized arguments: &
6月 24 17:41:09 AMULET3 systemd[1]: fs2es-indexer.service: Main process exited, code=exited, status=2/INVALIDARGUMENT
6月 24 17:41:09 AMULET3 systemd[1]: fs2es-indexer.service: Failed with result ‘exit-code’.


2022/10/8に実行した時のエラー

# systemctl status fs2es-indexer.service

● fs2es-indexer.service – start fs2es-indexer
Loaded: loaded (/etc/systemd/system/fs2es-indexer.service; enabled; vendor preset: disabled)
Active: failed (Result: exit-code) since Thu 2022-10-06 17:47:58 JST; 1 day 23h ago
Process: 1186 ExecStart=/usr/local/bin/fs2es-indexer daemon (code=exited, status=1/FAILURE)
Main PID: 1186 (code=exited, status=1/FAILURE)

10月 06 17:47:58 AMULET3 fs2es-indexer[1186]: method, path, params=params, headers=headers, body=body
10月 06 17:47:58 AMULET3 fs2es-indexer[1186]: File “/usr/local/lib/python3.6/site-packages/elasticsearch/_sync/client/_base.py”, line 295, in perform_request
10月 06 17:47:58 AMULET3 fs2es-indexer[1186]: client_meta=self._client_meta,
10月 06 17:47:58 AMULET3 fs2es-indexer[1186]: File “/usr/local/lib/python3.6/site-packages/elastic_transport/_transport.py”, line 334, in perform_request
10月 06 17:47:58 AMULET3 fs2es-indexer[1186]: request_timeout=request_timeout,
10月 06 17:47:58 AMULET3 fs2es-indexer[1186]: File “/usr/local/lib/python3.6/site-packages/elastic_transport/_node/_http_urllib3.py”, line 199, in perform_request
10月 06 17:47:58 AMULET3 fs2es-indexer[1186]: raise err from None
10月 06 17:47:58 AMULET3 fs2es-indexer[1186]: elastic_transport.ConnectionError: Connection error caused by: ConnectionError(Connection error caused by: NewConnectionError(<urllib3.connection.HTTPConnection object at 0x7f4020b64278>: Failed to establish a new connection: [Errno 101] Network is unreachable))
10月 06 17:47:58 AMULET3 systemd[1]: fs2es-indexer.service: Main process exited, code=exited, status=1/FAILURE
10月 06 17:47:58 AMULET3 systemd[1]: fs2es-indexer.service: Failed with result ‘exit-code’.


 

Elasticsearch関連ファイルのインストール先

https://www.elastic.co/guide/en/elasticsearch/reference/current/rpm.html#rpm-layout

Directory layout of RPMedit
The RPM places config files, logs, and the data directory in the appropriate locations for an RPM-based system:

Type Description Default Location Setting

home
Elasticsearch home directory or $ES_HOME
/usr/share/elasticsearch

bin
Binary scripts including elasticsearch to start a node and elasticsearch-plugin to install plugins
/usr/share/elasticsearch/bin

conf
Configuration files including elasticsearch.yml
/etc/elasticsearch
ES_PATH_CONF

conf
Environment variables including heap size, file descriptors.
/etc/sysconfig/elasticsearch

conf
Generated TLS keys and certificates for the transport and http layer.
/etc/elasticsearch/certs

data
The location of the data files of each index / shard allocated on the node.
/var/lib/elasticsearch
path.data

jdk
The bundled Java Development Kit used to run Elasticsearch. Can be overridden by setting the ES_JAVA_HOME environment variable in /etc/sysconfig/elasticsearch.
/usr/share/elasticsearch/jdk

logs
Log files location.
/var/log/elasticsearch
path.logs

plugins
Plugin files location. Each plugin will be contained in a subdirectory.
/usr/share/elasticsearch/plugins

repo
Shared file system repository locations. Can hold multiple locations. A file system repository can be placed in to any subdirectory of any directory specified here.
Not configured
path.repo

Linux、Netatalk、Samba、NFSを使用したファイルサーバーについて研究・運用しています。

fsをフォローする
手順

コメント