mongodb配置“主從”模式


版本的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")//投票節點

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM