---恢复内容开始---mongodb
也是闲的蛋疼,原本用27017/27018/27019三个端口启动了Replica Set,但是回头一想,这个和默认端口重了,仍是改为别的吧。因而想改为40001/40002/40003,折腾一圈发现仍是得看官方文档,就顺便在这里作个记录吧shell
先祭出官方连接数据库
操做步骤:ui
1. 中止全部复制集中的实例blog
2. 使用其余端口,去掉--replSet选项,启动mongo实例。--dbpath仍然使用以前的设置ip
更改端口是为了不在变动期间有客户端链接进来文档
mongod --port 37017 --bind_ip localhost --dbpath /data/mongodb/rs0-0 --smallfiles --oplogSize 128
mongod --port 37018 --bind_ip localhost --dbpath /data/mongodb/rs0-1 --smallfiles --oplogSize 128
mongod --port 37019 --bind_ip localhost --dbpath /data/mongodb/rs0-2 --smallfiles --oplogSize 128
3. 启动mongo shell链接到新端口get
mongo --port 37017
4. 修改replica set的配置。配置信息保存在local数据库的system.replset数据集中,这个配置也是system.replset数据集中惟一的一份文档。将replica set的配置修改成新的hostname和port。我用了3个实例作集群,因此须要指定3个host信息it
use local
cfg = db.system.replset.findOne({ "_id": "rs0" })
cfg.members[0].host = "localhost:40001"
cfg.members[1].host = "localhost:40002"
cfg.members[2].host = "localhost:40003"
db.system.replset.update( { "_id": "rs0" } , cfg )
5. 重复步骤3-4,分别使用37018/37019修改另外两个实例的配置
6. 中止全部的mongo实例
7. 使用新的端口启动mongo集群的实例,须要指定--replSet选项
mongod --replSet rs0 --port 40001 --bind_ip localhost --dbpath /data/mongodb/rs0-0 --smallfiles --oplogSize 128
mongod --replSet rs0 --port 40002 --bind_ip localhost --dbpath /data/mongodb/rs0-1 --smallfiles --oplogSize 128
mongod --replSet rs0 --port 40003 --bind_ip localhost --dbpath /data/mongodb/rs0-2 --smallfiles --oplogSize 128
8. 启动mongo shell链接到新端口
mongo --port 40001
9. rs.conf()查看目前的配置
rs0:PRIMARY> rs.conf()
{
"_id" : "rs0",
"version" : 1,
"protocolVersion" : NumberLong(1),
"writeConcernMajorityJournalDefault" : true,
"members" : [
{
"_id" : 0,
"host" : "localhost:40001",
"arbiterOnly" : false,
"buildIndexes" : true,
"hidden" : false,
"priority" : 1,
"tags" : {
},
"slaveDelay" : NumberLong(0),
"votes" : 1
},
{
"_id" : 1,
"host" : "localhost:40002",
"arbiterOnly" : false,
"buildIndexes" : true,
"hidden" : false,
"priority" : 1,
"tags" : {
},
"slaveDelay" : NumberLong(0),
"votes" : 1
},
{
"_id" : 2,
"host" : "localhost:40003",
"arbiterOnly" : false,
"buildIndexes" : true,
"hidden" : false,
"priority" : 1,
"tags" : {
},
"slaveDelay" : NumberLong(0),
"votes" : 1
}
],
"settings" : {
"chainingAllowed" : true,
"heartbeatIntervalMillis" : 2000,
"heartbeatTimeoutSecs" : 10,
"electionTimeoutMillis" : 10000,
"catchUpTimeoutMillis" : -1,
"catchUpTakeoverDelayMillis" : 30000,
"getLastErrorModes" : {
},
"getLastErrorDefaults" : {
"w" : 1,
"wtimeout" : 0
},
"replicaSetId" : ObjectId("5cedfa4e7be20c6138e87316")
}
}
搞定