您可以在 MongoDB Community Edition 中安装 MongoDB Search 和 MongoDB 向量搜索进程 mongot。mongot 进程可以作为具有 .tgz 扩展名的 tarball 部署到所有 Linux 发行版,例如 Red Hat、Ubuntu、Debian、SUSE 和 Amazon Linux。
开始之前
要在自管理部署中安装 mongot,您必须满足以下先决条件:
MongoDB Community Edition v8.3 或更高版本。
有关安装教程,请参阅安装MongoDB Community Edition。
注意
您必须安装 MongoDB 8.3 或更高版本,才能运行 MongoDB Search 和 MongoDB Vector Search 进程,无论您使用独立运行的实例自管理部署,还是使用 MongoDB Controllers for Kubernetes Operator 操作符进行部署。有关详细信息,请参阅 对
mongot的兼容性和要求。具有密钥文件访问权限控制的已启动副本集。
步骤
下载 mongot tarball。
从 MongoDB Search in Community 下载中心 下载适合您系统架构的最新 MongoDB Search in Community 索引文件包。
要从命令行下载特定版本,请将 {VERSION_NUMBER} 替换为您需要的 mongot 的版本,然后运行适用于您系统架构的命令:
wget https://downloads.mongodb.org/mongodb-search-community/{VERSION_NUMBER}/mongot_community_{VERSION_NUMBER}_linux_aarch64.tgzwget https://downloads.mongodb.org/mongodb-search-community/{VERSION_NUMBER}/mongot_community_{VERSION_NUMBER}_linux_x86_64.tgz(可选).验证 tarball 包的完整性。
有关详细信息,请参阅验证mongot包的完整性。
提取mongot tarball。
将 {VERSION_NUMBER} 替换为您下载的 mongot 的版本,并运行针对您的系统架构的命令以提取 tarball:
tar -zxvf mongot_community_{VERSION_NUMBER}_linux_aarch64.tgztar -zxvf mongot_community_{VERSION_NUMBER}_linux_x86_64.tgz注意
如果您的网络浏览器在下载过程中自动解压缩该文件,则文件扩展名为 .tar。
该 tarball 包含一个示例配置文件、mongot 启动程序脚本以及 MongoDB Search 和向量搜索许可证信息。
配置 mongod 以与 mongot 通信。
如果您有要使用的现有副本集,请配置以下 mongod 参数来路由搜索和MongoDB Vector Search 查询并托管索引。
Parameter | 说明 |
|---|---|
|
|
|
您必须在 |
| 指定是否为搜索索引管理服务器启用身份验证 |
| 指定是否为MongoDB搜索启用 GRPC |
示例,您可以将以下行添加到 mongod 配置文件中,然后重新启动 mongod:
setParameter: searchIndexManagementHostAndPort: localhost:27028 mongotHost: localhost:27028 skipAuthenticationToSearchIndexManagementServer: false useGrpcForSearch: true有关设置 mongod 参数的更多信息,请参阅自管理部署的 MongoDB Server Parameters。有关搜索特定 setParameter 选项的详细信息,请参阅MongoDB Search 选项。
注意
mongotHost、searchIndexManagementHostAndPort和useGrpcForSearch参数仅在启动时进行设置。您无法在运行时通过 setParameter 更改它们。要将 mongod 指向另一个 mongot 实例,请在 mongod 配置文件中更新这些参数,然后重启 mongod。
如果要使用密钥文件身份验证部署新的副本集,请按照部署具有密钥文件身份验证的自管理副本集。中的步骤进行操作。
为 MongoDB 部署上的 mongot 进程创建一个用户。
mongot 必须能够通过具有searchCoordinator角色的用户连接到MongoDB 部署。
以管理员用户身份连接到
mongosh。mongosh --port 27017 -u <your_admin_username> -p <your_admin_password>连接到
admin数据库。运行以下命令以连接到
admin数据库:use admin创建
mongot用户。要创建具有
searchCoordinator角色的用户:将
<mongot-username>替换为mongot用户的用户名将
<mongot-password>替换为在下一步中为passwordFile指定的密码运行以下命令:
db.createUser( { user: <mongot-username>, pwd: <mongot-password>, roles: [ "searchCoordinator"] })
指定 mongot 配置选项。
您可以使用 YAML 配置文件配置 mongot。使用名为 config.default.yml 的附带示例配置文件或新的配置文件来定义配置。有关 mongot 配置选项的更多信息,请参阅 mongot 选项。
该 tarball 包含以下示例配置文件config.default.yml,具有默认的mongot 设置。您可以修改部署的设置:
警告
根据您的系统拓扑结构,可能需要将 mongot 查询服务器绑定到可从 MongoDB 集群访问的接口。虽然允许绑定到 0.0.0.0 IP 地址,但这会将服务器暴露于所有公共网络,并带来未经授权访问的风险。
为了增强安全性,请考虑将 server.grpc.address 限制为在网络层受控制和保护的特定接口,例如 localhost 或其他可信内部地址。
syncSource: replicaSet: hostAndPort: "localhost:27017" # Replace with the mongod host and port. scramAuth: username: mongotUser # Replace with mongod username enabled with "searchCoordinator" role. authSource: admin # Replace with the database to authenticate the user against. passwordFile: "/etc/mongot/secrets/passwordFile" # Replace with path to password file for the above user. tls: enabled: falsestorage: dataPath: "/var/lib/mongot" # Replace with the path where you want mongot to store search data.server:grpc: address: "localhost:27028" # Replace with the address and port for mongot listen server tls: mode: "disabled"metrics: enabled: true address: "localhost:9946"healthCheck: address: "localhost:8080"logging: verbosity: INFO注意
配置文件中的 dataPath 目录必须可由运行 mongot 的用户写入。
示例配置使用 scramAuth 块进行 SCRAM 身份验证。您必须为同步源配置一种身份验证机制:SCRAM 或 X.509。要使用 TLS 客户端证书而不是用户名和密码进行身份验证,请使用 x509 块。对于这两种机制(包括分片集群 syncSource.router 配置),请参阅 为 mongot 配置身份验证和授权。
此示例在同一托管上运行 mongot 和 mongod,因此,它将 server.grpc.address 绑定到 localhost 并禁用 TLS。如果在不同的托管上运行 mongot 和 mongod,请完成以下步骤:
将
server.grpc.address绑定到mongod可以访问的网络接口,而不是localhost。将
mongod、mongotHost和searchIndexManagementHostAndPort参数设置为该地址。启用同步源和 gRPC 连接的 TLS。在没有 TLS 的情况下运行仅在
mongot和mongod在同一个托管上运行时才适合。要配置 TLS,请参阅 为mongot配置 TLS 加密。
使用 logging.logPath 指定 mongot 写入的日志文件的路径。如果您未指定日志文件路径,mongot 将日志记录到标准输出。
验证 mongot 进程的运行状况。
要验证,请使用 HTTP 客户端或 curl 向 /health 终结点发送请求。例如,发送 curl 请求,类似于以下示例请求:
curl localhost:8080/health端点在响应中返回以下内容之一:
SERVING, 如果mongot进程正在运行mongot可能无法提供服务查询,因为它不检查索引的状态,而索引必须处于Ready状态才能提供服务查询。NOT_SERVING,如果mongot进程未运行
有关详细信息,请参阅验证 mongot 连接。
卸载MongoDB Search 和MongoDB Vector Search
要从系统中删除 MongoDB Search 和 MongoDB Vector Search,必须删除 mongot、配置文件以及任何包含数据和日志的目录。以下部分将指导您完成必要步骤。
删除 的所有日志和日志目录 mongot
要删除 mongot 的日志和日志目录,请使用在 logging.logPath 中指定的日志目录的完整路径运行以下命令:
rm -rf /path/to/mongot-logs后续步骤
创建MongoDB Search 索引