Summary and solution of Mongodb replica set construction _mongodb

Source: Internet
Author: User
Tags mongodb tomcat mongo shell rabbitmq

Summary and solution of Mongodb replica set erection problem

The replica set of the MongoDB database is composed of multiple servers, one of which is the primary node, the other is from the node, and if the primary node is down, it automatically switches to any one from the node. If the previous master node repair completed and normal operation will automatically become from the node, from the node can not query data. You can also install multiple MongoDB ports on a single server.

in my previous cognition, a system once formally on-line, most likely will not easily migrate the server, especially that involves many correlation application, involves many hardware server's system, because this kind of migration will be far-reaching.

However, there is still this situation, as I am mainly responsible for these days, is a system of all server migration in the part of the machine migration, and a part of others responsible.

This system relates to flume data acquisition, storm data analysis, RABBITMQ message distribution, Ehcache cache elevation system performance, MongoDB replica set storage data, Tomcat management system application, etc., the architecture is as follows:

And here I am mainly responsible for is RABBITMQ, Tomcat, Ehcache, MongoDB, where the side Tomcat, Ehcache installation and configuration are relatively simple, but rabbitmq need to rely on Erlang. Erlang has to rely on something else, which requires root to execute yum, and we don't have root permission, so it takes a little bit of effort.

In addition, the MongoDB replica set has also met a little bit of a problem, but fortunately everything is in accordance with the development of the expected, before the problem has not been encountered by the experience of the perfect solution.

There are some problems with MongoDB replica sets, mostly because this is not done personally, but by the newcomers.
First of all, according to the document I gave him a step-by-step operation, the result on the port, do not know because of the habit or because of what he set the port is not the port we require.

Then when I asked him to change to the required port, he was a little confused, do not know whether all the configuration should be deleted, or how to.

Because of the time relationship, I offered him a solution to get rid of the port directly using the configuration priority. I've written a copy of the set of documents should have said priority how to change, in general, three steps below:

Config=rs.conf ()
config.members[0].priority=2
rs.reconfig (config)

So according to this, we envisage the change port should be below this (the following IP and port is just a casual assumption, the production environment can not casually disclose):

Config=rs.conf ()
config.members[0].host= "192.168.117.88:37017"
rs.reconfig (config)

But the result, in the third step when throwing an exception, unfortunately, just to solve the problem without screenshots, forget the specific what is abnormal, but the general meaning is that the members of this port does not exist.
So I offered him a second option, which was to remove any one of the three member central services from the member:

Rs.remove ("Ip:port")

Then change the port of the machine to the 37017 we need, then add it by using the Add-member command:

Rs.add ("Ip:port")

After this operation three times, the ports of the three servers were successfully modified to the required ports.

In this process, when you modify to the main service, because the highest priority is set at the beginning, you need to set the other one first to a higher priority operation.
The problem is solved, but after I think again, it seems that this solution is not the best of the most concise, because at that time did not think carefully about the first solution to the problem of the reason, later a thought, mostly because the machine or the original port has not been restarted.

If we first reset the port of the non-primary service machine, then it would be feasible to do it again with the first one, and it would be simpler than the second, and it would be a good chance to try.

I thought this would be OK, and then did not think that, when we all migrated completed, was told that those machines are testing service network segment, to be converted into production network segment.
As a then, all of the machine IP has changed so much that our MongoDB replica set has to be reconfigured.

But this time more troublesome is, the previous change port because I can at least guarantee that there are two machines or normal operation, can operate RS command, but this time the IP changed, I three machines can not normal to become the main service, so that RS command failure.

Several toss, always did not come up with a good plan, so had to delete the contents of the data directory, and then the real reconfiguration again.
However, in this novice's operation, the configuration of the process, should be the following command:

config={_id: "Reptest", Members:[{_id:0,host: "192.168.0.160:57017"},{_id:1,host: "192.168.0.211:57017"},{_id:, Host: "192.168.0.213:57017"}]}
rs.initiate (config)

Made it this way:

config={_id: "Reptest", Members:[{_id:0,host: "192.168.0.160:57017"},{_id:1,host: "192.168.0.211:57017"},{_id:, Host: "192.168.0.213:57017"}]}
rs.initiate ()

In other words, although he assigned to config, but did not use when loading, it is also strange to forget to tell him before the discovery of a problem.

usually we operate Linux applications on window systems using CRT or putty tools, both of which are pros and cons, and I find that when we go into the MONGO shell, the two tools are different, and putty can be rolled back, The CRT is no longer able to mongodb the shell.

So when he finishes Rs.initiate (), wants to go back to add config in parentheses, there is no return, can only bite the bullet.

And this time, rs.initiate () can only be executed once, and then the operation of my document is not the same, what should I do?

After a problem, this problem seems to be very good to solve, how to do it, I think can still use Rs.add and modify the configuration of the way to solve, and then the idea to tell him, he took this operation, it was once done!

OK, this time the two problems basically solved, do not know other friends, whether this situation there is a better solution? Welcome Message FAQ.

Thank you for reading, I hope to help you, thank you for your support for this site!

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.