RS集群中mongod的安装和单机一样,只是配置文件略有不同,
单机安装路径linux 下mongodb 3.2.5安装
下面是rs集群的配置文件:
systemLog:
destination: file
path: /home/mongodb/log1/mongod.log ##log的路径
logAppend: true
storage:
journal:
enabled: true
dbPath: /home/mongodb/data ##数据的路径
directoryPerDB: true
engine: wiredTiger
wiredTiger:
engineConfig:
cacheSizeGB: 6 ##这个值根据自己的机器的内存进行修改
directoryForIndexes: true
collectionConfig:
blockCompressor: zlib
indexConfig:
prefixCompression: true
replication:
oplogSizeMB: 10000
replSetName: luo
net:
port: 27018 ##根据自己的需要进行修改
配置文件的样板我在\\10.10.10.1\ShareDoc\User\luozhitao\replica set放了一份,拷过去修改下路径和replSetName即可
在三台机器上分别启动mongod实例以后,来配置replica set,选择任意一台机器
./mongo 10.10.5.248:27018 登陆后
> use admin
switched to db admin
> cfg3 = { _id:"luo", members:[
{_id:0,host:"10.10.7.33:27019",priority:1000},
{_id:1,host:"10.10.5.248:27018",priority:999},
{_id:2,host:"10.10.5.248:27017",priority : 800, arbiterOnly: true}
]
}
> rs.initiate(cfg3)
按enter直到出现
luo:PRIMARY>
luo:PRIMARY> rs.status()
{
"set" : "luo",
"date" : ISODate("2016-04-26T07:48:53.958Z"),
"myState" : 1,
"term" : NumberLong(1),
"heartbeatIntervalMillis" : NumberLong(2000),
"members" : [
{
"_id" : 0,
"name" : "10.10.7.33:27019",
"health" : 1,
"state" : 1,
"stateStr" : "PRIMARY",
"uptime" : 753,
"optime" : {
"ts" : Timestamp(1461656928, 1),
"t" : NumberLong(1)
},
"optimeDate" : ISODate("2016-04-26T07:48:48Z"),
"infoMessage" : "could not find member to sync from",
"electionTime" : Timestamp(1461656927, 1),
"electionDate" : ISODate("2016-04-26T07:48:47Z"),
"configVersion" : 1,
"self" : true
},
{
"_id" : 1,
"name" : "10.10.5.248:27018",
"health" : 1,
"state" : 2,
"stateStr" : "SECONDARY",
"uptime" : 17,
"optime" : {
"ts" : Timestamp(1461656928, 1),
"t" : NumberLong(1)
},
"optimeDate" : ISODate("2016-04-26T07:48:48Z"),
"lastHeartbeat" : ISODate("2016-04-26T07:48:53.377Z"),
"lastHeartbeatRecv" : ISODate("2016-04-26T07:48:49.622Z"),
"pingMs" : NumberLong(1),
"syncingTo" : "10.10.7.33:27019",
"configVersion" : 1
},
{
"_id" : 2,
"name" : "10.10.5.248:27017",
"health" : 1,
"state" : 7,
"stateStr" : "ARBITER",
"uptime" : 17,
"lastHeartbeat" : ISODate("2016-04-26T07:48:53.377Z"),
"lastHeartbeatRecv" : ISODate("2016-04-26T07:48:52.642Z"),
"pingMs" : NumberLong(0),
"configVersion" : 1
}
],
"ok" : 1
}
安装成功