mongodb配置「主從」模式

版本的mongodb不支持Master/slave模式了。推薦使用集羣模式。
你們都知道,集羣模式須要多於三臺的奇數臺機器(奇數個進程測試有意義,實際意義不大)
如今個人手頭有兩臺主機,更合理的配置我的以爲是「主從」。
看了看mongodb的官方文檔,找到了一個好思路:
mongodb容許增長arbiter(仲裁員),這個角色不用寫數據。只是投票用。這樣兩臺機器就能夠合理的使用資源了。mongodb

1、典型的配置文件以下圖:測試

# 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

2、添加集羣節點方式一spa

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)code

3、添加集羣節點方式二blog

1. use admin
2. rs.add("127.0.0.1:27010")//常規讀寫節點
3. rs.addArb("127.0.0.1:27011")//投票節點進程

相關文章
相關標籤/搜索