Saturday, April 18, 2020

Docker Introduction

Docker Introduction

  • Docker is an Open Source Platform designed to build, distribute and run applications inside the container.
  • Docker is Virtual box that packages applications.
  • Docker implements a high level API to proceed the light weight containers that run processors.
  • Also Docker is a tool for "Rapid Application Development"
  • Docker will use in Dev, Testing, Stage but before will not use in production because of security reason.
  • But now Docker itself has clearances, They integrated with SE-Linux(know that is for Security purpose).


Virtual Machines Vs Containers

                            VM's                                                          Docker Containers
   

                 -> More time to Create                               -> Less time to create

                 -> Dedicated OS                                        -> Common OS

                 -> Specific bin/lib                                       -> Common bin/lib

                 -> Dedicated Resources                              -> Common resources

                 -> Memory wastage                                    -> No Memory Wastage

                 -> Low Performance                                   -> high performance

                 -> Complex Configure                                -> Simple Configuration

                 -> Heavy Weight (Gb's)                              -> Light Memory (Mb's)

                 -> Memory can not share                             -> Can Share Memory

Docker Core Terminology

Docker mainly have Core parts. Those are

                   ** Images
                   ** Containers
                   ** Dockerfile
                   ** Docker Volumes
                   ** Docker Compose
                   ** Docker Network

Docker Images: 

  • Docker image is a collection of files and source meta data.
  • Images are made of layers, Conceptually stacked on top of each other.
  • Images can share layers to optimize the disk usage, transfer times and memory usage.
  • Docker image is Read Only file system.

Docker Containers:

  • A container is an executable form of docker image.
  • A Container is an encapsulated set of processes running in read-write copy of the file system.

Dockerfile:

  • Creates images automatically by using a build script: <Dockerfile>
  • Can be versionized in a version control system like Git or SVN along with all dependencies.
  • Docker hub can automatically build images based on dockerfiles on GitHub.

Docker Volumes:

  • In Docker, we have a separate volume that can shared across containers. These are known as Data Volumes.
  • They are initialized when the container is created.
  • They can be shared and also reused among many containers.
  • Any changes to the volume itself can be made directly.
  • They exist even after the container is deleted.
          Ex: # docker run -it -v /root/files:/files ubuntu

Docker Compose:

  • Docker Compose is a tool for defining and running multi-container Docker applications.
  • With Compose, we use a compose file to configure application's services.
  • Then, by using a single command we can create and start all the services from the given configuration requirement.
Docker Network: 
  • To communicate Docker Containers with each other and the outside world via the host machine, there has to be a layer of networking involved.
  • Docker supports different types of networks, each fit for certain use cases.
  • Different Network Types    
       Docker comes with network drivers geared towards different use cases. The most common network types being:
  • Bridge
  • Overlay
  • Macvlan

Run Platforms:

  • Various Linux Distributions (Ubuntu, CentOS, Fedora, RHEL, OpenSUSE, ...)
  • Cloud (AWS, GCP, Rackspace)
  • 2014-10: Microsoft announces plans to integrate Docker with next release of Windows Server.
  • 2013-03: Releases as Open Source Tool.



Friday, April 17, 2020

Install Grafana in CentOS with YUM/Distribution-method/RPM Methods

Grafana Introduction

  • Grafana is a  multi-platform open source analytics and interactive visualisation software
  • It is available since 2014
  • It provides charts, graphs and alerts for the web when connected to supported data sources.
  • It is expandable through a plug-in system.

Supported operating systems

  • Debian/Ubuntu
  • RPM-Based Linux (CentOS, Fedora, Opensuse, RHEL)
  • MacOS
  • Windows
Installation of Grafana on other operating systems is possible, but not supported.

Hardware Recommendations

  • Grafana does not use a lot of resources and is very lightweight in use of memory and CPU.
  • Minimum recommended memory: 255 MB 
  • Minimum recommended CPU: 1
  • Some features might require more memory or CPUs. Features require more resources include:
               a. Server side rendering of images
               b. Alerting
               c.  Data source proxy

Installation with YUM repo :

Step1 : Updating the server
$ sudo yum update
Step 2: Adding grafana repo for installing grafana
$ sudo vi /etc/yum.repos.d/grafana.repo
[grafana]
name=grafana baseurl=https://packages.grafana.com/oss/rpm
repo_gpgcheck=1
enabled=1
gpgcheck=1
gpgkey=https://packages.grafana.com/gpg.key
sslverify=1
sslcacert=/etc/pki/tls/certs/ca-bundle.crt
Step 3: Installing Grafana
$ sudo yum install grafana
Step 4: Start and Enable the grafana service
$ sudo systemctl daemon-reload
$ sudo systemctl start grafana-server
$ sudo systemctl status grafana-server
$ sudo systemctl enable grafana-server

Installation with Distribution Method (Using Binary):
Step 1: Downloading Grafana Zip file
Step 2: Unzip the Grafana zip file
tar -zxvf grafana-6.6.0.linux-amd64.tar.gz
Step 3: Start and enable the grafana server
$ sudo systemctl daemon-reload
$ sudo systemctl start grafana-server
$ sudo systemctl status grafana-server
$ sudo systemctl enable grafana-server

