Description:
There are two installed MongoDB database server, now need to set a main library, another set to from the library, to achieve master-slave synchronization.
Operating System: CentOS 7.0 64-bit
MongoDB database version:mongodb-linux-x86_64-2.6.5
preparatory work: MongoDB Database Installation
Please refer to: Linux installation configuration MongoDB database
Http://www.osyunwei.com/archives/7629.html
Specific actions:
First, configure the MongoDB main Library
The following actions are performed on the MongoDB main library server
1, cd/usr/local/mongodb/#进入MongoDB安装目录
Vi/usr/local/mongodb/mongodb.conf #编辑, add the following code on the last line of the original configuration file
Master=true #设置为主库
oplogsize=2048 #同步复制的日志大小设置, per mb
: wq! #保存退出
After adding it, the following figure shows:
System Yun-wei www.osyunwei.com warm reminder: qihang01 original Content © Copyright, reproduced please indicate the source and the original chain
2, restart the MongoDB database
Service Mongod Stop #停止MongoDB
Service Mongod Start #启动MongoDB
Second, configure MongoDB from the library
The following actions are performed on the MongoDB from the library server
1, cd/usr/local/mongodb/#进入MongoDB安装目录
Vi/usr/local/mongodb/mongodb.conf #编辑, add the following code on the last line of the original configuration file
Slave=true #设置为从库
source=192.168.21.100:27017 #设置要同步的MongoDB主库IP地址和端口, Format: IP: Port
slavedelay=10 #设置从库同步主库的延迟时间, Unit seconds
Autoresync=true #主从数据不一致时, Automatic resynchronization
: wq! #保存退出
After adding it, the following figure shows:
System Yun-wei www.osyunwei.com warm reminder: qihang01 original Content © Copyright, reproduced please indicate the source and the original chain
2, restart the MongoDB database
Service Mongod Stop #停止MongoDB
Service Mongod Start #启动MongoDB
Third, test MongoDB master and slave synchronization
1, in the main library to operate
MONGO #进入MongoDB控制台
Use test #创建数据库test Note that if nothing is done, the library will be deleted by the system.
Db.createcollection ("test_table") #创建表test_table
Show Collections #查看
Db.test_table.insert ({uid:1,name: "System Operation Dimension", URL: "http://www.osyunwi.com", Content: "System Operation Dimension Official website"}) #插入数据到表osyunweidb_ Table in
Db.osyunweidb.find ();
Show DBS #如下图所示, you can see that the test database has been created
Exit #退出
2, the operation from the library
MONGO #进入MongoDB控制台
Show DBS #如下图所示, you can see that the test database is already available from the library, master-slave sync has run successfully
Exit #退出
at this point, Linux MongoDB database master-Slave synchronization configuration is complete.