MongoDB Cluster--master/slave

Source: Internet
Author: User

Configuration of the cluster

(This test is placed on the same machine to configure, so the IP address, if it is on a different server to replace the IP can) 1, directory structure copy two parts MongoDB to/home/scotte.ye/mongo1 and/home/scotte.ye/mongo2 2, Open MongoDB Master: #cd/home/scotte.ye/mongo1/bin#./mongod--master-port=10111-dbpath=/home/data/10111-nohttpinterface & #这样主服务器就开启了, a description of several key parameters (of course, you can also view Help,./mongod--help):--master: Identifies the current MongoDB that is being turned on as the-port of the primary server: The listening service port of the current server. Default 27017-dbpath: The log save path where the current program runs. Default/data/db. Note This path MongoDB does not create their own, so be sure to create their own manually, or the program will not start normally. -nohttpinterface: Does not open the Web interface, that is, the Web page can not be viewed as the server running state. The default is to open a Web service on port 28017 to provide a user view server status. Because it is currently on the same machine, it cannot be opened if the two are turned on to create a conflict. From: #cd/home/scotte.ye/mongo1/bin#./mongod--slave--source=192.168.35.106:10111-port=10112-dbpath=/home/data/ 10112-nohttpinterface & #这是开启一个从服务器, multiple from is also in the same way to open. Several key parameter descriptions:--slave: Indicates that the slave server is currently turned on. --source: Indicates that the port and IP other parameters of the primary server to be connected from the server are the same as the main one, so don't repeat them. Cluster features1, only the primary server is allowed to write, the other slave server can only read. 2, from the server startup time will be and the main server for data synchronization, so do not worry about the coming from the server will not sync with the main server before the data, do not let us do it manually. master-Slave switching of the cluster1, host downtime, slave replacement
    • Stop the mongod process of slave
    • Delete the local.* file under the slave directory
    • Start B in--master mode
2, Switch Master/slave (the original master is normal operation)
    • Use the Fsync command to pause Master writes//To ensure master/slave data synchronization when switching
    • Close slave Service
    • Empty the local.* file in the slave directory
    • Restart slave with--master as master
    • Perform a write operation on the original slave, which is now master, and generate the Oplog to get the first synchronization point, because slave data synchronization with master is achieved through Oplog. So this step is important, be sure to finish.
    • Close the current master service, and Slave will also generate a new local.* file
    • To close the original master, replace the local.* above the original master with the local.* file above the current master. Because the file is larger, it is best to compress the copy
    • Restart the new master service with the--master option
    • Restart the original master service with--slave mode, and note that you have to add a-fastsync option. This is related to suspending master with Fsync.
If the original master is not normal, then this time can skip the first step, copy the new master file to the original master restart service is OK. 3, update the primary server location assumes the original starting from the host mode as follows: $ mongod--slave--source 192.168.35.106:10111 If you want to change the address of the primary server, you can do this in the following way:
    • Restart the Mongod service, do not add-slave and-source options: $ mongod
    • start the shell to do the following:
      • > Use local
      • switched to DB local
      • >db.sources.update ({host: "192.168.356.106:10111"},{$set: {host: "192.168.35.106:10112"}})
    • then restart 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.