Mongodb replica set

Source: Internet
Author: User
Tags mongodb server

Mongodb replica set

After the parameters are configured on the node respectively, the following hapame-db is displayed :~ # Cat/etc/mongod. conf | grep jieshireplSet = jieshi restart the MongoDB server and ensure that there are no other databases (except adminlocal) on the server. If there are other databases, in this step rs. initiate (hapameconfig). An error is returned. Log on to one of the MongoDB servers and configure hapame-db :~ # MongoMongoDB shell version: 1.6.5-rcconnecting to: test> show dbsadminlocal> hapameconfig = {_ id: "jieshi", members :[... {_ id: 0, host: "192.168.16.234 "},... {_ id: 1, host: "192.168.16.103 "},... {_ id: 2, host: "192.168.16.216"}...]} {"_ id": "jieshi", "members": [{"_ id": 0, "host": "192.168.16.234" },{ "_ id": 1, "host": "192.168.16.103" },{ "_ id": 2, "host": "192.168.16.216"}]}> rs. initiate (Hapameconfig) {"info": "Config now saved locally. shocould come online in about a minute. "," OK ": 1}> db. system. replset. find () {"_ id": "jieshi", "version": 1, "members": [{"_ id": 0, "host ": "192.168.16.234" },{ "_ id": 1, "host": "192.168.16.103" },{ "_ id": 2, "host ": "192.168.16.216"}]} on the 192.168.16.234 Server: (SUSE Linux Enterprise Server 11 (x86_64)> rs. isMaster () {"setName": "jieshi "," Ismaster ": true," secondary ": false," hosts ": [" 192.168.16.234 "," 192.168.16.216 "," 192.168.16.103 "]," OK ": 1}> rs. status () {"set": "jieshi", "date": "Fri Dec 10 2010 12:48:46 GMT + 0800 (CST)", "myState": 1, "members ": [{"_ id": 0, "name": "hapame-db: 27017", "health": 1, "state": 1, "self": true }, {"_ id": 1, "name": "192.168.16.103", "health": 1, "state": 2, "uptime": 133, "LastHeartbeat": "Fri Dec 10 2010 12:48:45 GMT + 0800 (CST)" },{ "_ id": 2, "name": "192.168.16.216", "health ": 1, "state": 2, "uptime": 127, "lastHeartbeat": "Fri Dec 10 2010 12:48:45 GMT + 0800 (CST)"}], "OK ": 1} on the 192.168.16.103 server: (CentOS release 5.5) [root @ jieshiyeskey ~] # Cat/etc/mongod. conf | grep jieshireplSet = jieshi [root @ jieshiyeskey mongo] # using MongoDB shell version: 1.6.4connecting to: test> use localswitched to db local> show collectionsmeoplog. rsreplset. minvalidsystem. indexessystem. replset> db. system. replset. find () {"_ id": "jieshi", "version": 1, "members": [{"_ id": 0, "host ": "192.168.16.234" },{ "_ id": 1, "host": "192.168.16.103" },{ "_ id": 2, "Host": "192.168.16.216"}]}> rs. isMaster () {"setName": "jieshi", "ismaster": false, "secondary": true, "hosts": ["192.168.16.103", "192.168.16.216 ", "192.168.16.234"], "primary": "192.168.16.234", "OK": 1}> rs. status () {"set": "jieshi", "date": "Fri Dec 10 2010 12:52:17 GMT + 0800 (CST)", "myState": 2, "members ": [{"_ id": 0, "name": "192.168.16.234", "health": 1, "state": 1 ," Uptime ": 344," lastHeartbeat ":" Fri Dec 10 2010 12:52:16 GMT + 0800 (CST) "},{" _ id ": 1," name ":" jieshiyeskey.hapaworld.com.cn: 27017 "," health ": 1," state ": 2," self ": true}, {" _ id ": 2," name ":" 192.168.16.216 ", "health": 1, "state": 2, "uptime": 338, "lastHeartbeat": "Fri Dec 10 2010 12:52:16 GMT + 0800 (CST)"}], "OK": 1} ON THE 192.168.16.216 server: (FreeBSD 8.1-RELEASE) [root @ jieshi ~] # Cat/usr/local/etc/mongodb. conf | grep jieshireplSet = jieshi [root @ jieshi/var/db/mongodb] # mongoMongoDB shell version: 1.6.3connecting to: test> show dbsadminlocal> use localswitched to db local> show collectionsmeoplog. rsreplset. minvalidsystem. indexessystem. replset> db. system. replset. find () {"_ id": "jieshi", "version": 1, "members": [{"_ id": 0, "host ": "192.168.16.234" },{ "_ id": 1, "host ":" 192.168.16.103 "},{" _ id ": 2," host ":" 192.168.16.216 "}]}> rs. isMaster () {"setName": "jieshi", "ismaster": false, "secondary": true, "hosts": ["192.168.16.216", "192.168.16.103 ", "192.168.16.234"], "primary": "192.168.16.234", "OK": 1}> rs. status () {"set": "jieshi", "date": "Fri Dec 10 2010 04:58:15 GMT + 0800 (CST)", "myState": 2, "members ": [{"_ id": 0, "name": "192.168.16. 234 "," health ": 1," state ": 1," uptime ": 101," lastHeartbeat ":" Fri Dec 10 2010 04:58:14 GMT + 0800 (CST )"}, {"_ id": 1, "name": "192.168.16.103", "health": 1, "state": 2, "uptime": 101, "lastHeartbeat ": "Fri Dec 10 2010 04:58:14 GMT + 0800 (CST)"}, {"_ id": 2, "name": "jieshi.hapame.com.cn: 27017", "health": 1, "state": 2, "self": true}], "OK": 1 }@@ add new member 192.168.16.211 :( Red Hat Ent Erprise Linux Server release 6.0 (Santiago) [root @ 6 mongo] # cat/etc/mongod. conf | grep jieshireplSet = jieshiroot @ 6 mongo] #/etc/init. d/mongod startStarting mongod: forked process: 8w.all output going to:/var/log/mongo/mongod. log [OK] [root @ 6 mongo] # tail/var/log/mongo/mongod. logFri Dec 10 13:18:50 [startReplSets] replSet can't get local. system. replset config from self or any seed (EMPTYCONFIG) F Ri Dec 10 13:18:54 [snapshotthread] cpu: elapsed: 4000 writelock: 0% Fri Dec 10 13:18:58 [snapshotthread] cpu: elapsed: 4000 writelock: 0% Fri Dec 10 13:19:00 [startReplSets] replSet can't get local. system. replset config from self or any seed (EMPTYCONFIG) Fri Dec 10 13:19:02 [snapshotthread] cpu: elapsed: 4000 writelock: 0% Fri Dec 10 13:19:06 [snapshotthread] cpu: elapsed: 4000 writelock: 0% Fri Dec 10 1 3:19:10 [snapshotthread] cpu: elapsed: 4000 writelock: 0% Fri Dec 10 13:19:10 [startReplSets] replSet can't get local. system. replset config from self or any seed (EMPTYCONFIG) # this warning is reported on each node. Fri Dec 10 13:19:14 [snapshotthread] cpu: elapsed: 4000 writelock: 0% Fri Dec 10 13:19:18 [snapshotthread] cpu: elapsed: 4000 writelock: 0% Add a new member only on primary: (currently 192.168.16.234 is primary) hapame-db :~ # MongoMongoDB shell version: 1.6.5-rc1connecting to: test> rs. add ("192.168.16.211") {"OK": 1}> rs. conf () {"_ id": "jieshi", "version": 2, "members": [{"_ id": 0, "host ": "192.168.16.234" },{ "_ id": 1, "host": "192.168.16.103" },{ "_ id": 2, "host": "192.168.16.216 "}, {"_ id": 3, "host": "192.168.16.211"}]}> rs. isMaster () {"setName": "jieshi", "ismaster": true, "secondary": fal Se, "hosts": ["192.168.16.234", "192.168.16.211", "192.168.16.216", "192.168.16.103"], "OK": 1}> rs. status () {"set": "jieshi", "date": "Fri Dec 10 2010 13:23:10 GMT + 0800 (CST)", "myState": 1, "members ": [{"_ id": 0, "name": "hapame-db: 27017", "health": 1, "state": 1, "self": true }, {"_ id": 1, "name": "192.168.16.103", "health": 1, "state": 2, "uptime": 46, "lastHeartbeat": "F Ri Dec 10 2010 13:23:08 GMT + 0800 (CST) "},{" _ id ": 2," name ":" 192.168.16.216 "," health ": 1," state ": 2, "uptime": 46, "lastHeartbeat": "Fri Dec 10 2010 13:23:08 GMT + 0800 (CST)" },{ "_ id": 3, "name ": "192.168.16.211", "health": 1, "state": 2, "uptime": 38, "lastHeartbeat": "Fri Dec 10 2010 13:23:08 GMT + 0800 (CST) "}]," OK ": 1}> view the following on 192.168.16.211: [root @ 6 mongo] # mongoMongoDB shell Version: 1.6.4connecting to: test> show dbsadminlocal> use localswitched to db local> show collectionsmeoplog. rsreplset. minvalidsystem. indexessystem. replset> db. system. replset. find () {"_ id": "jieshi", "version": 2, "members": [{"_ id": 0, "host ": "192.168.16.234" },{ "_ id": 1, "host": "192.168.16.103" },{ "_ id": 2, "host": "192.168.16.216 "}, {"_ id": 3, "host": "192.168.16.211"}] }> Rs. isMaster () {"setName": "jieshi", "ismaster": false, "secondary": true, "hosts": ["192.168.16.211", "192.168.16.216 ", "192.168.16.103", "192.168.16.234"], "primary": "192.168.16.234", "OK": 1}> rs. status () {"set": "jieshi", "date": "Fri Dec 10 2010 13:24:54 GMT + 0800 (CST)", "myState": 2, "members ": [{"_ id": 0, "name": "192.168.16.234", "health": 1, "state": 1, "uptime": 142, "LastHeartbeat": "Fri Dec 10 2010 13:24:52 GMT + 0800 (CST)" },{ "_ id": 1, "name": "192.168.16.103", "health ": 1, "state": 2, "uptime": 142, "lastHeartbeat": "Fri Dec 10 2010 13:24:52 GMT + 0800 (CST)" },{ "_ id ": 2, "name": "192.168.16.216", "health": 1, "state": 2, "uptime": 142, "lastHeartbeat ": "Fri Dec 10 2010 13:24:52 GMT + 0800 (CST)"}, {"_ id": 3, "name": "6.hapame.com: 27017 ", "Health": 1, "state": 2, "self": true}], "OK": 1} test: On 192.168.16.234:> rs. isMaster () {"setName": "jieshi", "ismaster": true, # indicates primary "secondary": false, "hosts": ["192.168.16.234 ", "192.168.16.211", "192.168.16.216", "192.168.16.103"], "OK": 1} You can have all permissions on primary, but you do not have the following permissions on the secondary node:> show dbsadminhapameworldlocal> use hapameworldswitched to db hapameworld> show collectionshapameworlds Ystem. indexes> db. hapameworld. find () {"_ id": ObjectId ("4d01bed1356d93b46d48ba34"), "name ": "markgeng"}> show dbsadminhapameworldlocal> use hapameworldswitched to db hapameworld> show collectionsFri Dec 10 14:46:57 uncaught exception: error: {"$ err": "not master", "code ": 10107} switch off the 192.168.16.234 server: hapame-db :~ # Ps-ef | grep droot 2377 1 7? 00:09:55/opt/mongodb/bin/mongod-f/etc/mongod. confroot 11035 10139 00:00:00 pts/5 grep mongodhapame-db :~ # Killall route dhapame-db :~ # Ps-ef | grep primary droot 11039 10139 0 00:00:00 pts/5 grep primary d Now 192.168.16.211 server is primary as follows: [root @ 6 ~] # MongoMongoDB shell version: 1.6.4connecting to: test> rs. isMaster () {"setName": "jieshi", "ismaster": true, "secondary": false, "hosts": ["192.168.16.211", "192.168.16.216 ", "192.168.16.103", "192.168.16.234"], "OK": 1}> show dbsadminhapameworldlocal> use hapameworldswitched to db hapameworld> show collectionshapameworldsystem. indexes> db. hapameworld. find () {"_ id": ObjectId ("4d01bed1356d9 3b46d48ba34 ")," name ":" markgeng "}> db. hapameworld. insert ({name: "jieshi"})> db. hapameworld. find () {"_ id": ObjectId ("4d01bed1356d93b46d48ba34"), "name": "markgeng"} {"_ id": ObjectId ("4d01d812b68ce41287454183 "), "name": "jieshi"} on the secondary server:> show dbsadminhapameworldlocal> use hapameworldswitched to db hapameworld> show collectionsFri Dec 10 15:36:13 uncaught exception: error: {"$ err ": "not m Aster "," code ": 10107} Now starts the previous primary :( 192.168.16.234) hapame-db :~ # Mongod-f/etc/mongod. confhapame-db :~ # Forked process: 12997all output going to:/opt/mongodb_logs/mongod. loghapame-db :~ # Ps-ef | grep droot 12997 1 0? 00:00:00 mongod-f/etc/mongod. confroot 13039 12417 0 00:00:00 pts/2 grep mongodhapame-db :~ # MongoMongoDB shell version: 1.6.5-rc1connecting to: test> rsMaster () Fri Dec 10 15:38:10 ReferenceError: rsMaster is not defined (shell): 0> rs. isMaster () {"setName": "jieshi", "ismaster": false, # has become a secondary node, and primary will not migrate it back by itself "secondary": true, "hosts ": ["192.168.16.234", "192.168.16.211", "192.168.16.216", "192.168.16.103"], "primary": "192.168.16.211", "OK ": 1}> show dbsadminhapameworldlocal> use hapameworldswitched to db hapameworld> show collectionsFri Dec 10 15:38:43 uncaught exception: error: {"$ err": "not master", "code": 10107}

Related Article

E-Commerce Solutions

Leverage the same tools powering the Alibaba Ecosystem

Learn more >

Apsara Conference 2019

The Rise of Data Intelligence, September 25th - 27th, Hangzhou, China

Learn more >

Alibaba Cloud Free Trial

Learn and experience the power of Alibaba Cloud with a free trial worth $300-1200 USD

Learn more >

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.