Install Mongodb on Centos 7

Step 1: download the package

1
wget https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-rhel70-3.4.2.tgz

Step 2: extract it

1
tar xzf mongodb-linux-x86_64-rhel70-3.4.2.gz

Step 3: create mongoDB database diretory

1
mkdir -p /data/db

Step 4: start mongodb without auth

1
/root/mongodb-linux-x86_64-rhel70-3.4.2/bin/mongod --port 27017 --dbpath /data/db

Step 5: connect to mongodb

1
/root/mongodb-linux-x86_64-rhel70-3.4.2/bin/mongo --port 27017

Step 6: add admin to mongoDB

1
2
3
use admin
db.createUser({user:"admin",pwd:"password",roles:["root"]})
db.auth("admin", "password");

Step 7: restart mongodb with auth

1
/root/mongodb-linux-x86_64-rhel70-3.4.2/bin/mongod --port 27017 --dbpath /data/db --auth