<\/span><\/h2>\n\n\n\nFirst, log in to your CentOS 8 server via SSH as the root user:<\/p>\n\n\n\n
ssh root@IP_Address -p Port_number<\/pre>\n\n\n\nYou will need to replace \u2018IP_Address\u2018 and \u2018Port_number\u2018 with your server\u2019s respective IP address and SSH port number. Additionally, replace \u2018root\u2019 with the username of the admin account if necessary.<\/p>\n\n\n\n
Before starting, you have to make sure that all CentOS packages installed on the server are up to date. You can do this by running the following commands:<\/p>\n\n\n\n
dnf update -y<\/pre>\n\n\n\n<\/span>Step 2: Install MongoDB on CentOS 8<\/span><\/h2>\n\n\n\nBy default, MongoDB does not included in the CentOS 8 standard repo. So you will need to create a MongoDB repo for that. You can create it with the following command:<\/p>\n\n\n\n
nano \/etc\/yum.repos.d\/mongodb-org.repo<\/pre>\n\n\n\nAdd the following lines:<\/p>\n\n\n\n
[mongodb-org]
name=MongoDB Repository
baseurl=https:\/\/repo.mongodb.org\/yum\/redhat\/$releasever\/mongodb-org\/4.4\/x86_64\/
gpgcheck=1
enabled=1
gpgkey=https:\/\/www.mongodb.org\/static\/pgp\/server-4.4.asc<\/p>\n\n\n\n
Save and close the file. Then, install the MongoDB by running the following command:<\/p>\n\n\n\n
dnf install mongodb-org -y<\/pre>\n\n\n\nAfter installing MongoDB, enable the MongoDB service to start at system reboot:<\/p>\n\n\n\n
systemctl enable mongod --now<\/pre>\n\n\n\nNext, you can verify the status of MongoDB with the following command:<\/p>\n\n\n\n
systemctl status mongod<\/pre>\n\n\n\nYou should see the following output:<\/p>\n\n\n\n
\u25cf mongod.service - MongoDB Database Server\n Loaded: loaded (\/usr\/lib\/systemd\/system\/mongod.service; enabled; vendor preset: disabled)\n Active: active (running) since Sat 2020-12-12 02:04:43 EST; 4s ago\n Docs: https:\/\/docs.mongodb.org\/manual\n Process: 3265 ExecStart=\/usr\/bin\/mongod $OPTIONS (code=exited, status=0\/SUCCESS)\n Process: 3264 ExecStartPre=\/usr\/bin\/chmod 0755 \/var\/run\/mongodb (code=exited, status=0\/SUCCESS)\n Process: 3262 ExecStartPre=\/usr\/bin\/chown mongod:mongod \/var\/run\/mongodb (code=exited, status=0\/SUCCESS)\n Process: 3260 ExecStartPre=\/usr\/bin\/mkdir -p \/var\/run\/mongodb (code=exited, status=0\/SUCCESS)\n Main PID: 3268 (mongod)\n Memory: 59.8M\n CGroup: \/system.slice\/mongod.service\n \u2514\u25003268 \/usr\/bin\/mongod -f \/etc\/mongod.conf\n\nDec 12 02:04:42 centos8 systemd[1]: Starting MongoDB Database Server...\nDec 12 02:04:42 centos8 mongod[3265]: about to fork child process, waiting until server is ready for connections.\nDec 12 02:04:42 centos8 mongod[3265]: forked process: 3268\nDec 12 02:04:43 centos8 mongod[3265]: child process started successfully, parent exiting\nDec 12 02:04:43 centos8 systemd[1]: Started MongoDB Database Server.\n<\/pre>\n\n\n\nNext, connect to the MongoDB console with the following command:<\/p>\n\n\n\n
mongo<\/pre>\n\n\n\nNext, verify the MongoDB version with the following command:<\/p>\n\n\n\n
> db.version()<\/pre>\n\n\n\nOutput:<\/p>\n\n\n\n
4.4.2\n<\/pre>\n\n\n\nNext, exit from the MongoDB console with the following command:<\/p>\n\n\n\n
> quit()<\/pre>\n\n\n\n<\/span>Step 3: Install MongoDB on Ubuntu 20.04<\/span><\/h2>\n\n\n\nFirst, install the required dependencies using the following command:<\/p>\n\n\n\n
apt-get install curl gnupg2 -y<\/pre>\n\n\n\nNext, add the MongoDB GPG key and repository with the following command:<\/p>\n\n\n\n
curl -fsSL https:\/\/www.mongodb.org\/static\/pgp\/server-4.4.asc | apt-key add -\necho \"deb [ arch=amd64,arm64 ] https:\/\/repo.mongodb.org\/apt\/ubuntu focal\/mongodb-org\/4.4 multiverse\" | tee \/etc\/apt\/sources.list.d\/mongodb-org-4.4.list<\/pre>\n\n\n\nNext, update the repository and install the MongoDB with the following command:<\/p>\n\n\n\n
apt-get update -y\napt-get install mongodb-org -y<\/pre>\n\n\n\nOnce the installation is finished, start the MongoDB service with the following command:<\/p>\n\n\n\n
systemctl start mongod<\/pre>\n\n\n\n