Install MongoDB in Amazon Linux VM:
Step-1: Create a Linux virtual machine in AWS.
Step-2: After creating it connect it through the putty or mobaXterm.
Step-3: Run “sudo su“ to get all the root privileges.
1 2 |
[ec2-user@ip-172-31-35-250 ~]$ sudo su [root@ip-172-31-35-250 ec2-user]# |
Step-4: To know about the version and its details which is required for installing MongoDB. run “uname -srm”. From this choose the platform in step5.
1 2 |
[root@ip-172-31-39-148 ec2-user]# uname -srm Linux 6.1.41-63.114.amzn2023.x86 64 x86 64 |
Step-5: Go to the link “https://www.mongodb.com/try/download/community” then choose the platform that you need like Amazon Linux, RedHat and package as tgz or server.
Step-6: After choosing the platform and package copy the link which is beside download.
Step-7: Run “curl -O https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-amazon2023-7.0.0.tgz”. It will connect to the site and download the files from the given site.
1 2 3 4 |
[root@ip-172-31-35-250 ec2-user]# curl -O https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-amazon2023-7.0.0.tgz % Total % Received % Xferd Average Speed Time Time Time Current Dload Upload Total Spent Left Speed 100 80.7M 100 80.7M 0 0 60.5M 0 0:00:01 0:00:01 --:--:-- 60.5M |
It shows that the software we download has a size of 60.5 MB.
Step-8: Run “ll -lhtr” to get the file name and its size which used to install it.
1 2 3 |
[root@ip-172-31-35-250 ec2-user]# ll -lhtr total 81M -rw-r--r--. 1 root root 81M Aug 29 05:58 mongodb-linux-x86_64-amazon2023-7.0.0.tgz |
Step-9: To install the files that you have downloaded Run the below command “tar -zxvf mongodb-linux-x86_64-amazon2023-7.0.0.tgz”. This installs the software.
1 2 3 4 5 6 7 8 |
[root@ip-172-31-35-250 ec2-user]# tar -zxvf mongodb-linux-x86_64-amazon2023-7.0.0.tgz mongodb-linux-x86_64-amazon2023-7.0.0/LICENSE-Community.txt mongodb-linux-x86_64-amazon2023-7.0.0/MPL-2 mongodb-linux-x86_64-amazon2023-7.0.0/README mongodb-linux-x86_64-amazon2023-7.0.0/THIRD-PARTY-NOTICES mongodb-linux-x86_64-amazon2023-7.0.0/bin/install_compass mongodb-linux-x86_64-amazon2023-7.0.0/bin/mongod mongodb-linux-x86_64-amazon2023-7.0.0/bin/mongos |
Step-10: Change directory to the blue color text which is highlighted in 8th step to do this run “cd mongodb-linux-x86_64-amazon2023-7.0.0”.
1 2 |
[root@ip-172-31-35-250 ec2-user]# cd mongodb-linux-x86_64-amazon2023-7.0.0 [root@ip-172-31-35-250 mongodb-linux-x86_64-amazon2023-7.0.0]# |
Step-11: List all the files inside that directory by running “ll -lhtr” command.
1 2 3 4 5 6 7 |
[root@ip-172-31-35-250 mongodb-linux-x86_64-amazon2023-7.0.0]# ll -lhtr total 176K -rw-r--r--. 1 ec2-user ec2-user 2.0K Aug 1 18:22 README -rw-r--r--. 1 ec2-user ec2-user 17K Aug 1 18:22 MPL-2 -rw-r--r--. 1 ec2-user ec2-user 30K Aug 1 18:22 LICENSE-Community.txt -rw-r--r--. 1 ec2-user ec2-user 120K Aug 1 18:22 THIRD-PARTY-NOTICES drwxr-xr-x. 2 root root 57 Aug 29 06:07 bin |
Step-12: Change the directory to bin by running “cd bin/” and to list all the files run “ll -lhtr” command.
1 2 3 4 5 6 7 8 9 10 |
[root@ip-172-31-35-250 mongodb-linux-x86_64-amazon2023-7.0.0]# cd bin/ [ec2-user@ip-172-31-35-250 bin]$ ll-thtr total 297M -rwxr-xr-x. 1 ec2-user ec2-user 15K Aug 18:22 install_compass -rwxr-xr-x. 1 ec2-user ec2-user 174M Aug 1 19:55 mongod -rwxr-xr-x. 1 ec2-user ec2-user 124M Aug 1 19:56 mongos -rw------- 1 root root 21K Aug 29 06:12 mongod.log.2023-88-29T06-12-14 drwxr-xr-x. 4 root root 16K Aug 29 06:14 datadir -rw------- 1 root root 17K Aug 29 06:14 mongod.log |
Step-13: Now create one directory by running “mkdir daata”. which is used to store all the database files in the directory which we create.
Step-14: Run “. /mongod -dbpath dataa/ –port 27017 –logpath ./mongod.log–fork”.to connect to MongoDB through the given port number and save the files in the given path.
1 2 3 |
about to fork child process, waiting until server is ready for connections. forked process: 3148 child process started successfully, parent exiting |
The child process is running shows that our service is running in the background.
Step-15: Run “ ps -ef | grep mongo” to know if the service is running or not.
1 2 3 |
[root@ip-172-31-35-250 dataa]# ps -ef | grep mongo root 3735 1 0 14:37 ? 00:00:14./mongod -dbpath dataa/-port 27017 -logpath /mongod.log-fork root 5420 5140 0 15:27 pts/2 00:00:00 grep-color-auto mongo |
Step-16: Now run “mongo” or run “. /mongo –port 27017” to start and work in MongoDB.
Author : Teja |
LinkedIn : https://www.linkedin.com/in/teja-sai-nadh-reddy-tatireddy-048882201
Thank you for giving your valuable time to read the above information. Please click here to subscribe for further updates.
KTExperts is always active on social media platforms.
Facebook : https://www.facebook.com/ktexperts/
LinkedIn : https://www.linkedin.com/company/ktexperts/
Twitter : https://twitter.com/ktexpertsadmin
YouTube : https://www.youtube.com/c/ktexperts
Instagram : https://www.instagram.com/knowledgesharingplatform
Note: Please test scripts in Non Prod before trying in Production.