MongoDB 主从同步设置
关于MongoDB的安装及启动参数说明可以参考我之前转载的与
主从设置
Master: 192.168.111.103 Port:8001
Slave:192.168.111.104 Port:8001
启动Master
mongod --dbpath /data/masterdb/ --master --oplogSize 64 --port 8001 --fork --logpath /var/logs/mongodb/mongod.log启动Slave
mongod --dbpath /data/slavedb/ --slave --source 192.168.111.103:8001 --oplogSize 64 --port 8001 --fork --logpath /var/logs/mongodb/mongod.log查看Slave log可以见到已经从Master复制数据
tail -f /var/logs/mongodb/mongod.logThu Feb 27 22:18:20 repl: main@192.168.111.103:8001Thu Feb 27 22:18:20 repl: sleep 2sec before next passThu Feb 27 22:18:22 repl: main@192.168.111.103:8001Thu Feb 27 22:18:22 repl: sleep 2sec before next passThu Feb 27 22:18:24 repl: main@192.168.111.103:8001Thu Feb 27 22:18:24 repl: sleep 2sec before next passThu Feb 27 22:18:26 repl: main@192.168.111.103:8001Thu Feb 27 22:18:26 repl: sleep 2sec before next passThu Feb 27 22:18:28 repl: main@192.168.111.103:8001Thu Feb 27 22:18:28 repl: sleep 2sec before next passThu Feb 27 22:18:30 repl: main@192.168.111.103:8001Thu Feb 27 22:18:30 repl: sleep 2sec before next passThu Feb 27 22:18:32 repl: main@192.168.111.103:8001Thu Feb 27 22:18:32 repl: sleep 2sec before next pass停用MongoDB
mongo -port 8001use admindb.shutdownServer()exit修复MongoDB
mongod --dbpath /data/masterdb/ repairmongod --dbpath /data/slavedb/ repair