Original: MongoDB cluster instance

Source: Internet
Author: User

Original: MongoDB cluster instance

It is estimated that I do not have so many servers for sharding, so the server cluster is similar to the master-slave server cluster, and the single database is not sharded to multiple machines.
The following goals are to save a complete copy of data on multiple machines and to automatically switch between the master and slave nodes (not implemented)

Even so, the configuration is still in full swing, especially onlineArticleMany implementation differences are based on the local machine or version, and multiple steps are not applicable to those tutorials.

Use version mongodb-win32-i386-2.0.2

1. Unzip the package and start using it.
2. Explain the configuration file.
The example on the Internet is basically a command line. The configuration file is as follows:
Mongod -- config D :\ mongodb-win32-i386-2.0.2 \ bin \ Mongo. CNF
Basically, the content of the configuration file is similar to the parameter: Remove "--" of the command line parameter and add "=" before the parameter value, and each parameter can be a single line.
Example:
Dbpath = D: \ mongodb-win32-i386-2.0.2 \ bin \ data

However, the example is still a command line, as shown below:
Mongod.exe -- dbpath D: \ mongodb-win32-i386-2.0.2 \ bin \ data -- replset RS1 -- Keyfile D: \ mongodb-win32-i386-2.0.2 \ bin \ key_r0

3. Check that the key_r0 file does not exist. This is the identifier that mongdb must have, and the master and slave hosts are the same (in fact, my master and slave hosts only have different Data Directories)
The content is a text file, which can be "this is RS1 super secret key"

4. Initialization must be performed in the command line for the first time, but after initialization, the file will be written and no longer needed,ProgramJust start.
5. initialize the master and slave hosts during initialization.
6. At least no data exists from the data on the machine during initialization. Execute Rs. Initiate (config_rs1); -- an error will be reported during configuration initialization. See the prompt.
7. The command is as follows:
Command 1
Config_rs1 = {_ ID: 'rs1', members :[
{_ ID: 0, host: '192. 168.41.177: 100', Priority: 1}, -- member IP address and port, priority = 1 indicates primary
{_ ID: 1, host: '192. 168.41.34: 100 '}
}

Command 2
Rs. Initiate (config_rs1); -- initialize the configuration

Maybe there is a problem with my version or configuration, and the English in the command should be removed.
8. Check whether the command is successful using RS. Status.
9. Run the command in mongodb.exe on the local machine.
10. If you want to use a tool such as mongovue to access data from the slave machine across machines, you can also use the user logon mode by adding a user to the database.
In the database, you can access all databases. Operations to add users must be performed on the host, automatically synchronized from the opportunity.
11. By default, the slave database is read-only and slaveok must be changed. Otherwise, "server is not a primary and slaveok is false .." will be reported .."
12. The login connection string for authentication is as follows:
Login Server MongoDB = Login server. Create ("MongoDB: // 192.168.41.34: 27017/root: 111 ");
Failed
// Login Server MongoDB = Login server. Create ("MongoDB: // 192.168.41.34: 27017/root: 111? Slaveok = true ");

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.