Installation with RPM:

Step 1: Adding Grafana RPM key
Step 2: Install some dependencies to install grafana with RPM
 $ sudo yum install initscripts urw-fonts wget
Step 3: Download the grafana RPM file
 $ sudo rpm -Uvh grafana-6.6.0-1.x86_64.rpm
Step 4: Installing Grafana

$ sudo yum localinstall grafana-6.6.0-1.x86_64.rpm
Step 3: Start and Enable the Grafana Server
 $ sudo systemctl daemon-reload
 $ sudo systemctl start grafana-server
 $ sudo systemctl status grafana-server
 $ sudo systemctl enable grafana-server
Referral Page : https://grafana.com/docs/grafana/latest/installation/



Install Ant in Ubuntu 16.04/18.04/20.04 Machine

APACHE ANT
  • ANT stands for another neat tools
  • It is java based build tool from Apache Software Fundation
  • Ant uses build.xml file 
  • Ant was created by james duncan davidson
Ant- Build Files:
  • Ants build file is called build.xml should reside in base directory(base directory means where the source code will maintained) of the project
  • In build.xml or any xml file it start with an xml tag project name and target a single project can have multiple targets
  • There should be no blank lines or white spaces before the xml declaration

Installation: 

    We can install ANT in different ways, those are 1. Using "apt" command module
                                                                                 2. Using "distribution method"

Here, we will see both the ways how to install ANT.

Prerequisites: 

Java should be install in the server.

Step 1: Update the Server 

$ sudo apt update -y 
Step 2: Install Java latest version, basically this command will install JAVA Runtime Environment
$ sudo apt install default-jre
Install Apache ANT in Ubuntu using "apt" command module
Step 3:  Update the Server Install Ant
$ sudo apt update 
$ sudo apt install ant -y
To verify the Ant installation
$ ant -version
Install Apache Ant Using "Distribution Method"
Step 1: Enter into the "opt" directory
cd /opt/
Step 2:  Download the tar or zap source file from http://ant.apache.org/bindownload.cgi
$ sudo wget http://mirrors.estointernet.in/apache//ant/binaries/apache-ant-1.10.5-bin.zip
Step 3:  Exatract the zip file or tar file
unzip apache-ant-1.10.5-bin.zip
Step 4: Add the ANT_HOME path.
$ sudo ANT_HOME=/opt/apache-ant-1.10.5
Step 5:  Now export the PATH
$ sudo PATH=$PATH:${ANT_HOME}/bin
Step 6: Now enter into the apache-ant-1.10.5
cd apache-ant-1.10.5
Step 7:  Now, Run the below command to start the "Build"
$ sudo ant -f fetch.xml -Ddest=system


Sunday, April 12, 2020

NFS Server Installation


Important files for NFS Configration

  • /etc/exports: Its a main configuration file of NFS, all exported files and directories are defined in this file at the NFS Server end.
  • /etc/fstab: To mount a NFS directory on your system across the reboots, we need to make an entry in /etc/fstab.
  • /etc/sysconfig/nfs: Configuration file of NFS to control on which port rpc and other services are listening.

To setup NFS mounts, we’ll be needing at least two Linux/Unix machines. Here in this tutorial, I’ll be using two servers.

             NFS Server: nfs.example.com with IP-192.168.0.63

             NFS Client : nfs-client.example.com with IP-192.168.0.64

At NFS Server End

Step 1: As the first step, we will install these packages on the CentOS server with yum
#      sudo yum install nfs-utils -y
Step 2:  Now create the directory that will be shared by NFS
#  sudo mkdir /var/nfsshare
Step 3: Change the permissions of the folder as follows:
# chmod -R 755 /var/nfsshare
# chown nobody:nobody /var/nfshare

NOTE: We use /var/nfsshare as shared folder, if we use another drive such as the /home directory, then the permission chnges will cause a massive permissions problem and ruin the whole hierarchy. So in case we want to share the /home directory then permissions must not be changed.

Step 4: 
#      PATH=$PATH:${ANT_HOME}/bin







How to Install ANT(Build Tool) in CentOS machine

APACHE ANT
  • ANT stands for another neat tools
  • It is java based build tool from Apache Software Fundation
  • Ant uses build.xml file 
  • Ant was created by james duncan davidson
Ant- Build Files:
  • Ants build file is called build.xml should reside in base directory(base directory means where the source code will maintained) of the project
  • In build.xml or any xml file it start with an xml tag project name and target a single project can have multiple targets
  • There should be no blank lines or white spaces before the xml declaration
Ant Installation In CentOS Machine

Step 1: Update the Virtual machine
$ sudo yum update -y 
Step 2: Enter into the "opt" directory
cd /opt/

Step 3:  Download the tar or zap source file from http://ant.apache.org/bindownload.cgi
Step 4:  Exatract the zip file or tar file
$ sudo unzip apache-ant-1.10.5-bin.zip

