Lab - initiate a replica set locally

How do i create a key file?
Where is that directory located? do i have to make it?
How do i set up the config files?
Between last weeks lab and this, I am having a lot of trouble. What is my deficiency? Is there a base of knowledge I am missing? I was told all I would need is the introductory course; which I finished.

Hi Aaron_30116,

Sorry that you are having so much problem running through this lab. Although, the steps to generate keyFile are mentioned in the Lab:

vagrant@m103:~$ sudo mkdir -p /var/mongodb/pki
vagrant@m103:~$ sudo chown vagrant:vagrant -R /var/mongodb
vagrant@m103:~$ openssl rand -base64 741 > /var/mongodb/pki/m103-keyfile
vagrant@m103:~$ chmod 600 /var/mongodb/pki/m103-keyfile

Run above commands from inside the Vagrant

You must have learnt on how to create a configuration file for mongod in Chapter 1: Configuration File. Its the same here except you have to create 3 configuration files for each node. You have to create your own directory where you want to place this or you can just create files in your current directory.

  • Suppose you create them in your current working directory by the name “mongod-1.conf”, then you run mongod:

    vagrant@m103:~$ mongod -f mongod-1.conf

Making sure you have mongod-1.conf file in the same directory, else you give the full path like this:

 vagrant@m103:~$ mongod -f /home/vagrant/mongod-1.conf

I hope it clears. Let me know if you still need more information.


my trouble is creating the config files and saving them in the correct directory. How is that done?

Hi Aaron,

You can do this by changing your current directory to the desired one using cd command. Suppose you have a directory called “/home/vagrant/config_files”, then:

  vagrant@m103:~$ cd /home/vagrant/config_files

Then, create a file using vi editor. The steps for the file editing and creating are mentioned here: How to write in the config file

Let me know if it helps!