生活随笔
收集整理的這篇文章主要介紹了
MongoDB replSet
小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
2019獨(dú)角獸企業(yè)重金招聘Python工程師標(biāo)準(zhǔn)>>>
http://cn.docs.mongodb.org/manual/tutorial/convert-secondary-into-arbiter/
http://api.mongodb.org/wiki/current/Replica%20Set%20Tutorial.html
http://cn.docs.mongodb.org/manual/core/replication/
還是看官方文檔吧!
新建目錄
# mkdir -p /data/rs0 /data/rs1 /data/rs2啟動(dòng)mongod replSet
# ./bin/mongod --port 11100 --dbpath /data/rs0 --replSet fish --smallfiles
# ./bin/mongod --port 11101 --dbpath /data/rs1 --replSet fish --smallfiles
# ./bin/mongod --port 11102 --dbpath /data/rs2 --replSet fish --smallfilesmongod replSet 報(bào)錯(cuò)
Fri Nov 30 16:07:27 [rsStart] warning: getaddrinfo("lenovo11") failed: Name or service not known
Fri Nov 30 16:07:27 [rsStart] getaddrinfo("lenovo11") failed: Name or service not known
Fri Nov 30 16:07:27 [rsStart] trying to contact lenovo11:11100
Fri Nov 30 16:07:27 [rsStart] getaddrinfo("lenovo11") failed: Name or service not known
Fri Nov 30 16:07:27 [rsStart] couldn't connect to lenovo11:11100: couldn't connect to server lenovo11:11100
Fri Nov 30 16:07:27 [rsStart] getaddrinfo("lenovo11") failed: Name or service not known
Fri Nov 30 16:07:27 [rsStart] replSet can't get local.system.replset config from self or any seed (yet)# /usr/local/mongodb/bin/mongo localhost:11100
> config = { _id: 'fish' ,members: [{_id:0,host:"127.0.0.1:11100"},{_id:1,host:"127.0.0.1:11101"},{_id:2,host:"127.0.0.1:11102}]}
> rs.initiate(config)
{"startupStatus" : 4,"info" : "fish","errmsg" : "all members and seeds must be reachable to initiate set", "ok" : 0
}
> rs.status()
{"startupStatus" : 4,"errmsg" : "can't currently get local.system.replset config from self or any seed (EMPTYUNREACHABLE)","ok" : 0
}
> rs.conf()
null
> db.getReplicationInfo()
{ "errmsg" : "neither master/slave nor replica set replication detected" }***************************************** 解決 **********************************************
問(wèn)了公司一個(gè)高手,雖然有點(diǎn)不屑這種小問(wèn)題,不過(guò)還是指出問(wèn)題所在。
“這就是DNS的問(wèn)題,它找不到“l(fā)enovo11”這個(gè)機(jī)器對(duì)應(yīng)的ip?!? ---> 原來(lái)是mongodb不能解析lenovo11.在/etc/hosts 添加一行:
127.0.0.1 lenovo11[root@lenovo11 mongodb]# ./bin/mongo localhost:11100
MongoDB shell version: 2.2.1
connecting to: localhost:11100/test
> config = { _id:'fish',members:[ {_id:0,host:'localhost:11100'}, {_id:1,host:'localhost:11101'}, {_id:2,host:'localhost:11102'}]}
{"_id" : "fish","members" : [{"_id" : 0,"host" : "localhost:11100"},{"_id" : 1,"host" : "localhost:11101"},{"_id" : 2,"host" : "localhost:11102"}]
}
> rs.initiate(config)
{"info" : "Config now saved locally. Should come online in about a minute.","ok" : 1
}
> rs.status()
{"set" : "fish","date" : ISODate("2012-11-30T09:41:51Z"),"myState" : 1,"members" : [{"_id" : 0,"name" : "localhost:11100","health" : 1,"state" : 1,"stateStr" : "PRIMARY","uptime" : 172,"optime" : Timestamp(1354268446000, 1),"optimeDate" : ISODate("2012-11-30T09:40:46Z"),"self" : true},{"_id" : 1,"name" : "localhost:11101","health" : 1,"state" : 2,"stateStr" : "SECONDARY","uptime" : 55,"optime" : Timestamp(1354268446000, 1),"optimeDate" : ISODate("2012-11-30T09:40:46Z"),"lastHeartbeat" : ISODate("2012-11-30T09:41:50Z"),"pingMs" : 1,"errmsg" : "syncing to: localhost:11100"},{"_id" : 2,"name" : "localhost:11102","health" : 1,"state" : 3,"stateStr" : "RECOVERING","uptime" : 55,"optime" : Timestamp(0, 0),"optimeDate" : ISODate("1970-01-01T00:00:00Z"),"lastHeartbeat" : ISODate("2012-11-30T09:41:49Z"),"pingMs" : 207}],"ok" : 1
}
fish:PRIMARY> rs.conf
rs.conf( rs.config(
fish:PRIMARY> rs.conf()
{"_id" : "fish","version" : 1,"members" : [{"_id" : 0,"host" : "localhost:11100"},{"_id" : 1,"host" : "localhost:11101"},{"_id" : 2,"host" : "localhost:11102"}]
}
fish:PRIMARY> rs.
rs.add( rs.constructor rs.isMaster( rs.status(
rs.addArb( rs.debug rs.propertyIsEnumerable( rs.stepDown(
rs.apply( rs.freeze( rs.prototype rs.syncFrom(
rs.call( rs.hasOwnProperty( rs.reconfig( rs.toLocaleString(
rs.conf( rs.help( rs.remove( rs.toString(
rs.config( rs.initiate( rs.slaveOk( rs.valueOf(
fish:PRIMARY> rs.isMaster()
{"setName" : "fish","ismaster" : true,"secondary" : false,"hosts" : ["localhost:11100","localhost:11102","localhost:11101"],"primary" : "localhost:11100","me" : "localhost:11100","maxBsonObjectSize" : 16777216,"localTime" : ISODate("2012-11-30T09:45:59.351Z"),"ok" : 1
}
轉(zhuǎn)載于:https://my.oschina.net/shineyyl/blog/92973
總結(jié)
以上是生活随笔為你收集整理的MongoDB replSet的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
如果覺(jué)得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。