# Meilisearch Windwos 環境設定備忘 ## 安裝步驟 * 下載 `meilisearch-windows-amd64.exe` 進位執行檔, 官方的 GitHub 可以找到。 * 下載 meilisearch設定檔`config.toml`範例 , ``` curl https://raw.githubusercontent.com/meilisearch/meilisearch/latest/config.toml > config.toml ``` * 下載 [NSSM](https://nssm.cc/download),解壓後提取 win64 下的 `nssm.exe` 出來用就可以了。 * 建立服務安裝目錄,假設是 `E:\meilisearch` ,把 `meilisearch-windows-amd64.exe` 、 `nssm.exe` `config.toml` 丟進目錄。 * 已系統管理員身份開啟 powershell 進入 `E:\meilisearch` 目錄。 * 進行服務安裝 ``` .\nssm.exe install meilisearch $PWD\meilisearch-windows-amd64.exe .\nssm.exe set meilisearch Description MeiliSearch全文檢索服務 .\nssm.exe set meilisearch DisplayName MeiliSearch全文檢索服務 ``` * 服務操作管理 ``` 啟動 .\nssm.exe start meilisearch 停止 .\nssm.exe stop meilisearch 移除 .\nssm.exe remove meilisearch ``` ## config.toml 設定說明 * `http_addr` 設定要 listen 的 port 跟 IP * `env` 設定運行環境是 development 或 production ,在 production 模式一定要設定 master_key , 而且不會有可預覽的 WebUI 全部都透過 WebAPI 操作。 * `master_key` 設定 API 主要認證 Token ,至少要 16 bytes * `http_payload_size_limit` 設定 WebAPI 單次可接收的最大請求大小。 * `max_indexing_memory` 限制最大記憶體用量,沒設定預設最大為系統記憶體的 2/3 。 ## API操作指令參考 * 建立索引 ``` curl \ -X POST 'http://localhost:7700/indexes/epaems/documents?primaryKey=emsno' \ -H 'Authorization: Bearer MASTER_KEY' \ -H 'Content-Type: application/json' \ --data-binary @ems.json ``` * 查詢目前作業狀態 ``` curl -X GET 'http://localhost:7700/tasks' \ -H 'Authorization: Bearer MASTER_KEY' ``` * 刪除索引 ``` curl -X DELETE 'http://localhost:7700/indexes/epaems' \ -H 'Authorization: Bearer MASTER_KEY' ``` * 備份資料庫 ``` curl \ -X POST 'http://localhost:7700//dumps' \ -H 'Authorization: Bearer MASTER_KEY' ``` ## 目錄說明 ( 下面是預設位置在config.toml 中都可以調整) * `data.ms` 主要資料存放位置 * `dumps` 備份資料存放位置,每呼叫 API dumps 就會產生一個檔案,備下來的只有資料,當匯入時會需要重新產生索引 。 ## 目前已測試環境 * `Windwos 11` ok * `Windwos Server 2019` ok * `Dokcer on Linux` ok ## 網路參考資料 * [Meilisearch 官方網站](https://www.meilisearch.com/) * [Meilisearch GitHub](https://github.com/meilisearch/meilisearch) * [NSSM 官方網站](https://nssm.cc/) * [介紹好用工具:優異的 nssm 服務管理員 (Non-Sucking Service Manager) ](https://blog.miniasp.com/post/2021/09/15/Useful-tools-the-Non-Sucking-Service-Manager)