单机
配置
processManagement:
fork: true
net:
bindIp: localhost
port: 27017
storage:
dbPath: /Volumes/SAO/data/mongo/27017/db
systemLog:
destination: file
path: "/Volumes/SAO/data/mongo/27017/mongod.log"
logAppend: true
storage:
journal:
enabled: true
启动命令
mongod -f /Volumes/SAO/data/mongo/27017/mongod.conf --fork
副本集
配置
replication:
oplogSizeMB: 64
replSetName: rs2
添加集群
rs.initiate(
{
_id: "rs2",
version: 1,
members: [
{ _id: 0, host : "127.0.0.1:27017" },
{ _id: 1, host : "127.0.0.1:27018" },
{ _id: 2, host : "127.0.0.1:27019" }
]
}
)
启动指令
mongod -f /Volumes/SAO/data/mongo/27017/mongod.conf --fork
mongod -f /Volumes/SAO/data/mongo/27018/mongod.conf --fork
mongod -f /Volumes/SAO/data/mongo/27019/mongod.conf --fork
常用指令
允许查询
rs.secondaryOk()