In this blog post, lets see how to setup and configure MongoDB in Linux environment (I am using CENTOS in my lab, but the steps to follow are exactly same for RHEL) and also how to spin up a MongoDB container(s), I will be using Dockers for all my containers.
Setup MongoDB on a Linux machine
Download the mongoDB repository file or create it manually in yum.repos.d folder with the content as shown below.
Go to the official MongoDB documentation for more specific details on how to get a specific release or how to pin a specific release.
Now that I’ve my repository configured, All I have to do is to run below command.
sudo yum install -y mongodb-enterprise
Great, At this point I’ve installed MongoDB enterprise on my machine, but it is in stopped state as shown below and I had to bring it online.
That is all it takes to setup MongoDB on a Linux machine with default values. In most of the cases we may want to change the default paths etc per requirements and standards in place. Well, let’s check them out and customize per our needs…
/var/lib/mongo – This is where your database files will be created.
Note: These are Error log files, don’t get confused with log files term that we use in our SQL Server world 🙂 In Mongo, write ahead logging is achieved by something called journaling and journal files will be created in a separate folder under “/var/lib/mongo”
This is the file which holds all the paths, configuration settings, parameter values and what not. There are hundreds of things that can be configured, MongoDB official documentation is your best friend here.
Create a MongoDB Docker container
Note: Docker run will also take care of pulling the image if you don’t have it. Or you can issue docker pull and then a docker run….It’s up to you.
docker run -d -p 27017:27017 -v data: /mongo/data/ mongo
-p : mapped local port 27017 on my host to mongodb def port 27017.
Note: I have mongodb client tools already installed on this machine.