安装和配置 Manticore Search

2026-01-29 62 浏览 0 评论

安装 Manticore Search 相对来说有一定复杂度,主要取决于你的服务器系统版本和运行环境,不同发行版与内核版本对 Manticore 的兼容性略有差异。官方安装文档可参考:https://manticoresearch.com/install/。

我的服务器环境是 CentOS 7。由于 CentOS 7 较旧,最新版的 Manticore Search 已不再提供完整兼容支持,因此最新版本安装会遇到依赖问题,而旧版本的软件源又相对难找。折腾了一段时间后,最终安装了 v6.3.6 版本:https://manticoresearch.com/zh/install-6.3.6/ 。
如果你的系统版本较新(如 Ubuntu 20+/RockyLinux/AlmaLinux),建议直接使用最新版;而对我目前的需求而言,6.3.6 已经完全够用。

安装 manticore search

arch=$(arch)
yum -y install https://repo.manticoresearch.com/repository/manticoresearch/release/centos/7/ ${arch}/manticore-common-6.3.6_24080214.593045790-1.el7.centos.noarch.rpm https://repo.manticoresearch.com/repository/manticoresearch/release/centos/7/ ${arch}/manticore-icudata.rpm https://repo.manticoresearch.com/repository/manticoresearch/release/centos/7/ ${arch}/manticore-tzdata-1.0.0_240522.a8aa66e-1.noarch.rpm https://repo.manticoresearch.com/repository/manticoresearch/release/centos/7/ ${arch}/manticore-server-core-6.3.6_24080214.593045790-1.el7.centos.${arch}.rpm https://repo.manticoresearch.com/repository/manticoresearch/release/centos/7/ ${arch}/manticore-server-6.3.6_24080214.593045790-1.el7.centos.${arch}.rpm

arch=$(arch)
yum -y install https://repo.manticoresearch.com/repository/manticoresearch/release/centos/7/ ${arch}/manticore-backup-1.3.8_24052208.57fc406-1.el7.noarch.rpm

arch=$(arch)
yum -y install https://repo.manticoresearch.com/repository/manticoresearch/release/centos/7/ ${arch}/manticore-tools-6.3.6_24080214.593045790-1.el7.centos.${arch}.rpm

arch=$(arch)
yum -y install https://repo.manticoresearch.com/repository/manticoresearch/release/centos/7/ ${arch}/manticore-icudata.rpm

原始官方提供的执行命令如下,但在 CentOS 7 下直接执行会出现依赖或路径问题,因此我拆分并调整成上面的方式逐个安装,成功率更高。

arch=`arch`
yum -y install https://repo.manticoresearch.com/repository/manticoresearch/release/centos/7/ ${arch}/manticore-common-6.3.6_24080214.593045790-1.el7.centos.noarch.rpm \
https://repo.manticoresearch.com/repository/manticoresearch/release/centos/7/ ${arch}/manticore-server-6.3.6_24080214.593045790-1.el7.centos.${arch}.rpm \
https://repo.manticoresearch.com/repository/manticoresearch/release/centos/7/ ${arch}/manticore-server-core-6.3.6_24080214.593045790-1.el7.centos.${arch}.rpm \
https://repo.manticoresearch.com/repository/manticoresearch/release/centos/7/ ${arch}/manticore-tools-6.3.6_24080214.593045790-1.el7.centos.${arch}.rpm \
https://repo.manticoresearch.com/repository/manticoresearch/release/centos/7/ ${arch}/manticore-6.3.6_24080214.593045790-1.el7.centos.${arch}.rpm \
https://repo.manticoresearch.com/repository/manticoresearch/release/centos/7/ ${arch}/manticore-devel-6.3.6_24080214.593045790-1.el7.centos.noarch.rpm \
https://repo.manticoresearch.com/repository/manticoresearch/release/centos/7/ ${arch}/manticore-buddy-2.3.12_24071807.45f6b91-1.el7.noarch.rpm \
https://repo.manticoresearch.com/repository/manticoresearch/release/centos/7/ ${arch}/manticore-backup-1.3.8_24052208.57fc406-1.el7.noarch.rpm \
https://repo.manticoresearch.com/repository/manticoresearch/release/centos/7/ ${arch}/manticore-executor-1.1.12_24071807.0565a65-1.el7.${arch}.rpm \
https://repo.manticoresearch.com/repository/manticoresearch/release/centos/7/ ${arch}/manticore-columnar-lib-2.3.0_24052206.88a01c3-1.el7.centos.${arch}.rpm \
https://repo.manticoresearch.com/repository/manticoresearch/release/centos/7/ ${arch}/manticore-icudata.rpm \
https://repo.manticoresearch.com/repository/manticoresearch/release/centos/7/ ${arch}/manticore-galera-3.37-1.el7.${arch}.rpm \
https://repo.manticoresearch.com/repository/manticoresearch/release/centos/7/ ${arch}/manticore-tzdata-1.0.0_240522.a8aa66e-1.noarch.rpm

