Docker Mongo setting master-slave backup

Time:2022-1-5

First set the mongodb config file

systemLog:
   destination: file
   path: "/my/log/mongodb/mongod.log"
   logAppend: true
replication:
   oplogSizeMB: 1024
   replSetName: configReplSet
   secondaryIndexPrefetch: all

Start the docker Mongo service

docker run --name db -v /my:/my -v /my/db:/data/db -p 27017:27017 -v /etc/localtime:/etc/localtime:ro -d mongo --config /my/config/mongod.conf

Enter the main server Mongo

cfg={"_id":"configReplSet",
     "members":[
         {"_id":0,"host":"ip:27017"}
     ]
}

users.initiate(cfg)Start configuration

thenrs.status()View configuration results

Add another server to enterrs.add("ip_second:27017")

Add another arbiter to enterrs.add("ip_third:27017",true)

end.