One-time hand-mistake causes the MONGO of the primary sub-set of the database to be processed by the secondary set

Source: Internet
Author: User

System Environment: CentOS6.5

Software: mongodb2.8


The original is to think of the current data to add a copy set, easy to read and write, did not think of the tragedy, and now even the original master data have become from the database, how also can not change the past 650) this.width=650; "Src=" http://img.baidu.com/hi/jx2/ J_0065.gif "alt=" J_0065.gif "/>.


Two solutions were tried:

1. Log in to the original main MongoDB, using the Rs.remove () method to remove the later added copy set from the member, failed.

650) this.width=650; "src=" Http://s1.51cto.com/wyfs02/M02/7E/56/wKiom1b8xtPQ0rdxAACX14VhqQ4864.png "title=" Rs-remove.png "alt=" wkiom1b8xtpq0rdxaacx14vhqq4864.png "/> Really tragic, how all remove, because the original master has become a slave, Cannot remove other Members


2. Change config, modify the priority of member 0, preempt master.


650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M01/7E/57/wKiom1b8x5uRpplbAAA888DL9gA707.png "title=" Rs-reconfig.png "alt=" Wkiom1b8x5urpplbaaa888dl9ga707.png "/>

Execution is also a failure because it is not currently master.


Helpless, can only find another way, because the MONGO data is not too familiar.

Later read the article on the Internet: https://segmentfault.com/q/1010000000532867 is also about this problem.

Probably think of the solution: Turn off this MONGO service, remove the local configuration directory from this instance, restart it, and then configure it with the Rs.initiate (CFG) method as master. The original data is still in haha 650) this.width=650; "src=" Http://img.baidu.com/hi/jx2/j_0057.gif "alt=" J_0057.gif "/>

step 1 .  closing the database:./bin/mongod --shutdown --dbpath /data/mongo/datacorestep 2  .  Delete or move local :  in the original replica set data #mv  /data/mongo/datacore /tmp           here do not delete, I am afraid there are some important configuration in the inside Ha step 3 .  start mongo ,  redo configuration [email  protected] mongodb]#/usr/local/mongodb/bin/mongod --directoryperdb --rest -replset  msbuset1 --dbpath=/data/mongo/datacore --port 27018 --fork --logpath /data /mongo/logs/datacorefile.log --logappend --maxconns 1600[[email protected] mongodb]#  ./bin/mongo --port 27017MongoDB shell version: 2.4.9connecting to:  127.0.0.1:27017/test>> show dbs;eventdev         0.203125gblocal   0.078125gbmessage 0.203125gbossdev  0.203125gbp2f      0.203125gbsnsdev  0.203125gbsnsuser 0.203125gbtest    0.203125gbtodo     0.203125gb> rs.stats () thu mar 31 13:33:21.757 typeerror: object  function  ()  { return  "Try rs.help ()"; } has no method  ' stats ' > rs.status () {         "Startupstatus"  : 3,          "Info"  :  "run rs.initiate (...)  if not yet done for the set ",          "OK"  : 0,         "errmsg"  :  "can" t get  local.system.replset config from self or any seed  (emptyconfig) "}>  cfg={_id: ' Msbuset0 ', members:[{_id:0,host: ' ${mongo_add_master}:27017 ',priority:10}]}{          "_id"  :  " Msbuset0 ",        " members " : [                 {                          "_ ID " : 0,                          "Host"  :  "${mongo_add_master}:27017",                           "Priority"  : 10                 }        ]}>  Rs.initiate (CFG) {         "OK"  : 0,          "ErrMsg " : " couldn ' t initiate : can ' t find self in the replset  config "}> cfg={_id: ' Msbuset0 ', members:[{_id:0,host: ' 192.168.22.198:27017 ',priority:10}]}{          "_id"  :  "Msbuset0",          "Members"  : [                 {                          "_id"  : 0,                           "host"  :  "192.168.22.198:27017",                          "Priority"  : 10                 }         ]}> rs.initiate (CFG) {         "info"  :  " Config now saved locally.  should come online in about a  minute. ",        " OK " : 1}>>>>>>> >>> rs.status () {         "set"  :  "Msbuset0",          "Date"  : isodate ("2016-03-31t05:36:34z"),          "MyState"  : 1,          "Members"  : [                 {                          "_id"  : 0,                          "Name"  :  " 192.168.22.198:27017 ",                          "Health"  : 1,                           "State"  : 1,                          "Statestr"  :  "PRIMARY",                           "Uptime"  : 234,                          "Optime"  : timestamp (1459402537, 5),                           "Optimedate"  : isodate ("2016-03-31t05:35:37z"),                           "Self"  : true                 }        ],          "OK"  : 1}msbuset0:PRIMARY>

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M02/7E/57/wKiom1b8yp7iE2vMAABA_kFTO9Q135.png "title=" Rs-initiate.png "alt=" Wkiom1b8yp7ie2vmaaba_kfto9q135.png "/>

Haha, finally succeeded.


This may be a stupid method, because it's not familiar to MongoDB.

If you have a good way, you can also say ha


This article is from the "Sea of Boundless" blog, please be sure to keep this source http://plong.blog.51cto.com/3217127/1758830

One-time hand-mistake causes the MONGO of the primary sub-set of the database to be processed by the secondary set

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.