MongoDB:
MongoDB is an open-source document database that provides high performance, high availability, as well as automatic scaling. MongoDB obviates the involve for an Object Relational Mapping (ORM) to facilitate development.- Basic MongoDB admin related commands:
Run below ascendance mongo to banking company gibe mongodb version
root@US16: # mongo MongoDB crunch version v3.6.0 connecting to: mongodb://127.0.0.1:27017 MongoDB server version: 3.6.0
2-List all the database: To listing all the DBs hitting ascendance show dbs;
> show dbs; admin 0.000GB config 0.000GB local 0.000GB >
3-Enable MongoDB authentication:
By default, mongodb installation convey opened upwards access to the shell. that hateful anyone tin forcefulness out run the ascendance as well as modify the dbs.
By default, mongodb installation convey opened upwards access to the shell. that hateful anyone tin forcefulness out run the ascendance as well as modify the dbs.
Let's enable authentication : Follow the steps below
3A-Create a user amongst total privileges: Run the next command
use admin db.createUser({user:"admin", pwd:"redhat", roles:[{role:"root", db:"admin"}]})
Command output would hold upwards similar this:
Now leave of absence from the mongo shell- type ascendance exit
3B- Stop mongod service
root@US16: # systemctl halt mongod.service
3C-Modify /lib/systemd/system/mongod.service :
root@US16: # vi /lib/systemd/system/mongod.service
Append --quiet --auth syntax inwards trouble starting fourth dimension with
ExecStart=/usr/bin/mongod --quiet --auth --config /etc/mongod.conf
[Service] User=mongodb Group=mongodb ExecStart=/usr/bin/mongod --quiet --auth --config /etc/mongod.conf # file size LimitFSIZE=infinity
Your ExecStart trouble should hold upwards like
Save as well as Exit from the file
4- Reload service daemon: Run the ascendance below
root@US16: # systemctl daemon-reload
5- Start mongo service:Run the ascendance below
root@US16: # systemctl starting fourth dimension mongod.service
6- Check mongo service status: We involve to validate mongo service afterward applied the changes let's banking company gibe mongo service condition using below command.
root@US16: # systemctl condition mongod.service
7- Everything hold off adept as well as mongo service is dorsum authentication has enabled, allow validate access.
7A- Access mongo crunch amongst authentication
root@US16: # mongo -u root -p
We are successfully able to login amongst username as well as password!
8- List all users: Login to mongo crunch amongst admin user
select database admin
select database admin
> utilisation admin
Execute the next ascendance show users; to listing users
> demo users; { "_id" : "test.admin", "user" : "admin", "db" : "test", "roles" : [ { "role" : "root", "db" : "admin" } ] } { "_id" : "test.amar", "user" : "amar", "db" : "test", "roles" : [ { "role" : "root", "db" : "admin" } ] } >
In the higher upwards out at that spot are 2 user available highlighted inwards cerise color
9- Check electrical flow selected database:
To banking company gibe electrical flow choose database utilisation ascendance db
> db admin >
10- Check electrical flow selected database's collection:
To banking company gibe electrical flow choose database's collection utilisation ascendance show collections
> demo collections system.users system.version >
11- Update password for existing user:
Use the next ascendance to update existing user's password
> utilisation admin switched to db admin > db.changeUserPassword("amar", "newpassword") >
Where "use admin" ascendance to choose database as well as db.changeUserPassword("username","Newpassword")
Tidak ada komentar:
Posting Komentar