Mongodb副本集

Mongodb副本集

文档管理(查询、插入、更新、删除)

副本集介绍

也称为Mongdb复制

指在多个服务器上存储数据副本,并实现数据同步

提高数据可用性、安全性,方便数据恢复

MongoDB复制原理

至少需要两个节点。其中一个是主节点,负责处理客户端请求,其余是从节点,负责复制主节点数据

常见搭配方式:一主一从、一主多从

主节点记录所有操作oplog,从节点定期轮询主节点获取这些操作,然后对自己的数据副本执行这些操作,从而保证从节点的数据与主节点一致

副本集实现方式

Master-Slave主从复制

启动一台服务器时加上”-master”参数,作为主节点

启动其他服务器时加上”-slave” 和  “-source” 参数,作为从节点

主从复制的优点

从节点可以提供数据查询,降低主节点的访问压力

由从节点执行备份,避免锁定主节点数据

当主节点故障时,可快速切换到从节点,实现高可用

副本集实现方式

Replica Sets副本集

1.6版本开始支持,优于之前的replication

支持故障自动切换、自动修复成员节点,降低运维成本

Replica Sets副本集的结构类似高可用集群

配置Replica Sets

  230  ls mongodb-linux-x86_64-rhel70-3.6.3.tgz 

  231  mkdir /usr/local/mongodb

  232  tar -zxf mongodb-linux-x86_64-rhel70-3.6.3.tgz 

  233  cp -r mongodb-linux-x86_64-rhel70-3.6.3/bin/  /usr/local/mongodb

  234  cd /usr/local/mongodb

  235  mkdir -p etc log data/db

  236  ls

  237  cd etc

  238  ls

  239  vim mongodb.conf

  240  cd ../

  241  ls

  242  ./bin/mongod -f /usr/local/mongodb/etc/mongodb.conf 

  243  netstat -utnlp | grep :27017

  244  history 

  245  netstat -utnlp | grep :27017

  246  ./bin/mongod --shutdown -f /usr/local/mongodb/etc/mongodb.conf 

  247  ls 

  248  cd etc/

  249  ls

  250  cat mongodb.conf 

  251  cd ../

  252  ls

  253  ./bin/mongod --shutdown -f /usr/local/mongodb/etc/mongodb.conf

  254  pwd

  255  rm -rf /usr/local/mongodb/data/db/*

  256  vim /usr/local/mongodb/etc/mongodb.conf

  257  cd ~

  258  vim /usr/local/mongodb/etc/mongodb.conf

  259  mongod -f /usr/local/mongodb/etc/mongodb.conf

  260  tail -2 /etc/profile

  261  vim  /etc/profile

  262  source /etc/profile

  263  tail -2 /etc/profile

  264  vim /usr/local/mongodb/etc/mongodb.conf 

  265  mongo --host 192.168.4.51 config={

  266  mongo --host 192.168.4.51 --port 27051

  267  ss -tunlp | grep mongo

  268  mongod -f /usr/local/mongodb/etc/mongodb.conf

  269  mongo --host 192.168.4.51 --port 27051

  270  ss -tunlp | grep mongo

cat /usr/local/mongodb/etc/mongodb.conf 
dbpath=/usr/local/mongodb/data/db
fork=true
logpath=/usr/local/mongodb/log/mongodb.log
logappend=true
bind_ip=192.168.4.51
port=27051
replSet=rs1

 vim  /etc/profile

  export PATH=/usr/local/mongodb/bin:$PATH

.   /etc/profile


vim /etc/bashrc

alias mstop='mongod --shutdown -f /usr/local/mongodb/etc/mongodb.conf'

alias mstar='mongod -f /usr/local/mongodb/etc/mongodb.conf'

.   /etc/bashrc

[root@host52 ~]# mongo --host 192.168.4.51 --port 27051

MongoDB shell version v3.6.3

connecting to: mongodb://192.168.4.51:27051/

MongoDB server version: 3.6.3

Server has startup warnings: 

2018-07-09T09:43:10.836+0800 I CONTROL  [initandlisten] 

2018-07-09T09:43:10.836+0800 I CONTROL  [initandlisten] ** WARNING: Access control is not enabled for the database.

2018-07-09T09:43:10.836+0800 I CONTROL  [initandlisten] **          Read and write access to data and configuration is unrestricted.

2018-07-09T09:43:10.836+0800 I CONTROL  [initandlisten] ** WARNING: You are running this process as the root user, which is not recommended.

2018-07-09T09:43:10.836+0800 I CONTROL  [initandlisten] 

2018-07-09T09:43:10.837+0800 I CONTROL  [initandlisten] 

2018-07-09T09:43:10.837+0800 I CONTROL  [initandlisten] ** WARNING: /sys/kernel/mm/transparent_hugepage/enabled is 'always'.

2018-07-09T09:43:10.837+0800 I CONTROL  [initandlisten] **        We suggest setting it to 'never'

2018-07-09T09:43:10.837+0800 I CONTROL  [initandlisten] 

2018-07-09T09:43:10.837+0800 I CONTROL  [initandlisten] ** WARNING: /sys/kernel/mm/transparent_hugepage/defrag is 'always'.

2018-07-09T09:43:10.837+0800 I CONTROL  [initandlisten] **        We suggest setting it to 'never'

2018-07-09T09:43:10.837+0800 I CONTROL  [initandlisten] 

> config={ _id:"rs1", members:[ {_id:0,host:"192.168.4.51:27051"}, {_id:1,host:"192.168.4.52:27052"}, {_id:2,host:"192.168.4.53:27053"} ] };

{

"_id" : "rs1",

"members" : [

{

"_id" : 0,

"host" : "192.168.4.51:27051"                                    #"host" : "192.168.4.51:27051"默认在那个主机操作就是主                                                                                                  #库,"host" : "192.168.4.51:27051"  primary:10  优先级大的为主库

},

{

"_id" : 1,

"host" : "192.168.4.52:27052"

},

{

"_id" : 2,

"host" : "192.168.4.53:27053"

}

]

}

> rs.initiate(config)

{

"ok" : 1,

"operationTime" : Timestamp(1531101753, 1),

"$clusterTime" : {

"clusterTime" : Timestamp(1531101753, 1),

"signature" : {

"hash" : BinData(0,"AAAAAAAAAAAAAAAAAAAAAAAAAAA="),

"keyId" : NumberLong(0)

}

}

}

rs1:SECONDARY> rs.isMaster()

{

"hosts" : [

"192.168.4.51:27051",

"192.168.4.52:27052",

"192.168.4.53:27053"

],

"setName" : "rs1",

"setVersion" : 1,

"ismaster" : true,

"secondary" : false,

"primary" : "192.168.4.51:27051",

"me" : "192.168.4.51:27051",

"electionId" : ObjectId("7fffffff0000000000000001"),

"lastWrite" : {

"opTime" : {

"ts" : Timestamp(1531101769, 1),

"t" : NumberLong(1)

},

"lastWriteDate" : ISODate("2018-07-09T02:02:49Z"),

"majorityOpTime" : {

"ts" : Timestamp(1531101769, 1),

"t" : NumberLong(1)

},

"majorityWriteDate" : ISODate("2018-07-09T02:02:49Z")

},

"maxBsonObjectSize" : 16777216,

"maxMessageSizeBytes" : 48000000,

"maxWriteBatchSize" : 100000,

"localTime" : ISODate("2018-07-09T02:03:00.159Z"),

"logicalSessionTimeoutMinutes" : 30,

"minWireVersion" : 0,

"maxWireVersion" : 6,

"readOnly" : false,

"ok" : 1,

"operationTime" : Timestamp(1531101769, 1),

"$clusterTime" : {

"clusterTime" : Timestamp(1531101769, 1),

"signature" : {

"hash" : BinData(0,"AAAAAAAAAAAAAAAAAAAAAAAAAAA="),

"keyId" : NumberLong(0)

}

}

}

rs1:PRIMARY> rs.isMaster()

{

"hosts" : [

"192.168.4.51:27051",

"192.168.4.52:27052",

"192.168.4.53:27053"

],

"setName" : "rs1",

"setVersion" : 1,

"ismaster" : true,

"secondary" : false,

"primary" : "192.168.4.51:27051",

"me" : "192.168.4.51:27051",

"electionId" : ObjectId("7fffffff0000000000000001"),

"lastWrite" : {

"opTime" : {

"ts" : Timestamp(1531101836, 1),

"t" : NumberLong(1)

},

"lastWriteDate" : ISODate("2018-07-09T02:03:56Z"),

"majorityOpTime" : {

"ts" : Timestamp(1531101836, 1),

"t" : NumberLong(1)

},

"majorityWriteDate" : ISODate("2018-07-09T02:03:56Z")

},

"maxBsonObjectSize" : 16777216,

"maxMessageSizeBytes" : 48000000,

"maxWriteBatchSize" : 100000,

"localTime" : ISODate("2018-07-09T02:03:57.856Z"),

"logicalSessionTimeoutMinutes" : 30,

"minWireVersion" : 0,

"maxWireVersion" : 6,

"readOnly" : false,

"ok" : 1,

"operationTime" : Timestamp(1531101836, 1),

"$clusterTime" : {

"clusterTime" : Timestamp(1531101836, 1),

"signature" : {

"hash" : BinData(0,"AAAAAAAAAAAAAAAAAAAAAAAAAAA="),

"keyId" : NumberLong(0)

}

}

}

rs1:PRIMARY> exit

bye

[root@host52 ~]# ss -tunlp | grep mongo

tcp    LISTEN     0      128    192.168.4.52:27052                 *:*                   users:(("mongod",pid=2152,fd=11))

[root@host52 ~]# mongo --host 192.168.4.51 --port 27051

MongoDB shell version v3.6.3

connecting to: mongodb://192.168.4.51:27051/

MongoDB server version: 3.6.3

Server has startup warnings: 

2018-07-09T09:43:10.836+0800 I CONTROL  [initandlisten] 

2018-07-09T09:43:10.836+0800 I CONTROL  [initandlisten] ** WARNING: Access control is not enabled for the database.

2018-07-09T09:43:10.836+0800 I CONTROL  [initandlisten] **          Read and write access to data and configuration is unrestricted.

2018-07-09T09:43:10.836+0800 I CONTROL  [initandlisten] ** WARNING: You are running this process as the root user, which is not recommended.

2018-07-09T09:43:10.836+0800 I CONTROL  [initandlisten] 

2018-07-09T09:43:10.837+0800 I CONTROL  [initandlisten] 

2018-07-09T09:43:10.837+0800 I CONTROL  [initandlisten] ** WARNING: /sys/kernel/mm/transparent_hugepage/enabled is 'always'.

2018-07-09T09:43:10.837+0800 I CONTROL  [initandlisten] **        We suggest setting it to 'never'

2018-07-09T09:43:10.837+0800 I CONTROL  [initandlisten] 

2018-07-09T09:43:10.837+0800 I CONTROL  [initandlisten] ** WARNING: /sys/kernel/mm/transparent_hugepage/defrag is 'always'.

2018-07-09T09:43:10.837+0800 I CONTROL  [initandlisten] **        We suggest setting it to 'never'

2018-07-09T09:43:10.837+0800 I CONTROL  [initandlisten] 

> config={ _id:"rs1", members:[ {_id:0,host:"192.168.4.51:27051"}, {_id:1,host:"192.168.4.52:27052"}, {_id:2,host:"192.168.4.53:27053"} ] };

{

"_id" : "rs1",

"members" : [

{

"_id" : 0,

"host" : "192.168.4.51:27051"

},

{

"_id" : 1,

"host" : "192.168.4.52:27052"

},

{

"_id" : 2,

"host" : "192.168.4.53:27053"

}

]

}

> rs.initiate(config)

{

"ok" : 1,

"operationTime" : Timestamp(1531101753, 1),

"$clusterTime" : {

"clusterTime" : Timestamp(1531101753, 1),

"signature" : {

"hash" : BinData(0,"AAAAAAAAAAAAAAAAAAAAAAAAAAA="),

"keyId" : NumberLong(0)

}

}

}

rs1:SECONDARY> rs.isMaster()

{

"hosts" : [

"192.168.4.51:27051",

"192.168.4.52:27052",

"192.168.4.53:27053"

],

"setName" : "rs1",

"setVersion" : 1,

"ismaster" : true,

"secondary" : false,

"primary" : "192.168.4.51:27051",

"me" : "192.168.4.51:27051",

"electionId" : ObjectId("7fffffff0000000000000001"),

"lastWrite" : {

"opTime" : {

"ts" : Timestamp(1531101769, 1),

"t" : NumberLong(1)

},

"lastWriteDate" : ISODate("2018-07-09T02:02:49Z"),

"majorityOpTime" : {

"ts" : Timestamp(1531101769, 1),

"t" : NumberLong(1)

},

"majorityWriteDate" : ISODate("2018-07-09T02:02:49Z")

},

"maxBsonObjectSize" : 16777216,

"maxMessageSizeBytes" : 48000000,

"maxWriteBatchSize" : 100000,

"localTime" : ISODate("2018-07-09T02:03:00.159Z"),

"logicalSessionTimeoutMinutes" : 30,

"minWireVersion" : 0,

"maxWireVersion" : 6,

"readOnly" : false,

"ok" : 1,

"operationTime" : Timestamp(1531101769, 1),

"$clusterTime" : {

"clusterTime" : Timestamp(1531101769, 1),

"signature" : {

"hash" : BinData(0,"AAAAAAAAAAAAAAAAAAAAAAAAAAA="),

"keyId" : NumberLong(0)

}

}

}

rs1:PRIMARY> rs.isMaster()

{

"hosts" : [

"192.168.4.51:27051",

"192.168.4.52:27052",

"192.168.4.53:27053"

],

"setName" : "rs1",

"setVersion" : 1,

"ismaster" : true,

"secondary" : false,

"primary" : "192.168.4.51:27051",

"me" : "192.168.4.51:27051",

"electionId" : ObjectId("7fffffff0000000000000001"),

"lastWrite" : {

"opTime" : {

"ts" : Timestamp(1531101836, 1),

"t" : NumberLong(1)

},

"lastWriteDate" : ISODate("2018-07-09T02:03:56Z"),

"majorityOpTime" : {

"ts" : Timestamp(1531101836, 1),

"t" : NumberLong(1)

},

"majorityWriteDate" : ISODate("2018-07-09T02:03:56Z")

},

"maxBsonObjectSize" : 16777216,

"maxMessageSizeBytes" : 48000000,

"maxWriteBatchSize" : 100000,

"localTime" : ISODate("2018-07-09T02:03:57.856Z"),

"logicalSessionTimeoutMinutes" : 30,

"minWireVersion" : 0,

"maxWireVersion" : 6,

"readOnly" : false,

"ok" : 1,

"operationTime" : Timestamp(1531101836, 1),

"$clusterTime" : {

"clusterTime" : Timestamp(1531101836, 1),

"signature" : {

"hash" : BinData(0,"AAAAAAAAAAAAAAAAAAAAAAAAAAA="),

"keyId" : NumberLong(0)

}

}

}

rs1:PRIMARY> exit

bye

[root@host52 ~]# ss -tunlp | grep mongo

tcp    LISTEN     0      128    192.168.4.52:27052                 *:*                   users:(("mongod",pid=2152,fd=11))

[root@host52 ~]# mongo --host 192.168.4.51 --port 27051

MongoDB shell version v3.6.3

connecting to: mongodb://192.168.4.51:27051/

MongoDB server version: 3.6.3

Server has startup warnings: 

2018-07-09T09:43:10.836+0800 I CONTROL  [initandlisten] 

2018-07-09T09:43:10.836+0800 I CONTROL  [initandlisten] ** WARNING: Access control is not enabled for the database.

2018-07-09T09:43:10.836+0800 I CONTROL  [initandlisten] **          Read and write access to data and configuration is unrestricted.

2018-07-09T09:43:10.836+0800 I CONTROL  [initandlisten] ** WARNING: You are running this process as the root user, which is not recommended.

2018-07-09T09:43:10.836+0800 I CONTROL  [initandlisten] 

2018-07-09T09:43:10.837+0800 I CONTROL  [initandlisten] 

2018-07-09T09:43:10.837+0800 I CONTROL  [initandlisten] ** WARNING: /sys/kernel/mm/transparent_hugepage/enabled is 'always'.

2018-07-09T09:43:10.837+0800 I CONTROL  [initandlisten] **        We suggest setting it to 'never'

2018-07-09T09:43:10.837+0800 I CONTROL  [initandlisten] 

2018-07-09T09:43:10.837+0800 I CONTROL  [initandlisten] ** WARNING: /sys/kernel/mm/transparent_hugepage/defrag is 'always'.

2018-07-09T09:43:10.837+0800 I CONTROL  [initandlisten] **        We suggest setting it to 'never'

2018-07-09T09:43:10.837+0800 I CONTROL  [initandlisten] 

> config={ _id:"rs1", members:[ {_id:0,host:"192.168.4.51:27051"}, {_id:1,host:"192.168.4.52:27052"}, {_id:2,host:"192.168.4.53:27053"} ] };

{

"_id" : "rs1",

"members" : [

{

"_id" : 0,

"host" : "192.168.4.51:27051"

},

{

"_id" : 1,

"host" : "192.168.4.52:27052"

},

{

"_id" : 2,

"host" : "192.168.4.53:27053"

}

]

}

> rs.initiate(config)

{

"ok" : 1,

"operationTime" : Timestamp(1531101753, 1),

"$clusterTime" : {

"clusterTime" : Timestamp(1531101753, 1),

"signature" : {

"hash" : BinData(0,"AAAAAAAAAAAAAAAAAAAAAAAAAAA="),

"keyId" : NumberLong(0)

}

}

}

rs1:SECONDARY> rs.isMaster()

{

"hosts" : [

"192.168.4.51:27051",

"192.168.4.52:27052",

"192.168.4.53:27053"

],

"setName" : "rs1",

"setVersion" : 1,

"ismaster" : true,

"secondary" : false,

"primary" : "192.168.4.51:27051",

"me" : "192.168.4.51:27051",

"electionId" : ObjectId("7fffffff0000000000000001"),

"lastWrite" : {

"opTime" : {

"ts" : Timestamp(1531101769, 1),

"t" : NumberLong(1)

},

"lastWriteDate" : ISODate("2018-07-09T02:02:49Z"),

"majorityOpTime" : {

"ts" : Timestamp(1531101769, 1),

"t" : NumberLong(1)

},

"majorityWriteDate" : ISODate("2018-07-09T02:02:49Z")

},

"maxBsonObjectSize" : 16777216,

"maxMessageSizeBytes" : 48000000,

"maxWriteBatchSize" : 100000,

"localTime" : ISODate("2018-07-09T02:03:00.159Z"),

"logicalSessionTimeoutMinutes" : 30,

"minWireVersion" : 0,

"maxWireVersion" : 6,

"readOnly" : false,

"ok" : 1,

"operationTime" : Timestamp(1531101769, 1),

"$clusterTime" : {

"clusterTime" : Timestamp(1531101769, 1),

"signature" : {

"hash" : BinData(0,"AAAAAAAAAAAAAAAAAAAAAAAAAAA="),

"keyId" : NumberLong(0)

}

}

}

rs1:PRIMARY> rs.isMaster()

{

"hosts" : [

"192.168.4.51:27051",

"192.168.4.52:27052",

"192.168.4.53:27053"

],

"setName" : "rs1",

"setVersion" : 1,

"ismaster" : true,

"secondary" : false,

"primary" : "192.168.4.51:27051",

"me" : "192.168.4.51:27051",

"electionId" : ObjectId("7fffffff0000000000000001"),

"lastWrite" : {

"opTime" : {

"ts" : Timestamp(1531101836, 1),

"t" : NumberLong(1)

},

"lastWriteDate" : ISODate("2018-07-09T02:03:56Z"),

"majorityOpTime" : {

"ts" : Timestamp(1531101836, 1),

"t" : NumberLong(1)

},

"majorityWriteDate" : ISODate("2018-07-09T02:03:56Z")

},

"maxBsonObjectSize" : 16777216,

"maxMessageSizeBytes" : 48000000,

"maxWriteBatchSize" : 100000,

"localTime" : ISODate("2018-07-09T02:03:57.856Z"),

"logicalSessionTimeoutMinutes" : 30,

"minWireVersion" : 0,

"maxWireVersion" : 6,

"readOnly" : false,

"ok" : 1,

"operationTime" : Timestamp(1531101836, 1),

"$clusterTime" : {

"clusterTime" : Timestamp(1531101836, 1),

"signature" : {

"hash" : BinData(0,"AAAAAAAAAAAAAAAAAAAAAAAAAAA="),

"keyId" : NumberLong(0)

}

}

}

rs1:PRIMARY> exit

bye

[root@host52 ~]# ss -tunlp | grep mongo

tcp    LISTEN     0      128    192.168.4.52:27052                 *:*                   users:(("mongod",pid=2152,fd=11))

检测

[root@host50 ~]# mongo --host 192.168.4.51  --port 27051
MongoDB shell version v3.6.3

connecting to: mongodb://192.168.4.51:27051/

rs1:PRIMARY> show dbs
admin   0.000GB
config  0.000GB
local   0.000GB
rs1:PRIMARY> db
test
rs1:PRIMARY> use gamedb
switched to db gamedb
rs1:PRIMARY> db.c1.save({name:"test",age:19})
WriteResult({ "nInserted" : 1 })

rs1:PRIMARY> 


默认从库不能执行show dbs要加入db.getMongo().setSlaveOk()

[root@host52 ~]# mongo --host 192.168.4.52 --port 27052
MongoDB shell version v3.6.3
connecting to: mongodb://192.168.4.52:27052/
MongoDB server version: 3.6.3
Server has startup warnings: 
2018-07-09T10:02:08.812+0800 I CONTROL  [initandlisten] 
2018-07-09T10:02:08.812+0800 I CONTROL  [initandlisten] ** WARNING: Access control is not enabled for the database.
2018-07-09T10:02:08.812+0800 I CONTROL  [initandlisten] **          Read and write access to data and configuration is unrestricted.
2018-07-09T10:02:08.812+0800 I CONTROL  [initandlisten] ** WARNING: You are running this process as the root user, which is not recommended.
2018-07-09T10:02:08.812+0800 I CONTROL  [initandlisten] 
2018-07-09T10:02:08.813+0800 I CONTROL  [initandlisten] 
2018-07-09T10:02:08.813+0800 I CONTROL  [initandlisten] ** WARNING: /sys/kernel/mm/transparent_hugepage/enabled is 'always'.
2018-07-09T10:02:08.813+0800 I CONTROL  [initandlisten] **        We suggest setting it to 'never'
2018-07-09T10:02:08.813+0800 I CONTROL  [initandlisten] 
2018-07-09T10:02:08.813+0800 I CONTROL  [initandlisten] ** WARNING: /sys/kernel/mm/transparent_hugepage/defrag is 'always'.
2018-07-09T10:02:08.813+0800 I CONTROL  [initandlisten] **        We suggest setting it to 'never'
2018-07-09T10:02:08.813+0800 I CONTROL  [initandlisten] 
rs1:SECONDARY> show dbs
2018-07-09T10:33:13.914+0800 E QUERY    [thread1] Error: listDatabases failed:{
"operationTime" : Timestamp(1531103586, 1),
"ok" : 0,
"errmsg" : "not master and slaveOk=false",
"code" : 13435,
"codeName" : "NotMasterNoSlaveOk",
"$clusterTime" : {
"clusterTime" : Timestamp(1531103586, 1),
"signature" : {
"hash" : BinData(0,"AAAAAAAAAAAAAAAAAAAAAAAAAAA="),
"keyId" : NumberLong(0)
}
}
} :
_getErrorWithCode@src/mongo/shell/utils.js:25:13
Mongo.prototype.getDBs@src/mongo/shell/mongo.js:65:1
shellHelper.show@src/mongo/shell/utils.js:816:19
shellHelper@src/mongo/shell/utils.js:706:15
@(shellhelp2):1:1
rs1:SECONDARY> db.g
db.getCollection(          db.getLogComponents(       db.getQueryOptions(        db.getSisterDB(            db.grantRolesToRole(
db.getCollectionInfos(     db.getMongo(               db.getReplicationInfo(     db.getSlaveOk(             db.grantRolesToUser(
db.getCollectionNames(     db.getName(                db.getRole(                db.getUser(                db.group(
db.getLastError(           db.getPrevError(           db.getRoles(               db.getUsers(               db.groupcmd(
db.getLastErrorCmd(        db.getProfilingLevel(      db.getSession(             db.getWriteConcern(        db.groupeval(
db.getLastErrorObj(        db.getProfilingStatus(     db.getSiblingDB(           db.grantPrivilegesToRole(
rs1:SECONDARY> db.getMongo(
Display all 175 possibilities? (y or n)
rs1:SECONDARY> db.getMongo().setSlaveOk()
rs1:SECONDARY> show dbs
admin   0.000GB
config  0.000GB
gamedb  0.000GB
local   0.000GB
rs1:SECONDARY> use gamedb
switched to db gamedb
rs1:SECONDARY> db.c1.find()
{ "_id" : ObjectId("5b42c9103da3f658581eb6b5"), "name" : "test", "age" : 19 }

rs1:SECONDARY> 



删除配置文件中的集群配置重启服务

dbpath=/usr/local/mongodb/data/db
fork=true
logpath=/usr/local/mongodb/log/mongodb.log
logappend=true
bind_ip=192.168.4.53
port=27053

#replSet=rs1   //#

[root@host53 ~]# mongod --shutdown -f /usr/local/mongodb/etc/mongodb.conf
killing process with pid: 2094
[root@host53 ~]# mongod -f /usr/local/mongodb/etc/mongodb.conf
about to fork child process, waiting until server is ready for connections.
forked process: 2926
child process started successfully, parent exiting
[root@host53 ~]# 

猜你喜欢

转载自blog.csdn.net/weixin_40018205/article/details/80966203