MongoDB Cluster--master/slave

Source: Internet
Author: User
Tags mongodb
configuration of the cluster(This test is placed on the same machine for configuration, so the IP address, if it is on a different server to replace the IP can be)
1, directory structure copy two MongoDB to/home/scotte.ye/mongo1 and/home/scotte.ye/mongo2
2, open MongoDB
Main: #cd/home/scotte.ye/mongo1/bin #./mongod--master-port=10111-dbpath=/home/data/10111-nohttpinterface & This allows the master server to be turned on, with a few key parameters to explain (and, of course, help yourself, too./mongod--help):--master: Identifies the currently open MongoDB as the primary server's-port: The current server's listening service port. Default 27017-dbpath: The log save path that the batch current program runs. Default/data/db. Note This path MongoDB not people to create their own, so be sure to create their own manually, otherwise the program can not start normally. -nohttpinterface: Do not open the Web interface, that is, the Web page can not view the status of the server running. The default is to open a Web service on port 28017 to provide users with View server status. Because the current is on the same machine, so if you open the two will have a conflict, so cannot be opened.
From: #cd/home/scotte.ye/mongo1/bin #./mongod--slave--source=192.168.35.106:10111-port=10112-dbpath=/home/data/ 10112-nohttpinterface & # This is to open a from the server, multiple from the same way to open. Several key parameter descriptions:--slave: Indicates that the current is open from the server. --source: Identifies the port and other IP parameters of the primary server to which the server is currently connected, so it is no longer to repeat.
Cluster features
1, only the primary server allows writing, other from the server can only read. 2, starting from the server will be immediately and the main server data synchronization, so do not worry about the later from the server will not be synchronized with the primary server before the data, and do not manually operate ourselves.
master-Slave switching of clusters
1, host downtime, Slave replacement stop Slave mongod process Delete Slave directory local.* file in--master mode to start B 2, switch Master/slave (original master is normal operation) Pause Master's write operation with the Fsync command//Ensure that the master/slave data is switched off slave service empties slave directory local.* file--master Restart slave for master In the original slave is now master above perform a write operation, generate Oplog, get the first sync point, because the slave and master data synchronization is achieved through Oplog. So this step is important and must be done. Closes the current master service, and Slave also generates a new local.* file to close the original master, replacing the local.* above the original master with the local.* file on the current master. Because the file is larger, it's best to compress the copy. Restart the new master service with the--master option and restart the original master service in--slave mode, and note that a-fastsync option is added. This is related to pausing master with Fsync if the original master is not normal, this time you can skip the first step, copy the new master file to the original master restart service.
3, update the primary server location
Suppose the original boot from the host is as follows: $ mongod--slave--source 192.168.35.106:10111 If you want to change the address of the primary server at this point, you can do this by restarting the Mongod service without adding-slave and -source option: $ mongod Start the shell to do the following: > Use the local switched to DB local >db.sources.update ({host: "192.168.356.106:10111 "},{$set: {host:" 192.168.35.106:10112 "}}) then reboot the server: $/mongod--slave--source=192.168.35.106:10112 $ # or $./mongod--s Lave







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.