MongoDB 主从复制 Replication
很多教程上面采用手工配置主从复制,我不建议你这样启动,请采用修改/etc/mongod.conf配置文件的方案。
创建主: mongod –port 27017 –dbpath /var/lib/mongodb –master 创建从: mongod –port 27017 –dbpath /var/lib/mongodb –slave –source master_ip_address:27017
Master
sed -i "s/#master = true/master = true/" /etc/mongod.conf systemctl restart mongod
Slave
sed -i "s/#slave = true/slave = true/" /etc/mongod.conf sed -i "s/#source = arg/source = mongodb.master.example.com/" /etc/mongod.conf systemctl restart mongod
测试
进入 Master
[root@localhost ~]# mongo MongoDB shell version: 2.6.11 connecting to: test Welcome to the MongoDB shell. For interactive help, type "help". For more comprehensive documentation, see http://docs.mongodb.org/ Questions? Try the sup