Back to Top Page


Make sure your Raspberry Pi is connected to the internet and run these commands as root to update the freshly installed OS:

These commands may take some time, depending on your internet connection; especially the second one.

One important note for the rest of this tutorial:
When commands are mentioned, they appear with one of these prompts:

In the first case, it means the command should be run as root, in the second a standard user is enough.

If for some reason you do not want to log in as root, then you can always add sudo at the beginning of the command to execute it. For example instead of:

you may use:

This trick will work as long as the user you are logged as is a member of the sudoers. This should be the case if you made a standard installation, for example by following the instructions just given, and are using the ubuntu account.

Next, run these commands to access the software repository holding the mongodb package:


Then run this command to include the new repository in the local list and make it usable:


You can now install the mongodb package on this machine, by doing:


At this point you will have all the software needed to use mongodb.

For the purpose of this tutorial, I use two USB sticks to store the data. I chose two inexpensive 16GB USB keys, but any size should work. If you have some serious use in mind you may want to use high capacity hard disks or SSD drives instead.

To format the sticks, plug both into the two USB-3 ports (the blue ones) and use the following commands (WARNING! Be sure to use only the proper drive letters (here sda1 and sdb1); so you don't format anything else by mistake! In your case the letters may be different!):


We used the XFS file system in the two last commands, because it is the one recommended with MongoDB. For more details on this subject, see this document (Section: Platform Specific Considerations).

Next, set your
file to have the two storage devices we just formatted, automatically mounted at the right point as soon as we power on the Raspberry Pi computer. I assume the USB sticks (or whatever you have chosen instead), will stay plugged in permanently.

Before touching the
file, run these commands to set the two mount points that you need:


Now you can modify the
file to suit your needs. This part is simple, just add the two lines below at the end of it.


To have your storage devices properly mounted, once
is updated and saved, you can use the mount command or (if you are not yet familiar with linux) you can just reboot your Raspberry Pi by running:


To check if all is OK, running this command:

should show this kind of result:

When your storage devices are mounted, run the following command to create the directories for the two future mongodb data bearing nodes that you will set on the Pi.


Next, set the ownership of the directories to easily accomodate your needs for the mongod servers:

Another note for the rest of this tutorial:
The commands shown in this color should only be run on the Pi where you decide to set the arbiter:


Now prepare the systemd service files.

The mongodb package installation you did earlier, set up a default stand alone instance of mongod as a systemd service. Though not enabled, there is already a file on the Raspberry Pi:

The two files you need will be based on it, though modified to your needs. Here is how to build them:

The two files are ready to be used:


There is one more file ready to be used:


When you finish the preparation later, you will only need to start the systemd services.

Before moving on, create a directory which will be useful in future steps. The mongodb package installation that you did previously created a user called mongodb. It has no shell and no home directory, and is meant to run the mongod process started by systemd. Create a home directory for this user:


At this stage you need to make some security related choices before moving on to finish this tutorial. Here are the three options: Your best choice depends on the reason why you are reading this.
If you see it as a way to study, then I think you should probably check out all the options, in the order they come up (that is by order of increasing complexity).
On the other hand, if you are referring to this document in order to get something done, then make the most adequate choice for your needs.

In any case, bear in mind that this is only a tutorial to get you started; where I share what I know. It is by no mean a guide to build a bulletproof secure MongoDB installation. If security is a concern for you, definitely look for more in depth information on the subject.


No Security

Key-File based Security

X.509 based Security