In this howto we’ll setup and configure MongoDB server on Ubuntu 14.04 x64 (it’s only available for x64 LTS distributions). To begin we have to setup custom repository:
MONGODB INSTALLATION
Add repo key:
1 |
root@mongodb:~# apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 7F0CEB10 |
Create apt source.list config:
1 |
root@mongodb:~# echo "deb http://repo.mongodb.org/apt/ubuntu "$(lsb_release -sc)"/mongodb-org/3.0 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-3.0.list |
Update apt repo list and install MongoDB:
1 |
root@mongodb:~# apt-get update; apt-get install -y mongodb-org |
MONGODB ACCESS CONFIGURATION
Now let’s setup access to MongoDB.
Run MongoDB shell and switch to admin user:
1 2 3 4 5 6 7 8 9 10 11 12 |
root@mongodb:~# mongo MongoDB shell version: 3.0.5 connecting to: test Welcome to the MongoDB shell. For interactive help, type "help". For more comprehensive documentation, see http://docs.mongodb.org/ Questions? Try the support group http://groups.google.com/group/mongodb-user > use admin switched to db admin > |
Create root user and exit the shell:
1 2 3 4 5 6 7 8 9 10 11 12 13 |
> db.createUser({user:"admin", pwd:"root", roles:[{role:"root", db:"admin"}]}) Successfully added user: { "user" : "admin", "roles" : [ { "role" : "root", "db" : "admin" } ] } > exit bye root@mongodb:~# |
Enable authentication in MongoDB config and restart MongoDB service:
1 2 |
root@mongodb:~# sed -i "s/#auth = true/auth = true/g" /etc/mongod.conf root@mongodb:~# service mongod restart |
Test the connection to database with new credentials:
1 2 3 4 |
root@mongodb:~# mongo -u admin -p root --authenticationDatabase admin MongoDB shell version: 3.0.5 connecting to: test > |
That’s all, your MongoDB is setup.