Wednesday 14 February 2018

Docker on Amazon Ec2 Linux/CentOs

How to install and run Docker on Amazon Ec2 Linux/CentOs

DOCKER: Build, Ship & Run Your Software Anywhere, A lightweight tool which uses container to package up an application with all the requirements and dependencies before shipping the complete container as one package.  Docker is an application that makes it simple and easy to run application processes in a container, which are like virtual machines, which are more portable, more resource-friendly, and more dependent on the host operating system. For a detailed introduction to the different components of a Docker container please visit below link.
https://www.digitalocean.com/community/tutorials/the-docker-ecosystem-an-introduction-to-common-components

Features:
• Use Docker container with any language
• Ship the container wherever you want, be it QA, your team or even the cloud
• Scale up to 1000’s node
• Update with zero downtime

Best practice:
Step 1: Know your Linux release: In my case "4.9.77-31.58.amzn1.x86_64"
  • uname -r
Step 2: Check the update available and you can update a package if required update
  • sudo yum check-update
  • sudo yum update package_name
Step 3: Install Docker:
  • sudo yum -y install docker docker-registry
  • sudo service docker start
  • sudo chkconfig docker on
  • sudo service docker status
Step 4: Verify docker version and know more about docker system.
  • sudo docker --version
  • sudo docker info
Step 5: Add user to docker group to avoid typing sudo every time before docker commands
  • sudo usermod -aG docker $(whoami) (for logged in user)
  • sudo usermod -aG docker username (for any user)
Step 6: Download an image from docker hub(hello-world is known image at docker hub)
  • sudo docker run hello-world
Step 7: Search an docker image in docker hub repository.
  • sudo docker search centos
Step 8: Pull docker image from repository.
  • sudo docker pull centos
Step 9: List all downloaded images.
  • sudo docker images
Step 10: Run docker image.
  • sudo docker run centos
Step 11: Login to docker:.
  • sudo docker attach "docker-id"
[root@c0755c7130fc /]#

Other useful commands:
To view all containers — active and inactive, pass it the -a switch:
  • docker ps -a
To view the latest container you created, pass it the -l switch:
  • docker ps -l
Stopping a running or active container is as simple as typing:
  • docker stop container-id
Starting a stopped container is as simple as typing:
  • docker start container-id















Monday 5 February 2018

Ansible on Ubuntu 16.04


Ansible on Ubuntu:
Ansible is an automation engine, similar to Chef or Puppet, that can be used to ensure deployment and configuration consistency across many Servers/Network Gears, Ansible helps to keep servers and applications up-to-date. Ansible model is client less and works on SSH protocol to communicate and configure a client, Ansible takes on a modular approach, making it easy to extend to use the functionalities of the main system to deal with specific scenarios. Modules can be written in any language and communicate in standard JSON. Configuration files are mainly written in the YAML data serialization format due to its expressive nature and its similarity to popular markup languages. Ansible can interact with clients through either command line tools or through its configuration scripts called Playbooks.

How to install Ansible on Ubuntu 16.04
Step1: The best way to get Ansible for Ubuntu is to add the project's PPA (personal package archive) to your system, Add the Ansible PPA by using following command:
  • sudo apt-add-repository ppa:ansible/ansible

Step2: Now refresh system's package index so that it is aware of the packages available in the PPA and then install ansible
  • sudo apt-get update
  • sudo apt-get install ansible

Step 3: Configuring Ansible Hosts
Ansible keeps track of all of the servers through a "hosts" file. We need to set up this file first before we can begin to communicate with our other computers.
  • sudo vim /etc/ansible/hosts

Step4: Verification of ansible install:
  • ansible --version
ansible 2.4.2.0
  config file = /etc/ansible/ansible.cfg
  configured module search path = [u'/home/ubuntu/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/lib/python2.7/dist-packages/ansible
  executable location = /usr/bin/ansible
  python version = 2.7.6 (default, Nov 23 2017, 15:49:48) [GCC 4.8.4]

Other configuration files:
/etc/ansible/ansible.cfg
 /etc/ansible/playbooks/
/etc/ansible/roles/


Command Examples:
  • ansible "host_name" -i hosts -m command -a "uptime"
  • ansible -m shell -a "hostname" all
  • ansible-playbook "playbook_name" --ask-sudo-pass

Playbook to create group, user and install htop on ubuntu: Note apache is the name in config file under which I have defined servers on which configuration needs to be done.
***********************************************************************************
---
- hosts: apache
  sudo: yes
  tasks:
  - name: install htop package
  apt: name=htop update_cache=yes state=latest

  - name: creating groups
  group: name=test-group state=present

  - name: creating user
  user: name=devops uid=2001

**********************************************************************************