Operating System: CentOS 7.0 64-bit
MongoDB database version:mongodb-linux-x86_64-2.6.5
preparatory work: MongoDB Database Installation
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
oplogsize=2048 #同步复制的日志大小设置, per MB
After adding it, the following figure shows:
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
source=192.168.21.100:27017 #设置要同步的MongoDB主库IP地址和端口, format: IP: Port
slavedelay=10 #设置从库同步主库的延迟时间, unit seconds
Autoresync=true #主从数据不一致时, automatic resynchronization
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
Use test #创建数据库test Note that if nothing is done, the library will be deleted by the system .
Db.createcollection ("test_table") #创建表test_table
Db.test_table.insert ({uid:1,name: "System Operation Dimension", URL: "http://www.osyunwi.com", Content: "System Operation Dimension Official website"}) #插入数据到表osyunweidb_ Table in
Show DBS #如下图所示, you can see that the test database has been created
2, the operation from the library
Show DBS #如下图所示, you can see that the test database is already available from the library , master-slave sync has run successfully
At this point, Linux under the MongoDB database master-Slave synchronization configuration completed.