The construction of the master-slave copy of MongoDB database
Writeby:lipeng date:2014-10-22
Recent projects using the location query, on the Internet to see the MongoDB support distance query, so I learned a bit mongodb, in the study summed up the problems encountered and solutions, as well as MongoDB installation, master-slave replication, clustering and in. NET application of the operation, recorded to facilitate their own later use to get, but also hope to help those who learn MongoDB, I have just learned mongodb, there are problems hope everyone reminded out, learn from each other, common progress.
1. Preparation
Windows operating system computer one, in the e-disk new two folders to store the main database and from the database, the configuration file in the main database is as follows:
Where port, DBPath is the location of database files, logpath log file storage location
Note: Master=true represents the primary server.
The configuration file from the server is as follows:
Where port is the port number, DBPath is the location of the database file, and the location of the LogPath log file is stored.
Note: Slave=true represents the primary server. SOURCE=127.0.0.1:27017 represents the server from which the database files are synchronized.
2. Concrete implementation
- To open a CMD command operation, execute the following command:
Where: Enter the location of the configuration file after--config,
After successful startup, the following is displayed:
At this point, the primary server has started successfully.
2. Open a CMD operation again and execute the following command:
Where: Enter the location of the configuration file after--config
After successful startup, the following is displayed:
The server is now open.
3. Open the Home Server page: http://localhost:28017/----Note the port number plus 1000 as follows:
can see:
3. Open the Web page from the server: http://localhost:13548/----Note the port number plus 1000 as follows:
can see:
3. Testing
Enter the following command in the shell of the primary server: Db.test.save ({"11", 123})
Enter the following command in the shell from the server: Db.test.find () The result is as follows:
The test results indicate that master-slave replication is complete.
4. Problems encountered and solutions
- Time to start MongoDB error; Can not read from Mongdb.config. This error can occur because the path to the profile is not correctly written or the parameters of the configuration file are not written correctly.
- The error is as follows:
The reason for this error is that the port number being opened is already in use, and a new one will start normally.
MongoDB Database Learning Series ———— (i) The construction of the master-slave copy of MongoDB database