検索エンジンを分離
何度か紹介しているのでご存知の方もいると思うが、ここの環境は、AWS上のEC2最少インスタンス(t2.nano)で稼働している。CPU「1コア」はまだ我慢できるとしても、メモリ「512MB」はかなりパフォーマンス的に苦しくなっていて、その対策として、以前、監視サービスである「Zabbix」は別のVPS環境へ移行したのではあるが、、、今回はメモリ食いの元凶である、検索エンジンの「Elasticsearch」を分離することにした。移行先は色々迷った挙げ句、5$/月のAmazon Lightsail VPS環境(1コア/1GB)に決定、OSはEC2と同じ「Ubuntu 18.04 LTS」を選択した。「Elasticsearch」のみを稼働させるので、セキリュティ対策として、可能な限りのポートはクローズしてある。
WordPressの変更は、プラグインに設定するサーバーを対象サーバーのアドレスに書き換えるだけで完了。ただし、Elasticsearch側で「elasticsearch.yml」のnetwork環境変数を「network.host = 0.0.0.0」に変更する必要があった。その後プラグインの設定画面でインデックスを再作成して移行完了。Mediawikiは「LocalSettings.php」へ「$wgCirrusSearchServers = [ ‘サーバーアドレス’ ];」を追加の記述が必要で、その後インデックスの再作成を実行したところ、以下のエラーが発生した。
root@192.168.0.1:php extensions/CirrusSearch/maintenance/updateSearchIndexConfig.php indexing namespaces... Indexing namespaces...[d38d6c644c97b4af0345d5a4] [no req] Elastica\Exception\ResponseException from line 179 of /var/www/html/wk/extensions/Elastica/vendor/ruflin/elastica/lib/Elastica/Transport/Http.php: no such index [index: mw_cirrus_metastore]
リモート接続している(新たに作成した)「Elasticsearch」上にメタストアが無いと言うエラーのようなので、「metasore.php」を実行して「metastore index」を作成してもらう。
root@192.168.0.1:php extensions/CirrusSearch/maintenance/metastore.php mw_cirrus_metastore missing creating. Creating metastore index... mw_cirrus_metastore_firstScanning available plugins... analysis-icu, analysis-kuromoji ok Green! Creating mw_cirrus_metastore alias to mw_cirrus_metastore_first. Update and check the CirrusSearch metastore index. Always operates on a single cluster.
この後は、「README」に書いてある通常の手順でインデックスを作成して移行が完了した。さて、これでどの程度パフォーマンスに効果が現れるのか、しばらく様子を見てみよう。