Step 5: Add the ANT_HOME path.
$ sudo ANT_HOME=/opt/apache-ant-1.10.5
Step 6:  Now export the PATH
$ sudo PATH=$PATH:${ANT_HOME}/bin
Step 7: Now enter into the apache-ant-1.10.5
$ sudo cd apache-ant-1.10.5
Step 8:  Now, Run the below command to start the "Build"
$ sudo ant -f fetch.xml -Ddest=system

Saturday, April 11, 2020

Ansible templates

Ansible templates:
  • Templates will copy the source file to the target host destination.
  • While the template module gets executed it will read the template file and change all the variables to its value and copy the file to the target host.
  • Template file ends with .j2 extension which stands for Jinja2 templates.
Example-1:
—–
Create a directory.
#mkdir templates
Sample template file.
#vi templates/file.j2

<html>

<h1> Hello! Venkat </h1>

<h1> GoodDay {{username}} </h1>

</html>
Ansible Templates in Playbooks:
——————————————-
#vi playbooks/pb1.yml

- hosts: dev
vars:
- username: Venkat
- file_path: /var/www/html
tasks:
- name: Copy site files
template:
src= templates/file.j2
dest= {{file_path}}/index.html mode=0777
–> Use template module to copy the template file and the variables used in the template.

Ex-2: To change Tomcat port
#vi templates/demo.j2

.......

<Connector port= "{{myport}}"
protocol= "HTTP/1.1"
.......

(server.xml content)
After changing the Port edit the playbook.
#vi playbooks/pb2.yml
---
- hosts: web
become: true
vars:
- myport: 9090
- file_path: /etc/tomcat7/
tasks:
- name: to update packages
apt: update_cache=yes

- name: to install java
apt:
name=openjdk-7-jdk
state: latest

- name: to install tomcat
apt: 
name: tomcat7 
state: latest
- name: to change tomcat port
template:
src: templates/demo.j2
dest: {{file_path}}/server.xml
notify:
- restart tomcat

handlers:
- name: restart tomcat
service: 
name: tomcat7
state: restarted

Ansible Roles

<Ansible Playbooks                                                                                                                      Ansible Templates>
ANSIBLE ROLES:
  • Ansible roles are the organized way to perform the tasks in different playbooks according to their functionality in a directory structure way.
  • Roles allow you to call a set of variables, tasks, and handlers by simply specifying a defined role.
  • In the role file inside every directory, there is a main.yml file.
  • By default, the execution starts from the main.yml file.
Ansible Role Directory Structure:
Mainly ansible roles contain below the directories below.
  • Tasks (a series of tasks are defined here)
  • Handlers (All handlers are defined here)
  • vars (all the variables are defined here)
  • files (all the files will be placed inside this directory)
  • meta (It is used to declare role dependences and information about a role)

Example:
#vi playbooks/pb1.yml
 ---
 - hosts: dev 
   remote_user: root 
   roles: 
     - myrole
Create the directories in the role directory.
#cd playbooks
#mkdir -p roles/myrole/{files,handlers,tasks,vars,meta}
Create task files.
#vi roles/myroles/tasks/main.yml

- include: pack_install.yml
- include: deploy_app.yml
Create the installation files.
#vi roles/myrole/tasks/pack_install.yml

- name: install {{pack1}}
  apt:
  name: {{pack1}}
  state: latest
  when: ansible_distribution=='Ubuntu'
  notify:
   - start apache2

- name: install {{pack2}}
  apt: 
  name: {{pack2}}
  state: latest
  when: ansible_distribution=='Ubuntu'
  notify:
  - start tomcat

- name: install {{pack3}}
  apt:
  name: {{pack3}}
  state: latest
  when: ansible_distribution=='Ubuntu'
  notify:
  - start mysql

Create deploy file.
#cd /playbooks/roles/myrole/tasks

#vi deploy_app.yml

- name: to deploy index.html
  copy: 
    src: index.html
    dest: /var/www/html/index.html

- name: to deploy sample.war
  copy: 
    src: sample.war
    dest: /var/lib/tomcat7/webapps/sample.war
Create handlers file.
#vi roles/myrole/handlers/main.yml

- name: start apache
  service:
  name: apache2
  state: started

- name: start tomcat
  service:
  name: tomcat7
  state: started

- name: start mysql
  service:
  name: mysql
  state: started
Create variables file.
#vi roles/myrole/vars/main.yml

pack1: apache2
pack2: tomcat7
pack3: mysql-server
Create sample files.
#vi roles/myrole/files/index.html

<h1> Hello from ansible role</h1>
See the files in the files directory
#vi playbooks/roles/myrole/files# ls

index.html  sample.war
Check the syntax
#ansible-playbook playbooks/myrole.yml --syntax-check
Execute the Roles
#ansible-playbook playbooks/myrole.yml

Role tree Structure:
After creating the roles directories and all files, the tree view will display like the example below.
Common role directory tree structure
                                                                                          
<Ansible Playbooks                                                                                                                     Ansible Templates> 





Featured Post

Ansible Tool Introduction

                                                                                                                                    Next ...