MongoDB Finishing Notes Management replica sets

Source: Internet
Author: User

I. Read and write Separation

Queries can be made from the library, which can share a large number of query requests from the main library.

1. Insert a test data into the main library first

[Email protected] bin]#/mongo--port 280101.8.1 127.0.0.1:28010/testrs1:primary> Db.c1.insert ({age:30}) Db.c2rs1:PRIMARY>"_id": ObjectId ("4fc77f421137ea4fdb653b4a"), "age": 30}

2, in the query from the library and other operations

[Email protected] bin]#/mongo--port 280111.8.1 127.0.0.1:28011/testrs1:secondary>  22:27:17 uncaught exception:error: {"$err": "Not Master and Slaveok=false","code": 13435 }rs1 : Secondary>

Query error, description is an operation from the library and cannot execute the query

3, let from the library can read, share the pressure of the main library

Rs1:secondary> Db.getmongo (). Setslaveok () not master and Slaveok=falsers1:secondary > show Collectionsc1system.indexesrs1:SECONDARY>"_id": ObjectId ("4fc77f421137ea4fdb653b4a ")," age ": }rs1:secondary>

We did it.

ii.. Failover

Replication sets better than the traditional master-slave is that he can fail the automatic transfer, if we stop a member in the replication set, then the remaining members will automatically elect a member, as the main library, for example: We will 28010 this main library to stop, and then look at the state of the replica set

Test:

1. Kill 28010-Port MongoDB

[[Email protected] bin]# PS aux|  6706 1.6 6.9 463304 6168 Sl 21:49 0:26/apps/mongo/bin/mongod--replset rs1--keyfile/data/key/r0--fork--port 2 80106733 0.4 6.7 430528 6044? Sl 21:50 0:06/apps/mongo/bin/mongod--replset rs1--keyfile/data/key/r1--fork--port 280116747 0.4 4.7 431548 4 260?  Sl 21:50 0:06/apps/mongo/bin/mongod--replset rs1--keyfile/data/key/r2--fork--port 280127019 0.0 0.7 5064 684 PTS/2 s+ 22:16 0:00-9 6706
View Code

2. Then view the replication set status

[Email protected] bin]#/mongo--port 28011MongoDB Shell version:1.8.1Connecting to:127.0.0.1:28011/testrs1:secondary>Rs.status () {"Set": "Rs1","Date": Isodate ("2012-05-31t14:17:03z"),"MyState": 2,"Members" : [{"_id": 0,"Name": "localhost:28010","Health": 0,"State": 1,"Statestr": "(not Reachable/healthy)","Uptime": 0,"Optime" : {"T": 1338472279000,"I": 1},"Optimedate": Isodate ("2012-05-31t13:51:19z"),"Lastheartbeat": Isodate ("2012-05-31t14:16:42z"),"ErrMsg": "Socket Exception"},{"_ID": 1,"Name": "localhost:28011","Health": 1,"State": 2,"Statestr": "Secondary","Optime" : {"T": 1338472279000,"I": 1},"Optimedate": Isodate ("2012-05-31t13:51:19z"),"Self":true},{"_ID": 2,"Name": "localhost:28012","Health": 1,"State": 1,"Statestr": "PRIMARY","Uptime": 1528,"Optime" : {"T": 1338472279000,"I": 1},"Optimedate": Isodate ("2012-05-31t13:51:19z"),"Lastheartbeat": Isodate ("2012-05-31t14:17:02z")}],"OK": 1}rs1:secondary> "Statestr": "(not Reachable/healthy)",
View Code

Can see 28010 this port MongoDB has an exception, and the system automatically elected 28012 of this port-based, so the fault-handling mechanism, can greatly improve the stability of the system.

MongoDB Finishing Notes Management replica sets

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.