Installing Ubuntu MongoDB 22.04
Today I present a guide so that in a few steps install MongoDB on our server with Ubuntu.
Feel free to read.
At the beginning we make an update repositories
1 | apt-get update |
Then we install MongoDB
1 | apt-get install -y mongodb |
Check the server status MongoDB command:
1 | sudo systemctl status mongodb |
the result of the:
1 2 3 4 5 6 7 8 | ● mongodb.service - An object/document-oriented database Loaded: loaded (/lib/systemd/system/mongodb.service; enabled; vendor preset: enabled) Active: active (running) since Sat 2018-05-26 07:48:04 UTC; 2min 17s ago Docs: man:mongod(1) Main PID: 2312 (mongod) Tasks: 23 (limit: 1153) CGroup: /system.slice/mongodb.service └─2312 /usr/bin/mongod --unixSocketPrefix=/run/mongodb --config /etc/mongodb.conf |
Which indicates that the server is running correctly.
To confirm this connection we make a diagnostic command:
1 | mongo --eval 'db.runCommand({ connectionStatus: 1 })' |
We should get the result as below:
1 2 3 4 5 6 7 8 9 | MongoDB shell version v3.6.3 connecting to: mongodb://127.0.0.1:27017 MongoDB server version: 3.6.3 { "authInfo" : { "authenticatedUsers" : [ ], "authenticatedUserRoles" : [ ] }, "ok" : 1 |
If you use the firewall must add a port to exceptions in the case of UFW:
1 | sudo ufw TWOJ ADRES IP/32 port np: 27017 |
Command
1 | sudo ufw status |
This will allow us to verify whether a connection on this port is open:
1 2 3 4 5 6 7 8 | Status: active To Action From -- ------ ---- OpenSSH ALLOW Anywhere 27017 ALLOW Anywhere OpenSSH (v6) ALLOW Anywhere (v6) 27017 (v6) ALLOW Anywhere (v6) |
To allow remote connection, edit the file:/etc/mongodb.conf
1 | nano /etc/mongodb.conf |
And set:
1 2 3 4 5 6 7 | ... logappend=true bind_ip = 127.0.0.1,IP TWOJEGO SERWERA #port = 27017 ... |