mongod社区版 + mongot社区版,实现数据库+向量库检索等功能

部署目录层级

kotlin 复制代码
mongo
├── mongod
│   ├── data
│   ├── docker-compose.yml
│   ├── init.txt
│   ├── mongodb-community-server_8.2.1-ubi8.tar
│   ├── mongod.conf
│   └── sampledata.archive
└── mongot
    ├── data
    ├── docker-compose.yml
    ├── mongodb-community-search_0.54.0.tar
    ├── mongot.conf
    └── pwfile

部署 mongod社区版

创建文件 mongod.conf

yaml 复制代码
storage:
   dbPath: /data/db

net:
   port: 27017
   bindIp: 0.0.0.0

setParameter:
   searchIndexManagementHostAndPort: mongot-service:27028
   mongotHost: mongot-service:27028
   skipAuthenticationToSearchIndexManagementServer: false
   useGrpcForSearch: true


replication:
   replSetName: rs0

创建文件 init.txt

php 复制代码
# 进入shell
mongosh


# 查副本集状态
rs.status()


# 创建副本集
rs.initiate({
   _id: "rs0",
   members: [
     { _id: 0, host: "宿主机ip:27017" }
   ]
 });


# 建用户
db.getSiblingDB('admin').createUser({
   user: '数据库用户名',
   pwd: '数据库密码',
   roles: [{ role: 'root', db: 'admin' }]
});


use admin;

show users;

创建文件 docker-compose.yml

yaml 复制代码
services:
  mongod-service:
    user: root
    image: mongodb/mongodb-community-server:8.2.1-ubi8
    container_name: mongod
    command: 
         mongod --config /etc/mongod.conf 
    ports:
      - 27017:27017
    volumes:
      - ./data:/data/db
      - ./mongod.conf:/etc/mongod.conf:ro
      - /etc/hosts:/etc/hosts
    networks:
      - mongo-network
    healthcheck:
      test: ["CMD", "mongosh", "--eval", "db.adminCommand('ping')"]
      interval: 10s
      timeout: 5s
      retries: 5
      start_period: 30s

networks:
  mongo-network:
    name: mongo-network

启动

csharp 复制代码
docker-compose up -d
根据init.txt,进入容器,初始化

部署 mongot社区版

创建文件 mongot.conf

yaml 复制代码
syncSource:
   replicaSet:
      hostAndPort: "mongod-service:27017"
      username: 数据库用户名
      passwordFile: /mongot-community/pwfile
      authSource: admin
      tls: false
      readPreference: primaryPreferred
storage:
   dataPath: "/data/mongot"
server:
   grpc:
      address: "mongot-service:27028"
      tls:
         mode: "disabled"
metrics:
   enabled: true
   address: "mongot-service:9946"
healthCheck:
   address: "mongot-service:8080"
logging:
   verbosity: DEBUG

创建文件 pwfile

bash 复制代码
echo -n "数据库密码" > pwfile
chmod 400 pwfile

创建文件 docker-compose.yml

yaml 复制代码
services:
  mongot-service:
    user: root
    image: mongodb/mongodb-community-search:0.54.0
    container_name: mongot
    networks:
      - mongo-network
    volumes:
      - ./data:/data/mongot
      - ./mongot.conf:/mongot-community/config.default.yml
      - ./pwfile:/mongot-community/pwfile:ro
      - /etc/hosts:/etc/hosts
    ports:
      - 27028:27028
      - 9946:9946
      - 8080:8080
    healthcheck:
      test: ["CMD", "curl", "-f", "http://宿主机ip:8080/health"]
      interval: 30s
      timeout: 10s
      retries: 3

networks:
  mongo-network:
    name: mongo-network

启动

复制代码
docker-compose up -d

验证

ruby 复制代码
验证
https://www.mongodb.com/zh-cn/docs/atlas/atlas-vector-search/tutorials/vector-search-quick-start/?deployment-type=self#init-mongo.sh
相关推荐
KYGALYX4 小时前
服务异步通信
开发语言·后端·微服务·ruby
掘了4 小时前
「2025 年终总结」在所有失去的人中,我最怀念我自己
前端·后端·年终总结
爬山算法5 小时前
Hibernate(90)如何在故障注入测试中使用Hibernate?
java·后端·hibernate
Moment5 小时前
富文本编辑器在 AI 时代为什么这么受欢迎
前端·javascript·后端
Cobyte6 小时前
AI全栈实战:使用 Python+LangChain+Vue3 构建一个 LLM 聊天应用
前端·后端·aigc
程序员侠客行7 小时前
Mybatis连接池实现及池化模式
java·后端·架构·mybatis
Honmaple7 小时前
QMD (Quarto Markdown) 搭建与使用指南
后端
PP东7 小时前
Flowable学习(二)——Flowable概念学习
java·后端·学习·flowable
invicinble7 小时前
springboot的核心实现机制原理
java·spring boot·后端
全栈老石8 小时前
Python 异步生存手册:给被 JS async/await 宠坏的全栈工程师
后端·python