安装完成后,即可通过 systemctl 管理 Manticore Search 服务。

systemctl start manticore
systemctl enable manticore
searchd --status
systemctl restart manticore
systemctl status manticore
systemctl stop manticore

其中:

  • searchd 是 Manticore 的核心搜索守护进程;
  • 9306 端口提供 MySQL 协议接口;
  • 9308 端口提供 HTTP 接口;
  • 9313 为传统 SphinxQL/内部通信端口。

编写 Manticore Search 配置文件

我个人比较习惯使用传统 Sphinx 风格的配置方式,之前使用 Sphinx Search 时也是这样组织配置,因此在 Manticore 上继续沿用这一习惯。

Manticore 对 Sphinx 配置兼容度非常高,这种方式简单直观,便于后期维护。

source p2pspider
{
    type            = mysql
    sql_host        = 127.0.0.1
    sql_user        = root
    sql_pass        = knHo?1112
    sql_db          = p2pspider
    sql_port        = 3306
    sql_query_pre = SET NAMES utf8mb4
    sql_query       = SELECT id, name title, files content FROM torrent
}
index p2pspider
{
    source          = p2pspider
    path            = /var/lib/manticore/p2pspider
    charset_table   = 0..9, A..Z->a..z, a..z, U+4E00..U+9FFF
    morphology      = icu_chinese
    min_word_len    = 1
    dict            = keywords
}
searchd {
    listen = 127.0.0.1:9313
    listen = 0.0.0.0:9306:mysql
    listen = 127.0.0.1:9308:http
    log = /var/log/manticore/searchd.log
    query_log = /var/log/manticore/query.log
    pid_file = /run/manticore/searchd.pid
}

上面的配置已经启用了 ICU 中文分词。

Manticore 默认并不自带中文分词方案,需要结合 charset_table + morphology = icu_chinese 才能得到较好的中文搜索效果。我也是查阅了不少资料后,最终整理出这一套可用配置组合。

建立索引

首次建立索引:

indexer p2pspider

不停机增量更新索引:

indexer --rotate p2pspider

--rotate 参数会在新索引构建完成后自动替换旧索引,过程中 searchd 不会中断服务,适合生产环境使用。

测试搜索

mysql -h127.0.0.1 -P9306
SELECT * FROM p2pspider WHERE MATCH('shkd 400') LIMIT 10;

注意:如果在 Linux 命令行中直接输入中文关键词,可能会出现乱码或匹配不到结果的问题,这通常是终端字符编码未设置为 UTF-8 所导致。
但在后续通过 Web 接口或程序 API 调用时,一般不会有编码问题,因此不必过度纠结命令行测试阶段的乱码现象。

权限修正

如果 searchd 无法启动,通常是数据目录权限问题,可以执行:

chown -R manticore:manticore /var/lib/manticore
chmod -R 755 /var/lib/manticore

然后重新启动服务即可。

索引模式说明

当前这种配置方式属于 批量离线索引(Plain Index) ,并不是实时索引(RT Index)。

由于我的业务数据量较大,每次完整构建索引需要一定时间,因此我选择定期手动重建索引,或者通过 crontab 定时执行 indexer --rotate 来更新数据。

如果你的业务对实时写入和即时搜索有更高要求,也可以研究 Manticore 的 RT Index(实时索引)Percolate Index ,它们支持直接通过 SQL 接口插入数据并实时生效,但配置和资源消耗会相对更高。


发布评论

发布评论前请先 登录

评论列表 0

暂无评论