Original link: http://www.cnblogs.com/huangxincheng/archive/2012/03/04/2379755.html
This machine installs MongoDB not to introduce, this article MONGO small rookie to learn native practice. Gossip less, the book belongs to the story.
- Simulates a multi-machine operating environment. (only in this machine, does not mean that multiple machines must be successful)
- Start each MongoDB service and configure the master-slave server
- Primary server inserting data
- Querying from server data
The first step: simulate the multi-machine operating environment, where Servermain is the primary database, and the other is from the database. Direct
Step two: Start each MongoDB service and configure the master-slave server. Switch to each database folder, the primary service start command is Mongod--dbpath=f:\mongodb_servermain--master, the default port number is 27017. Start from the server in turn, and configure the primary service to 127.0.0.1:27017,server1 Start command for Mongod--dbpath=f:\mongodb_serverother1--port 1111--slave--source The 127.0.0.1:27017,server2 Start command is: Mongod--dbpath=f:\mongodb_serverother2--port 2222--slave--source 127.0.0.1:27017.
The above two graphs are from databases 1 and 2, which can be seen every 10 seconds from the primary database synchronized sequentially data. Syncing from host 127.0.0.1:27017
Step three: The primary server inserts data. Also open a window, navigate to the main database folder under Bin. Execute command MONGO here we directly default test database, and then insert a few data, Db.friend.insert ({"Name": "Test", "from": "Main"}), the figure is as follows
Fourth step: Query the data from the database. According to the method of the third step, open the window from the database separately, navigate to the Bin folder. Execute the command MONGO and then execute the query Db.friend.find (). Directly, you can see that the data has been synchronized to the slave server. Interested students can perform delete modifications and other actions. Check to see if the data from the server is synchronized, the answer is yes. This is not a demo. :
Summary: The above steps can basically achieve the function of master-slave replication, but a single machine is too small, right when learning and understanding. Learning.
Follow the big theology Mongo,mongodb master-slave copy native simple operation summary