MongoDB – Create New User

After the MongoDB installation, I continued with creating a new root user which carries the admin right with password. It is recommended to secure the database with password all the time.

To do so, I used the Mongo command shell to run the commands.
1. Create the root user.

db.createUser({user:"admin", pwd:"admin123", roles:[{role:"root", db:"admin"}]})

The command prompt will show success message once the new user is created.

2. Enable Mongodb authentication
Edit the Mongodb service file ‘/lib/systemd/system/mongod.service’ with your editor on the ‘ExecStart’ line 9, add the new option ‘–auth’.

ExecStart=/usr/bin/mongod --quiet --auth --config /etc/mongod.conf

And here is where I faced the same problem again, I am unable to edit the file using the text editor because of the permission. If you able to edit, then continue with below steps.

3. Reload the systemd service using systemd daemon-reload
4. Restart MongoDB service.
5. Connect to the Mongodb shell with this command:
mongo -u admin -p admin123 –authenticationDatabase admin

Fill in using the userID and password set when we create new root user. Even I did not change the file, mongod.service, I am still able to connect to the MongoDB with my own userID and password. Below, showed the success login.

Lastly, you can show or list the databases by using command,

show dbs
Advertisements

MongoDB – Installation

Today I am going to try the MongoDB installation on my Linux machine which I installed in my VMware. I am not going to do the same installation on my Windows’ laptop. I am expected to learn and workaround with the MongoDB in my virtual machine only.

Let us get started, it is simple installation and just a small confusion on one of the configuration parts, not to worry about it too much at this point. As I googled how to install MongoDB on Ubuntu, there is a list of guides to follow and I personally followed these two links:
1. From the MongoDB website: https://docs.mongodb.com/v3.2/tutorial/install-mongodb-on-ubuntu/
2. From a tutorial website: https://www.howtoforge.com/tutorial/install-mongodb-on-ubuntu-16.04/

Both are guiding us on how to install on the Ubuntu 16.04. Just follow the commands given in the website and I will just briefly mention what I do on each step.

1. Import the public key.
2. Create source list file MongoDB. I used below command, but using my Ubuntu version, Xenial,

echo "deb http://repo.mongodb.org/apt/ubuntu xenial/mongodb-org/3.2 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-3.2.list

Else, the default command is,

echo "deb http://repo.mongodb.org/apt/ubuntu "$(lsb_release -sc)"/mongodb-org/3.2 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-3.2.list

3. Update the repository.
4. Install MongoDB.
At this step, it asks us to create a new mongodb systemd service file in the ‘/lib/systemd/system’ directory. Below is the instruction:
Go to that directory and create the new mongodb service file ‘mongod.service’ with vim.

cd /lib/systemd/system/
vim mongod.service

In the edit mode (command prompt), I am unable to edit anything in which I should paste the setting on it and save. I have no idea how the vim works. Maybe you can enlighten me on this part.

I tried to use the text editor and I am unable to save the file because of permission issue. I did not change the file, anyway, and proceed to update the systemd service using the given command line.
5. Start Mongodb and add it as service to be started at boot time.
6. Now check that Mongodb has been started on port 27017 with the netstat command.

You can check the MongoDB’s log at /var/log/mongodb/mongod.log and the port configured in /etc/mongod.conf, 27017 by default.

The installation is completed. Few commands to be remember:
1. Start service – sudo service mongod start
2. Stop service – sudo service mongod stop (or control-C)
3. Restart service – sudo service mongod restart
4. Go to Mongo shellmongo

Ubuntu 16.04 – Unable to Set Singapore Timezone

Upon the Ubuntu 16.04 installation completion on my machine, I realized it was showing Jakarta’s timezone. I repeated the same installation in my virtual machine and it showed Los Angelas’ timezone. Oddly, it is an automatically detected from the Internet.

I tried to enter ‘Singapore’ under the Location, however, it failed to show the correct Asia/Singapore as shown below.

I became clueless why Singapore was not listed in the timezone selection. The closest timezone will be Kuala Lumpur or Johor state in Malaysia. I tried to pick the location from the map which was quite hard because Singapore is a very tiny country in the world map. I am so sorry, I could not input Singapore and I have to use Kuala Lumpur, Malaysia.

If you have the solution on this issue, kindly share with me. Thank you in advanced.

First Linux Experience

The new environment requires me to work using the Linux OS – Ubuntu. It is my first time using the Linux in my working life and it is my second time using Linux OS. The first time was during my college time when we were working on the group assignment to introduce a Linux OS. Back then, I used Suse Linux. I barely have any memories of using the command lines and it is going to be a challenge for me.

Without much knowledge, I dived into the Ubuntu installation from the flash drive on a new machine which just delivered to me this morning. However, I have mistakenly gone into the Windows environment before I started the installation from the USB

I got a help from my colleague. He tried to restart the laptop with an attempt to boot to Advanced Setup from Windows. Make sure the USB is connected to the laptop. I saw he pressed ‘Shift’ and restart.

For Windows 10, we have to change the UEFI Firmware settings to boot device from the USB. It goes into this screen and select ‘Use a device’. Select the USB to be used and the computer will now restart and boot from the selected USB drive.

Some guides can refer here too, https://www.tenforums.com/tutorials/21756-boot-usb-drive-windows-10-pc.html.

However, for my case, after applied the new UEFI firmware setting, it restarted and directly booted up from the USB whereby the Ubuntu installation took place. I

Since my laptop is using the Windows OS, I installed the VMware Workstation in order to allow myself to install the same Ubuntu version on the virtual machine. I feel it is more easy for my learning or do my work if I have the similar environment on my laptop.

Before I begin my setup to create new virtual machine in the VMware Workstation, I downloaded the Ubuntu 16.04 disk image from the Ubuntu website, https://www.ubuntu.com/download/desktop.

To create a new virtual machine, it is simple by following the step by step in the VMware. There is an online guide to follow too, https://betanews.com/2012/08/29/how-to-install-ubuntu-on-vmware-workstation/. I find the step by step setup is easy and fast.

If you wish to customize the setting, you can do it by clicking the ‘Customize Hardware’ button. It prompts up to the screen above. I increased the RAM to 2 GB instead of the default 1 GB and keep the default 20 GB for hard disk space.

Complete the installation with naming the virtual machine and personalized the user setting with username and password. You can choose to ‘Power On’ the virtual machine and start using it before hitting the ‘Finish’ button. This is how the Ubuntu’s interface looks like.

Everything is well setup and working fine. I pretty like the user interface with the task bar on the left, maroon in colour and simple user interface. Initially, I fear that I have to use command prompt all the way to do my work.