mongodb 副本集失败
两台电脑做测试
zhf-linux:192.168.0.11
zhf-maple:192.168.0.12
在192.168.0.12上启动
启动命令:mongod --dbpath /home/zhf/node0 --replSet rs0
在192.168.0.11上启动
启动命令:mongod --dbpath /home/zhf/node1 --replSet rs0
在192.168.0.12上进入数据库,执行如下命令
> use admin
switched to db admin
> conf={_id:"rs0",members:[{_id:0,host:"zhf-maple:27017"},{_id:1,host:"zhf-linux:27017"}]}
{
"_id" : "rs0",
"members" : [
{
"_id" : 0,
"host" : "zhf-maple:27017"
},
{
"_id" : 1,
"host" : "zhf-linux:27017"
}
]
}
> rs.initiate(conf)
{ "ok" : 1 }
rs0:SECONDARY> rs.conf()
{
"_id" : "rs0",
"version" : 1,
"protocolVersion" : NumberLong(1),
"members" : [
{
"_id" : 0,
"host" : "zhf-maple:27017",
"arbiterOnly" : false,
"buildIndexes" : true,
"hidden" : false,
"priority" : 1,
"tags" : {
},
"slaveDelay" : NumberLong(0),
"votes" : 1
},
{
"_id" : 1,
"host" : "zhf-linux:27017",
"arbiterOnly" : false,
"buildIndexes" : true,
"hidden" : false,
"priority" : 1,
"tags" : {
},
"slaveDelay" : NumberLong(0),
"votes" : 1
}
],
"settings" : {
"chainingAllowed" : true,
"heartbeatIntervalMillis" : 2000,
"heartbeatTimeoutSecs" : 10,
"electionTimeoutMillis" : 10000,
"catchUpTimeoutMillis" : 60000,
"getLastErrorModes" : {
},
"getLastErrorDefaults" : {
"w" : 1,
"wtimeout" : 0
},
"replicaSetId" : ObjectId("5a5b4512be0049ae009cd493")
}
}
但是一直无法同步:提示如下消息
2018-01-14T19:56:44.394+0800 I REPL [rsBackgroundSync] waiting for 2 pings from other members before syncing
2018-01-14T19:56:44.827+0800 I REPL [ReplicationExecutor] Not starting an election, since we are not electable due to: Not standing for election because I cannot see a majority (mask 0x1)
2018-01-14T19:56:45.415+0800 I REPL [ReplicationExecutor] Error in heartbeat request to zhf-linux:27017; Location13111: exception: field not found, expected type 16
2018-01-14T19:56:45.428+0800 I REPL [ReplicationExecutor] Error in heartbeat request to zhf-linux:27017; Location13111: exception: field not found, expected type 16
2018-01-14T19:56:45.438+0800 I REPL [ReplicationExecutor] Error in heartbeat request to zhf-linux:27017; Location13111: exception: field not found, expected type 16