First we need to get an EC2 instance up and running using 64-bit Amazon Linux. I like to do this from their command line tools commonly known as their CLI. You can also do this from their console. Here we indicate that we want to use a small instance in the US East 1a data center.
This will take a few minutes to get this guy up and running. I look for running instances by issuing this command.
Once the instance is up and running, I ssh into the machine.
Let’s udpate all of the software on the machine and make sure that we have modern versions of everything. This step is not necessary and you should probably skip it if you are just having fun.
Let’s add the 10gen repo to Yum. This will enable us to download packages from the people who manage MongoDB.
Insert the following within vi. If you don’t know vi, then type i to insert text, then paste this in there, and then hit ESC to exit edit mode and then :wq ENTER to write and quit.
name=10gen Repository
baseurl=http://downloads-distro.mongodb.org/repo/redhat/os/x86_64
gpgcheck=0
Now use yum package manager to install MondoDB.
Let’s create a directory for Mongo to put stuff.
Check out the help on Mongo so you can see what to do.
Ok, now let’s run the Mongo database in the background.
Now we can run the interactive shell and check it out.
> db.people = { 'firstName':'Michael','lastName':'Connor' }
Thu Jul 18 20:54:43.915 [conn1] build index test.people { _id: 1 }
Thu Jul 18 20:54:43.916 [conn1] build index done. scanned 0 total records. 0.001 secs
> db.people.find()
{ "_id" : ObjectId("51e856137213983dec659177"), "firstName" : "Michael", "lastName" : "Connor" }
exit
That’s it. If you wanna run Mongo in production then ignore this entire post and go to the 10gen website and read about RAID disks and other real world production issues. This is just for fun. Oh, one last thing. If you want to have Mongo continue to run after you log out you will need to run nohup before logging out.