mongodb high-availability architecture --- Replica Set

mongodb high-availability architecture --- Replica Set Replica Set using the n nodes mongod construct comprising automatic failover (auto-failover), availability of automatic recovery scheme (auto-recovery) of. Use Replica Set to read and write separation. When connection or by specifying slaveOk specified in the master library, the read to share Secondary pressure, Primary bear only a write operation. For Replica Set in the secondary node default it is unreadable. Environment as follows: 192.168.198.131 192.168.198.129 192.168.198.132 mongod services were installed on three servers, installed as follows: # wget http://fastdl.mongodb.org/linux/mongodb-linux-x86_64-2.0.3.tgz # tar zxvf mongodb-linux-x86_64-2.0.3.tgz -C ../software/ # ln -s mongodb-linux-x86_64-2.0.3 / usr / local / mongodb # useradd mongodb # mkdir -p / data / mongodb / myset # cd / usr / local / mongodb / bin # ./mongod --replSet myset --dbpath / data / mongodb / myset --oplogSize 100 --logpath /data/mongodb/myset/myset.log --logappend --fork # ./mongo // optionally performed following a> config = {_ id: "myset", members: [... {_id: 0, host: "192.168.198.131:27017"}, .. . {_id: 1, host: "192.168.198.129: 1 represents a normal, abnormal 0 at the same time, each group has only one Primary Replica Sets, for receiving a write operation. And then copied to other members of the database asynchronously. Once the primary die, will automatically vote for the primary to succeed, after the original server is restored to become ordinary members. If the data has not been copied from the previous primary server to a member, it is possible to lose data. PRIMARY> db.test.insert ({ "name": "foobar", "age": 25}) PRIMARY> db.test.find () { "_id": ObjectId ( "4f4f38fc47db2bfa5ceb2aee"), "name": " foobar "," age ": 25} SECONDARY> db.test.find () error: {" $ err ":" not master and slaveok = false "," code ": 13435} SECONDARY> db.test.insert ({ "name": "foobar", "age": 25}) not master set slaveok = ok pRIMARY> db.getMongo () setSlaveOk () SECONDARY> use test switched to db test SECONDARY> db.test on the primary library. find () { "_id": ObjectId ( "4f4f38fc47db2bfa5ceb2aee"), "name": "foobar",

Reproduced in: https: //my.oschina.net/766/blog/211493

Guess you like

Origin blog.csdn.net/weixin_34357436/article/details/91493039