mongodb 互为主从
一台window 然后和虚拟机linux 两个mongodb 设置为主从
1 linux上 mongodb安装后
常用启动 方式:
可以把参数放在mongod.conf文件中 如下:
启动方式为:
linux 上配置就如上所示。
2 window7 上配置如:
- port=27017
- dbpath=D:\mongodbdata\data1
- logpath=D:\mongodbdata\config\mongodb2.log
- #fork =true #后台运行
- master=true
- slave =true
- source =192.168.204.171:27017
- slavedelay=10 #设置从库同步主库的延迟时间,单位为秒
- autoresync=true #主从数据不一致时,自动重新同步
启动方式如下:
测试效果如图:
右边window7,左面linux。
中间遇到问题:
没有同步,log中打印 数据太过陈旧
repl: data too stale, halting replication
解决办法:
autoresync=true
配置中加上这句。