在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
主从配置 openssl rand -base64 741 > mongo_key 将mongo_key 分别置于master 和 slave mongodb user可以access的地方。 chmod 700 mongo_key 设置 onwer chown mongodb:nogroup mongo_key 2.master配置 master = true keyFile = /path/to/mongo_key 3.slave 配置 slave = true source = <ip of master> only = bookstore keyFile = /usr/local/bookstore/mongo_key 如果只同步一个db,配置only项,如果多个DB需同步,注释掉only项。 use admin db.runCommand( { resync: 1 } ) 如果数据落后较多,则需要较长时间。 主从同步要点解析 首先要在master的local数据库中创建名为repl的账户,并设置密码; > use admin switched to db admin > db.addUser("root","zhuima") WARNING: The 'addUser' shell helper is DEPRECATED. Please use 'createUser' instead Successfully added user: { "user" : "root", "roles" : [ "root" ] } 2.分别在master/slave的local数据库下创建一个名为repl的账户,并设置密码相同 > use local switched to db local > db.addUser("repl","zhuima") WARNING: The 'addUser' shell helper is DEPRECATED. Please use 'createUser' instead Successfully added user: { "user" : "repl", "roles" : [ "dbOwner" ] } 3.master配置文件 [root@redis ~]# sed -e '/^$/d;/^#/d' /etc/mongodb.conf bind_ip = 192.168.58.30 port = 27017 fork = true pidfilepath = /var/run/mongodb/mongodb.pid logpath = /var/log/mongodb/mongodb.log dbpath =/mydata/data journal = true auth = true# 开启认证模式 master = true # 指定该mongodb为master模式 4.slave配置文件 [root@localhost ~]$ sed -e '/^$/d;/^#/d' /etc/mongodb.conf bind_ip = 192.168.58.10 port = 27017 fork = true pidfilepath = /var/run/mongodb/mongodb.pid logpath = /var/log/mongodb/mongodb.log dbpath = /mydata/data journal = true auth = true # 开启认证模式 slave = true # 指定该mongodb为slave模式 source = 192.168.58.30:27017 # 指定master服务器 5.检查同步情况 > db.printReplicationInfo() this is a slave, printing slave replication info. source: 192.168.58.30:27017 syncedTo: Fri Jul 18 2014 10:22:31 GMT+0200 (CEST) = 22 secs ago (0.01hrs) # 这个是指延迟时长 |
请发表评论