The following tutorial describes how to install MongoDB system Centos 8.
The whole is simple and comes down to a few simple commands wykonanaia.
In previous entries we described the installation process for Ubuntu 18.04 which is under this entry.
For starters, we create a repository:
nano /etc/yum.repos.d/mongodb.repo
its content:
[mongodb-org-4.2] name=MongoDB Repository baseurl=https://repo.mongodb.org/yum/redhat/$releasever/mongodb-org/development/x86_64/ gpgcheck=1 enabled=1 gpgkey=https://www.mongodb.org/static/pgp/server-4.2.asc
Save the file and install the same service kodonujemy:
dnf install mongodb-org
Run it and add to autostart:
systemctl start mongod
systemctl enable mongod
Check the status of services:
systemctl status mongod
Score:
? mongod.service - MongoDB Database Server Loaded: loaded (/usr/lib/systemd/system/mongod.service; enabled; vendor preset: disabled) Active: active (running) since my 2020-01-03 03:59:12 EDT; 5min ago Docs: https://docs.mongodb.org/manual Process: 737 ExecStart=/usr/bin/mongod $OPTIONS (code=exited, status=0/SUCCESS) Process: 735 ExecStartPre=/usr/bin/chmod 0755 /var / run / mongodb (code=exited, status=0/SUCCESS) Process: 732 ExecStartPre=/usr/bin/chown mongod:mongod / var / run / mongodb (code=exited, status=0/SUCCESS) Process: 726 ExecStartPre=/usr/bin/mkdir -p /var/run/mongodb (code=exited, status=0/SUCCESS) Main PID: 914 (mongod) Memory: 216.1M CGroup: /system.slice/mongod.service ??914 /usr/bin/mongod --auth -f /etc/mongod.conf Oct 28 03:58:14 centos8 systemd[1]: Starting MongoDB Database Server... Oct 28 03:58:28 centos8 mongod[737]: about to fork child process, waiting until server is ready for connections. Oct 28 03:58:28 centos8 mongod[737]: forked process: 914 Oct 28 03:59:12 centos8 mongod[737]: child process started successfully, parent exiting Oct 28 03:59:12 centos8 systemd[1]: Started MongoDB Database Server.
MongoDB to get to using the command:
mongo
Creating a user administrative MongoDB
we get to MongoDB command :
mongo
Then we move the database named admin
use admin
We issue a command to create user:
db.createUser( { user: "mongodadmin", pwd: "password123", roles: [ { role: "userAdminAnyDatabase", db: "admin" } ] } )
password123 we change, of course, to our secret password 😉
We should get the result:
Successfully added user: { "user" : "mongodadmin", "roles" : [ { "role" : "userAdminAnyDatabase", "db" : "admin" } ] }
Check your command:
show users
Score:
{ "_id" : "admin.mongodadmin", "userId" : UUID("f6e908db-e393-44a9-8c77-0fdb1c2baa0e"), "user" : "mongodadmin", "db" : "admin", "roles" : [ { "role" : "userAdminAnyDatabase", "db" : "admin" } ], "mechanisms" : [ "SCRAM-SHA-1", "SCRAM-SHA-256" ] }
Configure authentication MongoDB
By default MongoDB allows all users access to the MongoDB shell and run arbitrary commands. It is therefore recommended that you configure authentication MongoDB, to prevent other users to run commands without the required permissions.
First you need to enable authentication for MongoDB, by editing the file
nano /lib/systemd/system/mongod.service
And so we set the following line:
Environment="OPTIONS= --auth -f /etc/mongod.conf"
reload services:
systemctl --system daemon-reload
systemctl restart mongod
Now we try to enter without permission:
mongo
use admin
show users
We'll see an error
2019-10-28T04:13:15.346-0400 And QUERY [js] uncaught exception: Error: command usersInfo requires authentication : _getErrorWithCode@src/mongo/shell/utils.js:25:13 DB.prototype.getUsers@src/mongo/shell/db.js:1638:15 shellHelper.show@src/mongo/shell/utils.js:883:9 shellHelper@src/mongo/shell/utils.js:790:15 @(shellhelp2):1:1
Now we log on correctly privileges:
db.auth('mongodadmin', 'password123') show users
You should see the admin user with their roles in the following output: { "_id" : "admin.mongodadmin", "userId" : UUID("f6e908db-e393-44a9-8c77-0fdb1c2baa0e"), "user" : "mongodadmin", "db" : "admin", "roles" : [ { "role" : "userAdminAnyDatabase", "db" : "admin" } ], "mechanisms" : [ "SCRAM-SHA-1", "SCRAM-SHA-256" ] }
The guide below describes how to install KeePass on Ubuntu. Całość wykonamy za pomocą kilku poleceń…
Master PDF Editor is a comprehensive PDF program, which includes many features. Oprócz tworzenia i edycji…
Iotop jest prostym narzędziem dla systemów Uniksowych umożliwiającym monitorowanie użycia dowolnego nośnika pamięci flash/hdd/ssd w…
You can separate two or more commands with semicolons (;), Semicolon (;): służy do oddzielania…
Poniższy poradnik opisuje w jaki sposób za pomocą konsoli możemy dokonać edycji danych zdjęcia exif.…
The following guide describes how to install Rocket.Chat on Rocky Linux 8 Całość bardzo prosto zainstalujemy…