When it comes to databases, besides the well-known relational databases, there is a rising star in the scene—NoSQL (which is short for Not Only SQL). Today, we’ll introduce MongoDB, a key member of this family. As a document-oriented database based on distributed file storage, MongoDB is especially suitable for handling flexible data structures. In this guide, we will walk you through the process of installing MongoDB 3.6 from source on RedHat 6.5.
When you see this log message, the startup is successful:
1
[initandlisten] waiting for connections on port 27017
Test the Connection
1 2 3 4
mongo --host 127.0.0.1:27017 # After entering, type the ping command to test > db.runCommand({ping:1}) { "ok" : 1 } # If you see this response, everything's fine
Security Setup: A Must-Know
Create an Admin Account
Start MongoDB in non-authentication mode:
1
mongod --dbpath /data/db
After connecting, create a superuser:
1 2 3 4 5 6
use admin db.createUser({ user: "admin", pwd: "yourStrongPassword", roles: ["userAdminAnyDatabase"] })
Creating Regular Users
1 2 3 4 5 6
use your_database db.createUser({ user: "app_user", pwd: "securePassword", roles: ["readWrite"] })
Enable Authentication
Add the –auth parameter to your startup command, or, preferably, use a configuration file:
Using a configuration file for startup is both professional and convenient, making it ideal for production environments. Remember to back up your /data/db directory regularly and protect important data with the –auth parameter. If you encounter issues, check the /data/mongod.log log file; it will usually point you in the right direction. Get started with MongoDB now and embark on your database journey!