版本的mongodb不支持Master/slave模式了。推荐使用集群模式。
大家都知道,集群模式需要多于三台的奇数台机器(奇数个进程测试有意义,实际意义不大)
现在我的手头有两台主机,更合理的配置个人觉得是“主从”。
看了看mongodb的官方文档,找到了一个好思路:
mongodb允许增加arbiter(仲裁人),这个角色不用写数据。只是投票用。这样两台机器就可以合理的使用资源了。
一、典型的配置文件如下图:
# where to write logging data. systemLog: destination: file logAppend: true path: /home/mongo/mongo.log # Where and how to store data. storage: dbPath: /home/mongo/data journal: enabled: true # how the process runs processManagement: fork: true # fork and run in background pidFilePath: /home/mongo/run/mongod.pid # location of pidfile timeZoneInfo: /usr/share/zoneinfo # network interfaces net: port: 27017 bindIp: 0.0.0.0 # Enter 0.0.0.0,:: to bind to all IPv4 and IPv6 addresses or, alternatively, use the net.bindIpAll setting. replication: replSetName: sanro
二、添加集群节点方式一
1. use admin
2. config={_id:"sanros",members:[{_id:0,host:"10.47.156.246:27017"},{_id:1,host:"10.47.156.246:27018"},{_id:2,host:"10.47.156.246:27019"}]}//常规读写节点
2. config={_id:"sanros",members:[{_id:0,host:"192.168.183.128:27017"},{_id:1,host:"192.168.183.128:27018"},{_id:2,host:"192.168.183.128:27019",arbiterOnly:true}]}//投票节点
3. rs.initiate(config)
三、添加集群节点方式二
1. use admin
2. rs.add("127.0.0.1:27010")//常规读写节点
3. rs.addArb("127.0.0.1:27011")//投票节点
原文:https://www.cnblogs.com/yoyotl/p/11300016.html