Goal
The Aim of the Blog is to setup MongoDB on Oracle Cloud Infrastructure Classic , Open the required ports and access it from outside – we will use MongoDB VM Image from Bitnami to make it easier
Bitnami Image
Login to https://oracle.bitnami.com , Select MongoDB Image from this URL https://bitnami.com/stack/mongodb , and Launch Instance, I will select Ubuntu OS with Default Security List that opens SSH port 22.
Select on Size and Click Create
This should be easiest thing to do , check the official documentation link
SSH to Mongo DB Instance
Download Private and Public Keys , .pem and .ppk files from the Bitnami Console into a folder , change permission of .pem file and SSH to Public IP address
chmod 700 bitnami-opc-a457995.pem ssh -i bitnami-opc-a457995.pem [email protected]
Connect to Mongo DB and Create few records
[email protected]:~$ mongo admin --username root -p MongoDB shell version v3.6.3 Enter password: connecting to: mongodb://%2Fopt%2Fbitnami%2Fmongodb%2Ftmp%2Fmongodb-27017.sock/admin MongoDB server version: 3.6.3 Welcome to the MongoDB shell. For interactive help, type "help". For more comprehensive documentation, see http://docs.mongodb.org/ Questions? Try the support group http://groups.google.com/group/mongodb-user Server has startup warnings: 2018-03-13T08:32:56.958+0000 I STORAGE [initandlisten] 2018-03-13T08:32:56.958+0000 I STORAGE [initandlisten] ** engine 2018-03-13T08:32:56.958+0000 I STORAGE [initandlisten] ** > db = db.getSiblingDB('admin') admin > db = db.getSiblingDB('employeedb') employeedb > db.products.insert( { item: "card", qty: 15 } ) WriteResult({ "nInserted" : 1 }) > db.products.insert( { _id: 10, item: "box", qty: 20 } ) WriteResult({ "nInserted" : 1 }) > db.products.insert( ... [ ... { _id: 11, item: "pencil", qty: 50, type: "no.2" }, ... { item: "pen", qty: 20 }, ... { item: "eraser", qty: 25 } ... ] ... ) BulkWriteResult({ "writeErrors" : [ ], "writeConcernErrors" : [ ], "nInserted" : 3, "nUpserted" : 0, "nMatched" : 0, "nModified" : 0, "nRemoved" : 0, "upserted" : [ ] }) > db.products.find({item : "box"}).forEach(printjson); { "_id" : 10, "item" : "box", "qty" : 20 } > exit bye
Accessing MongoDB Outside the VM and from Public Network
Most often the Applications that talk to MongoDB can reside outside the actual MongoDB Instance, so we need to Open the Public Port 27017 in the Network Layer
Opening Port 27017 at Oracle Cloud Network Layer
Open the Compute Classic URL
https://computeui.us.oraclecloud.com/mycompute/console/view.html?page=instances
Locate the Instance that is Matching the Public IP and Select it
Make a Note of Security List Name , in our case it is Bitnami-mongodb-9ef2
Click on the Network Tab, Select Security Application and Create New Security Application
Now Create Security Rule to Map to the newly created security Application , and also make 2 important selections Security IP List is Public Internet and Security List should be the one that we noted earlier Bitnami-mongodb-9ef2
Check the highlighted security rule
this should open port 27017 for public internet access
Please Note : it is not recommended to open database ports for public internet access
Reality Check Access the Application from Workbench
Download any IDE to connect to MongoDB instance like https://studio3t.com
Install Studio3T
Create Connection
PublicIP Address : Port 27101
Root Password will be available in Bitnami MongoDB Instance created page
View the Key Values that we had created sometime back
Author Madhusudhan Rao