Monday, December 31, 2018

Happy New Year 2019!!!

We are very near (10 minutes) to the new year, I wanna say everybody "Happy New Year 2019". Since this blog is my technical blog, I am gonna write my technical experience. So far I have not written any such new year resolution in a technical field. Today, suddenly, something came up into my mind, why not write new year resolutions and see which are fulfilled after one year.

1) GIT = Thorough Learning
2) Gradle = Thorough Learning
3) NodeJS = Implement RestAPI (with NoSQL DB)
4) NoSQL(MongoDB) (partly from professional project)
5) ReactJS
6) Docker
7) RestAPI (Server & Client) (from professional project)
8) WebSocket Server & Client (Spring & NodeJS) (from professional project)
9) Python(with Tensorflow)
10) Hobby Projects in Arduino & Raspberry PI: Implement above technologies in this projects
11) Jenkins
12)Spring Boot: (from professional project)


The fireworks are becoming louder and louder. Oh, just 2 minutes now. I gotta go to watch fireworks!

I am back and its already 2019! Lets welcome 2019.










Sunday, December 9, 2018

MongoDB Walkthrough

INTRODUCTION

MongoDB is a quite popular no-SQL database system. In this article, I am going to write something about this database system. Yes, no-SQL databases are meant for performance and scalability, however, like relational databases, there exists no relation between tables or collections in the database.

MongoDB is super easy, can be run in a single host, and data is stored in document format(as JSON objects) which makes very easy to analyze or export. It provides a nice client GUI tool called "MongoDB Compass".  The storage of data is transparent in the sense that we can copy the database and reuse it. Also, there are flexibilities regarding the log files, data files, and config files.

I have used another alternative no-SQL database called Cassandra, which is also powerful and popular. Cassandra, however, requires more resources than MongoDB. Also, I could not get any better GUI client tools. Configuration is also a bit different compared to MongoDB. Cassandra is Java-based, MongoDB is C++ based.

INSTALLATION:

There are methods to install:

1) Using Debian file available from

https://repo.mongodb.org/apt/ubuntu/dists/xenial/mongodb-org/4.0/multiverse/binary-amd64/mongodb-org-server_4.0.4_amd64.deb

2) Using Terminal

sudo apt install mongodb-server
sudo apt install mongodb-clients

3) Using installation files from

http://downloads.mongodb.org/linux/mongodb-linux-x86_64-ubuntu1604-v4.0-latest.tgz

CONFIGURATION

The above mentioned two methods are quite straightforward, do not basically need any configuration.
I am writing the configuration of installation step 3 mentioned above.

# After downloading, extract the file and place contents into /opt/mongodb. Create a short link of the original extracted folder into /etc/mongodb.

# Set /opt/mongodb/bin as PATH variable so that we can directly run MongoDB commands.

# Create a folder /data/db
sudo mkdir -p /data/db

# Start Server

sudo mongod --dbpath /data/db --logpath /var/log/mongodb/mongod.log --fork

or create a config file /etc/mongod.conf with the following contents:

# mongod.conf
systemLog:
 destination: file
 path: "/var/log/mongodb/mongod.log"
 logAppend: true
storage:
 journal:
  enabled: true
processManagement:
 fork: true 
net:
 bindIp: 0.0.0.0
 port: 27017

And run the following command:

sudo mongod -f /etc/mongod.conf


# Stop Server

sudo mongod --shutdown

# Change bind address

The default is localhost can connect to the server, and any connections from outside are blocked. So, we need to change the bind address. 

We change the file /etc/mongod.conf created above step. 

Default is:

net:
  bindIp: 127.0.0.1

Change it to

net:
  bindIp: 0.0.0.0 # allow connections from anywhere

# Configure autostart

Everytime system restarts, the server should also start. We define a cronjob for that(/etc/cron.d/mongodb) with the following content:

@reboot root sleep 60 && /opt/mongodb/bin/mongod -f /etc/mongod.conf

We have defined one minute(60 seconds) sleep before starting mongodb server.

An alternative will be to create a service, and we can enable service to start at the time system starts.

CLIENTS:

1. Command Line Tool: mongo 

We can connect using mongo. Mongo uses default values to connect to the server. There are several options for this command.

After running the command, we go into the environment we can run MongoDB commands to access the database and carry out several dataset related operations.

Sample operations:
a. Connect to remote mongodb server
    mongo --host server[:port]
                           or
    mongo "mongodb://server:port"

b. Select database

  use database

c. Authenticate

    db.auth(user,password)     


2. GUI Administration: MongoDB Compass

This is a nice GUI tool, we can carry out operations on collections and documents using this nice GUI tool.

3. Create a user

Using the mongo command-line tool, we create a user.
use admin
db.createUser(
  {
    user: "myUserAdmin",
    pwd: "abc123",
    roles: [ { role: "userAdminAnyDatabase", db: "admin" }, "readWriteAnyDatabase" ]
  }
)

We have to provide option --auth in mongod command to enable authorization. 

Or add the following line in the /etc/mongod.conf file:

security:

 authorization: enabled

Saturday, December 8, 2018

Path Variable in Ubuntu System


The paths defined in Ubuntu or any operating systems are searched to find out any commands given in command line terminal. If a program is installed from Debian(.deb) or windows installer(.exe), then the installer defined the path automatically. 

If we have not packaged installer, we get all files in a folder with a bin directory inside it with all executables. The bin folder contains executables should be available from the terminal, otherwise, we have to go into the executable location to execute the binary files.

There are two methods we can define path variable in Linux system (Actually, I tested it with Ubuntu 18.04 and 16.04, other Linux systems should also work.)

Method 1: User-specific path variable. 

Each user can define their own path variable. The path to define path variable is 
~/.bashrc

export PATH=/path/to/bin:$PATH

Then the following command makes it effective. 

$ source ~/.bashrc 

Or we can restart the terminal to take effect. 


Method 2: System path variable 

 This method is used to set the path variable globally, that means these path variables are defined systemwide. The path to define the path variable is 

/etc/environment

Just open it as a root user, add the path variable as follows:

PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/opt/cassandra/bin:/path/to/bin"

Then run the following command to carry out effect:

$. /etc/environment

I hope this is helpful to you guys!