码迷,mamicode.com
首页 > 数据库 > 详细

docker——mongodb副本集

时间:2020-06-14 14:50:16      阅读:76      评论:0      收藏:0      [点我收藏+]

标签:查看   error   info   inf   res   and   doc   status   mongodb   

 

docker mongodb 副本集

 

 

docker network create net-mongoset

docker network ls

 

docker run -d -p27001:27017 --name docker_mongo1 --net net-mongoset  mongo:3.4.24 --replSet yinSet

docker run -d -p27002:27017 --name docker_mongo2 --net net-mongoset  mongo:3.4.24 --replSet yinSet

docker run -d -p27003:27017 --name docker_mongo3 --net net-mongoset  mongo:3.4.24 --replSet yinSet

 

mongo --port 27001

 

>rs.status()

 

> rs.initiate()

{

"info2" : "no configuration specified. Using a default configuration for the set",

"me" : "218f50912c40:27017",

"ok" : 1

}

 

>rs.add("docker_mongo2:27017")

>rs.add("docker_mongo3:27017")

 

>rs.status()

 

主节点插入数据,查看副节点同步

mongo --port 27001

yinSet:PRIMARY> use mytest

switched to db mytest

yinSet:PRIMARY> 

yinSet:PRIMARY> db.mytest.insert({"name":"axboy"})

WriteResult({ "nInserted" : 1 })

yinSet:PRIMARY> show dbs;

yinSet:PRIMARY> use mytest

switched to db mytest

 

yinSet:PRIMARY> db2 = (new Mongo(‘127.0.0.1:27002‘)).getDB(‘mytest‘)

mytest

yinSet:PRIMARY> db2.mytest.find()

Error: error: {

"ok" : 0,

"errmsg" : "not master and slaveOk=false",

"code" : 13435,

"codeName" : "NotMasterNoSlaveOk"

}

yinSet:PRIMARY> db2.setSlaveOk()

yinSet:PRIMARY> 

yinSet:PRIMARY> db2.mytest.find()

{ "_id" : ObjectId("5ee5aff0d779793f66bc376f"), "name" : "axboy" }

yinSet:PRIMARY> 

yinSet:PRIMARY> 

 

 

docker——mongodb副本集

标签:查看   error   info   inf   res   and   doc   status   mongodb   

原文地址:https://www.cnblogs.com/xingchong/p/13124426.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!