mongodb3.2 Replica Set Configuration

Source: Internet
Author: User

The information on the Internet is too chaotic, and so the crossing network to find the most clear and concise recommended official website copy set configuration: https://docs.mongodb.com/manual/tutorial/deploy-replica-set/ Quote the Great God for a summary: http://blog.csdn.net/huwei2003/article/details/40453223 Conceptually, the difference between a MongoDB replica set and a master-slave copy. In fact, the replica set (Replica set) is an advanced form of master-slave replication. Where is the premium? Active replication implements a data backup + read extension, but if Master is down, you need to manually start slave. Replica set on this basis to achieve the function of automatic backup restart, that is, a certain slave will come forward, assume the responsibility of master. So there are three roles, Master (Primary), Slave (secondary), and arbiter server. Environment: win7,mongodb3.2 Replica Set Advantages: The replica set implements the function of automatic restart of the backup, that is, master once down, no need to manually start the slave, one will automatically slave stand up, assume the responsibility of master,   Maintain database read-write operation target: one master (primary): Master 127.0.0.1:5555 Three Slave (secondary): Mslave1 127.0.0.1:6666;  Mslave2 127.0.0.1:7777; Mslave3 192.168.228.134:27017 where 192.168.228.134 is the address of my virtual machine win7, all 64-bit First step: Basic ConfigurationSkip the installation and basic operation of MongoDB, see my other blog post: http://www.cnblogs.com/leskang/p/6000852.html Step Two: Set up the master server1, manually create four service instances of the file directory, and configure the respective bin directory environment variables, my local words just configure once 127.0.0.1:5555 corresponding native d:\mongodata\5555127.0.0.1:6666 corresponding native d:\ mongodata\6666127.0.0.1:7777 corresponds to the native e:\mongodata\7777192.168.228.134:27017 corresponding to the virtual machine D:/data 2, start the local 127.0.0.1 : 5555 Server Replica set instance, open command prompt as Mastercmd, run
After starting the service, open another command prompt to log in
MONGO--port 5555
Then define the variables and run:
conf = {_id: "MySet", Members:[{_id:0,host: "127.0.0.1:5555"}]}  
Enter then run:
The carriage return appears as follows: Then you enter:
will show that your current database service instance has been added to the replica set and is master, Step three: Start other local services and join the replica set, i.e. 127.0.0.1:5555 and 127.0.0.1:6666Open a 2 command prompt, enter it separately and return
Mongod--dbpath D:\mongodata\6666--replset myset--port 6666  --dbpath E:\mongodata\7777--replset MySet-- Port 7777
Alternatively, open a command prompt locally and log in to master:
MONGO--port 27017  
Then add just those 2 service instances to the replica set, enter them separately and return to them:
Rs.add ("127.0.0.1:6666") Rs.add ("127.0.0.1:7777")
The display is as follows: Added successfully, at this time you can log on any machine input rs.status () to view the collection, I landed slave 127.0.0.1:7777 Fourth Step: Add the virtual machine's database server to the replica setThat is, the 192.168.228.134:27017 method is basically the same as: Start the service to the virtual machine first, the same run Mongod--dbpath d:/data--replset myset--port 27017 then go back to the local, open a command prompt, Login Mastermongo--port 27017 and then add the service of the virtual machine to the replica set Rs.add ("192.168.228.134:27017") everything OK. Test: 1 Login Master Insert some data, then go to slave to see the same existence, Replication succeeded.Note: The new slave is unreadable and writable, and Errmsg:not master and slaveok=flase code:13435 errors occur when reading from the server, and need to be performed: Rs.slaveok () to turn on the Read function2 Close the Master window (that is, stop the Master service), the original master can not access, another slave become master, still can add the modified data 3 login to any service instance, run Rs.ismaster () You can see if the current service is master, run Rs.status () to see the inside of the replica group

mongodb3.2 Replica Set Configuration

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.