?? MongoDB Setup for Cloud Server (Database Server) – Key Considerations for Admins and DevOps Engineers ??
?? Setting Up MongoDB on Ubuntu for a Secure and Fully Permission-Controlled Database Environment ??
As a Server Administrator and DevOps Engineer, I recently deployed MongoDB on a cloud server, with a particular focus on managing roles and permissions to ensure robust security. In this post, I'll walk through the key steps involved in setting up MongoDB on an Ubuntu server and configuring user permissions so that the developer user has restricted access and cannot drop collections or databases.
1. Cloud Server Preparation:
First, I provisioned a clean server instance on my preferred cloud provider (AWS, GCP, Azure), ensuring that it met the necessary specifications (memory, CPU, storage) for MongoDB to perform optimally. I chose Ubuntu 22.04 LTS for its reliability and long-term support, a great fit for database deployment.
?
2. MongoDB Installation:
To ensure a stable and up-to-date setup, I installed the MongoDB 7.0 Community Edition from the official MongoDB repositories. Here are the steps I followed:
this process is mongodb installation on debian based ubuntu
$ sudo rm /tmp/mongodb-27017.sock
$ sudo systemctl restart mongod
$ sudo systemctl status mongod
3. Configuring Roles and Permissions:
MongoDB allows for fine-grained control over user roles, which is crucial when deploying databases in a production environment. For this setup, I created two users:
$ mongosh --> (this command fire on your terminal for access the mongodb-cli).
$ use admin --> (to change the database for using this command).
$ use ravikant --> (to create the new database).
$ show dbs --> (to show all the current databases).
$ show collections --> ( to show all the current create and previous collections).
$ db.getUsers() --> (to check the all users).
$ db.getRoles() --> (to check the created roles).
$ db.createCollection("ravikant") --> (to create the collection in database).
$ db.dropUser("username") --> (to delete the user).
$ db.dropRole("rolename") --> (to delete the role).
$ db.collectionname.drop() -->(to delete the collections).
$ currentOp() --> (to check the total number of connections are active now).
$ db.serverStatus().
$ mongosh -u admin -p Admin --authenticationDatabase admin --> (to login as a admin).
领英推荐
$ mongosh -u developer -p Password --authenticationDatabase ravikant -->(to login as a dev).
login for mongodb compass
mongodb://developer:[email protected]:27017/ravikant
admin> db.createRole({
role: "developerRole",
privileges: [{
resource: { db: "ravikant", collection: "" },
actions: ["find", "insert", "update", "remove", "createCollection", "createIndex", "collStats", "listIndexes", "dbHash", "validate"]
}],
roles: []
});
admin> db.updateUser("developer", {
roles: [{ role: "developerRole", db: "ravikant" }]
});
security:
authorization: enabled
4. Monitoring MongoDB Connections:
To monitor active connections, I utilized the following script to check and print the unique connections to MongoDB:
admin> const ops = db.currentOp().inprog; const uniqueClients = new Set(ops.map(op => op.client)); print(`Unique Connections Count: ${uniqueClients.size}`);
5. Security and Scalability Considerations:
When deploying databases, security and scalability are paramount. For MongoDB in production, it's crucial to configure:
By following these steps, I successfully deployed a fully secured and permission-controlled MongoDB instance on my cloud server, providing both admin and developer users with the appropriate level of access.
Feel free to reach out if you're interested in discussing database deployments, cloud infrastructure, or DevOps practices!
#MongoDB #DevOps #Cloud #ServerAdministration #DatabaseSecurity #DataEngineering #CloudInfrastructure #Ubuntu #DatabaseDeployment
?
Ex-DevOps QuibbleAI | Ex-DevOps Intern Learn and Build | DevOps Enthusiast | AWS | Python | Kubernetes | Terraform | Jenkins | Docker | Git/GitHub | Cloud Infrastructure | Linux
1 个月Interesting
Senior Managing Director
2 个月Ravi Kant Very interesting. Thank you for sharing
Student at Rajasthan Technical University, Kota || Training in JAVA || J2EE || Leetcode+GFG (150+) DSA || CPP || C++ programing || software developer
2 个月Very helpful ?