部署目录层级
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