MongoDB 主从同步设置

MongoDB 主从同步设置

关于MongoDB的安装及启动参数说明可以参考我之前转载的《Ubuntu安装MongoDB》《Mongodb启动命令mongod参数说明》


主从设置

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.log
Thu Feb 27 22:18:20 repl: main@192.168.111.103:8001
Thu Feb 27 22:18:20 repl: sleep 2sec before next pass
Thu Feb 27 22:18:22 repl: main@192.168.111.103:8001
Thu Feb 27 22:18:22 repl: sleep 2sec before next pass
Thu Feb 27 22:18:24 repl: main@192.168.111.103:8001
Thu Feb 27 22:18:24 repl: sleep 2sec before next pass
Thu Feb 27 22:18:26 repl: main@192.168.111.103:8001
Thu Feb 27 22:18:26 repl: sleep 2sec before next pass
Thu Feb 27 22:18:28 repl: main@192.168.111.103:8001
Thu Feb 27 22:18:28 repl: sleep 2sec before next pass
Thu Feb 27 22:18:30 repl: main@192.168.111.103:8001
Thu Feb 27 22:18:30 repl: sleep 2sec before next pass
Thu Feb 27 22:18:32 repl: main@192.168.111.103:8001
Thu Feb 27 22:18:32 repl: sleep 2sec before next pass

停用MongoDB

mongo -port 8001
use admin
db.shutdownServer()
exit

修复MongoDB

mongod --dbpath /data/masterdb/ repair
mongod --dbpath /data/slavedb/ repair


posted @ 2014-02-27 22:26  傲雪星枫  阅读(715)  评论(0编辑  收藏  举报