English 中文(简体)
How to scale MongoDB?
原标题:

I know that MongoDB can scale vertically. What about if I am running out of disk?

I am currently using EC2 with EBS. As you know, I have to assign EBS for a fixed size.

What if the MongoDB growth bigger than the EBS size? Do I have to create a larger EBS and Copy & Paste the files?

Or shall we start more MongoDB instance and each connect to different EBS disk? In such case, I could connect to a different instance for different databases.

问题回答

If you re running out of disk, you obviously need to get a bigger disk.

There are several ways to migrate your data, it really depends on the type of up-time you need. First steps of course involve bundling the machine and creating the new volume.

These tips go from easiest to hardest.

Can you take the database completely off-line for several minutes?

If so, do this (migration by copy):

  1. Mount new EBS on the server.
  2. Stop your app from connecting to Mongo.
  3. Shut down mongod and wait for everything to write (check the logs)
  4. Copy all of the data files (and probably the logs) to the new EBS volume.
  5. While the copy is happening, update your mongod start script (or config file) to point to the new volume.
  6. Start mongod and check connection
  7. Restart your app.

Can you take the database off-line for just a few minutes?

If so, do this (slaving and switch):

  1. Start up a new instance and mount the new EBS on that server.
  2. Install / start mongod as a --slave pointing at the current database. (you may need to re-start the current as --master)
  3. The slave will do a fresh synchronization. Once the slave is up-to-date, you ll do a "switch" (next steps).
  4. Turn off writes from the system.
  5. Shut down the original mongod process.
  6. Re-start the "new" mongod as a master instead of the slave.
  7. Re-activate system writes pointing at the new master.

Done correctly those last three steps can happen in minutes or even seconds.

Can you not afford any down-time?

If so, do this (master-master):

  1. Start up a new instance and mount the new EBS on that server.
  2. Install / start mongod as a master and a slave against the current database. (may need to re-start current as master, minimal down-time?)
  3. The new computer should do a fresh synchronization.
  4. Once the new computer is up-to-date, switch the system to point at the new server.

I know it seems like this last version is actually the best, but it can be a little dicey (as of this writing). The reason is simply that I ve honestly had a lot of issues with "Master-Master" replication, especially if you don t start with both active.

If you plan on using this method, I highly suggest a smaller practice run first. If something bombs here, Mongo might simply wipe all of your data files which will have the effect of taking more stuff down.

If you get a good version of this please post the commands, I d like to see it in action.

Doesn t the E in EBS stand for elastic meaning something like resizing on the fly?

Currently the MongoDB team is working on finishining sharding which will allow you horizontal scaling by partitioning data separately on different servers. Give it a month or two and it will work fine. The developers are quite good at keeping their promises.

http://api.mongodb.org/wiki/current/Sharding%20Introduction.html http://api.mongodb.org/wiki/current/Sharding%20Limits.html

You could slave the bigger disk off the smaller until it s caught up

or

fsync+lock and take a file system snapshot and copy it onto the bigger disk.

well, I am using Mongo DB now. I am pretty amazed the performance it generated, especially on some simple sorting.

I believe it s a good tool for simple web application logic. The remaining concern for is how to scale and backup. I will continue to explore.

The only disadvantage I have is that I didn t have any good tools to reveal the data stored inside. For example, I want to put my logging from MYSQL into Mongo as well. However, it s pretty difficult for me to view the log. Previously, i can use MYSQL query to fetch what I want easily.

Anyway, it s a good tool and I will continue to use it.





相关问题
Mount windows shared drive to MWAA in bootscript

In MWAA startup script sudo yum install samba-client cifs-utils -y sudo mount.cifs //dev/test/drop /mnt/dev/test-o username=testuser,password= pwd ,domain=XX Executing above commonds giving error - ...

How to get Amazon Seller Central orders programmatically?

We have been manually been keying Amazon orders into our system and would like to automate it. However, I can t seem to figure out how to go about it. Their documentation is barely there. There is: ...

Using a CDN like Amazon S3 to control access to media

I want to use Amazon S3/CloudFront to store flash files. These files must be private as they will be accessed by members. This will be done by storing each file with a link to Amazon using a mysql ...

unable to connect to database on AWS

actually I have my website build with Joomla hosted on hostmonster but all Joomla website need a database support to run this database is on AWS configuration files need to be updated for that I ...

Using EC2 Load Balancing with Existing Wordpress Blog

I currently have a virtual dedicated server through Media Temple that I use to run several high traffic Wordpress blogs. Both tend to receive sudden StumbleUpon traffic surges that (I m assuming) ...

SSL slowness in EC2

We ve deployed our rails app to EC2. In our setup, we have two proxies on small instances behind round-robin DNS. These run nginx load balancers for a dynamically growing and shrinking farm of web ...

热门标签