Friday, April 1, 2016

Installing MongoDB on an EC2 Linux instance



We have to Log into the instance as root user

Now we have to add the 10gen MongoDB repository for yum, by creating the file 

sudo vi /etc/yum.repos.d/10gen-mongodb.repo

For 64-bit. Copy the below.

[10gen]
name=10gen Repository
baseurl=http://downloads-distro.mongodb.org/repo/redhat/os/x86_64
gpgcheck=0

For 32-bit . Copy the below.

[10gen]
name=10gen Repository
baseurl=http://downloads-distro.mongodb.org/repo/redhat/os/i686
gpgcheck=0

Install MongoDB by running the following command

sudo yum install mongo-10gen mongo-10gen-server

Modify the file /etc/mongod.conf Change the location of DB, logs files, ports as necessary

logpath=/var/log/mongo/mongod.log
port=27017
dbpath=/var/lib/mongo

If you have changed the location of the db or log files, make sure that mongod has write permissions at the new locations. If not assign persmission

sudo chown mongod:mongod /data/mongodb
sudo chown mongod:mongod /data/mongo/mongod.log

The new location can be /data/mongodb for dbpath and /data/log/mongo/mongod.log for logpath. If these directories are created then we have to give the permissions to the specified folders

Start MongoDB server

sudo service mongod start
or
sudo /etc/init.d/mongod start

To start MongoDB on server reboot

sudo chkconfig --levels 235 mongod on