Wednesday, January 24, 2018

Docker

What Is Docker And Concept Of Containers With Virtualization?
Docker, a booming technology replacing bars of application deployment and environment dependency. Most of the people wanted to know what actually/really DOCKER is? This Series will clear most of your doubts and will help you to learn Docker a bit.
What is Docker?
Docker is a Container management service, which was initially launched in year Ma
rch 2013. As this article picture says, Docker is basically an idea based on three keywords which are: develop, ship and run anywhere. The concept of Docker and the idea behind this technology was: develop the application, ship them as containers and deploy these containers anywhere.


Note: Docker needs kernel version 3.8 and higher.

 

Benefits Of Docker:

Ø  Docker actually reduces the size of development environment by giving smaller traces of the operating system with the help of containers.
Ø  Containers made the task easy for different the teams working on different area/units like development, QA, and Operations.
Ø  The best part of Docker(containers) is that you can deploy containers anywhere and anywhere means cloud VMs and physical machines.
Ø  These Docker containers are lightweight and are very easily scalable. Also, they take a fraction of a second to get a restart.
Ø  Docker Uses host OS as these are light weighted VMs
Ø  You don’t need to pre-allocate any RAM in containers.

We are talking a lot about containers to its very important to know container before moving forward.

What are Containers?

Well, Containers are extremely lightweight virtual machines (VMs). these VMs are footprints/traces of a real operating system. Well, this technology is not a competitor of virtualization. It is actually using the concept of virtualization on an upper level. In fact, containers are to complement VMs.

Containers isolate the application from accessing the resources as these are VMs. Now here is a fact, containers concept is not really new to our world. we have been using the same concept around for a while in Solaris zones, FreeBSD jails and chroot. All of them were containers.
Execution of containers is governed by Container engines (The Docker Engine) and share the OS kernel and required libraries. Docker uses cgroups(control groups is a Linux kernel feature that limits, accounts for, and isolates the resource usage) and namespaces in the Linux kernel which impose resource isolation. Once Docker is installed and services are started, the Docker daemon is responsible for building, running and distributing the Docker containers.
The Docker client interacts with the Docker daemon via sockets or through a RESTful API to do all the tasks.

Now Let’s Know More About Docker and its Components

Components Of Docker:

Internal components

There are three internal components that need to be understood
1.    Docker Images: Docker images are read-only templates; these images contain the operating system with the required libraries/tools and the applications.
2.    Docker Registries: Docker registries hold these images. These registries are like public/private repositories. The public Docker registry is called Docker Hub and has a huge collection of images with various applications embedded.
3.    Docker Containers: A Docker container holds everything that is needed for an application to execute. Containers are created from a Docker image. Similar to virtual machines, containers can be started, stopped, moved and deleted. Each container provides an isolated and secure environment for applications to run.

Useful Information About Docker:

Following are several other components of Dockers depending upon OS and other factors.
1.    Docker for Mac − It allows one to run Docker containers on the Mac OS.
2.    Docker for Linux − It allows one to run Docker containers on the Linux OS.
3.    Docker for Windows − It allows one to run Docker containers on the Windows OS.
4.    Docker Engine − It is used for building Docker images and creating Docker containers.
5.    Docker Hub − This is the registry which is used to host various Docker images.
6.    Docker Compose − This is used to define applications using multiple Docker containers.

When Docker runs a container from an image, it adds a read-write layer to the image by using the Union file system.
The Docker registries contain many base images either created by Docker Inc. or the community. These base images are used to build custom images with applications injected. Docker images can be built using a recipe file called Dockerfile.

Docker Vs VM:

 

                          As I said containers are based on the technology of virtualization but on an upper level but VMs and Containers differ on quite a few dimensions. Containers provide a way to virtualize an OS in order for multiple workloads to run on a single OS instance, whereas with VMs, the hardware is being virtualized to run multiple OS instances. Containers’ speed, agility, and portability make them yet another tool to help streamline software development like containers are based on virtualizing an OS in order for multiple workloads to run on a single OS instance, while in the case of virtualization, the hardware is virtualized to run multiple OS instances.Also, Containers’ are good in speed, agility, and portability which makes them another tool to help streamline software development. This Image will help you a lot to understand the fact.

How To Install Docker On CentOS/RHEL 6/7 And Learn Docker HUB Registration:

                                  Docker can be installed easily and it is available for almost every Linux distro’s and other OS(s) like Windows or Mac. Docker can also be compiled on the local system itself with the use of source code present on GitHub. Also, there are pre-compiled packages for Docker. It can be installed on the Host Machine OS or on a Virtual Machine.
                            As I mentioned that Docker can be installed on the Host Machine OS or on a Virtual Machine so it’s up to you what you gonna do. But before moving further with installation process you may like read about Docker, its components, and benefits
Scenario :
Host OS: CentOS 7 x86_64
RAM: 4GB memory,
Network Port:  1GB/s
HDD: 1000GB of disk space.

Prerequisite:
1.    Disabled the SELinux and FirewallD services
2.    We will pull the Docker-relevant packages from the repo, so provide proxy details.

 Note: –  If the system is behind the proxy, then ensure that HTTP_PROXY and HTTPS_PROXY are defined in the configuration file/etc/sysconfig/docker

Note: – This tutorial is for the scenario mentioned above but commands and steps for RHEL/CentOS 6/7 are same.

Step 1: Install EPEL Repository
                     For the installation of Docker, we required EPEL (Extra Packages for Enterprise Linux) repository pre-configured on CentOS/RHEL 6. But, If you are running a CentOS/RHEL 7 then you don’t need to install EPEL because CentOS 7 already have all packages required for Docker installation.
For RHEL/CentOS 6 32-64 Bit

#wget http://download.fedoraproject.org/pub/epel/6/i386/epel-release-6-8.noarch.rpm#
#rpm -ivh epel-release-6-8.noarch.rpm





For RHEL/CentOS 6 64-Bit

#wget http://download.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm
#rpm -ivh epel-release-6-8.noarch.rpm

Step 2:  Perform Docker Installation
                  We have completed and finished our dependencies and now we can move forward with Docker installation with following commands
For CentOS/RHEL 7

# yum install docker 
# yum install device-mapper-event-libs

For RHEL 6

# yum install docker-io
# yum install device-mapper-event-libs


Step 3: Start/Enable Docker Service
                     As we have successfully installed Docker and service, we need to start its service. For starting docker we need will use the following sets of command for CentOS/RHEL 6/7. Also we ill enable the service for current runlevel(s).
For RHEL/CentOS 7

# systemctl start docker.service
# systemctl status docker.service
# systemctl enable docker.service


For RHEL/CentOS 6

# service docker start
# service docker status
# chkconfig docker on

Step 4: Verify Installation
                    As we have a successful installation and a running service of Docker, we can verify its presence with two methods
1 . Checking Version 

# docker -v
Docker version 1.12.6, build 1398f24/1.12.6
2. Saying Hello  To Docker

# docker run hello-world
Hello from Docker!
This message shows that your installation appears to be working correctly.
To generate this message, Docker took the following steps:
1. The Docker client contacted the Docker daemon.
2. The Docker daemon pulled the "hello-world" image from the Docker Hub.
3. The Docker daemon created a new container from that image which runs the
executable that produces the output you are currently reading.
4. The Docker daemon streamed that output to the Docker client, which sent it
to your terminal.

To try something more ambitious, you can run an Ubuntu container with:
$ docker run -it ubuntu bash

Share images, automate workflows, and more with a free Docker ID:
https://cloud.docker.com/

For more examples and ideas, visit:
https://docs.docker.com/engine/userguide/

If you could See this then Your Docker installation is a success and its verified.
                     Now if you want to pull images(CentOS, Ubuntu etc.) from the Docker Hub then you need to complete a registration process on Docker HUB.  After successful registration, those credentials will be used for several other purposes too, other just pulling images from HUB. Once the registration is done, use the command docker login to log into the hub. (We will use this in Next Article)

But For Now A Quick Guide for  Docker Registration
                  Docker Hub is a registry service on the cloud that allows you to download Docker images that are built by other communities. You can also upload your own Docker built images to Docker hub.
Step 1: Follow the Link For Docker HUB  (https://hub.docker.com/) And Complete The Form


Step 2:- Active Your Account after clicking on the link you got in your Activation Email on your Email ID
Step 3: – After Logging in you Docker HUB Interface Be like this

Learn To Install, Run And Delete Applications Inside Docker Containers


1. Start Container

             First, start the container and with the help of the following command get the ContainerID
[root@localhost ~]# docker run -it centos /bin/bash   ------------ You Started Container
[root@7d81872f6a2b /]# exit      ------------ Exit Container
exit
[root@localhost ~]# docker ps -l ----------- Get ContainerID
CONTAINER ID IMAGE    COMMAND    CREATED                  STATUS                                PORTS    NAMES
7d81872f6a2b      centos    "/bin/bash"     About a minute ago   Exited (0) 7 seconds ago                    desperate_kare

As you have got a ContainrID but as you can see it’s in Exited State.

2. Install A Service In Container

           To install a service or the packages we need to start this container and get attached to it. We get access inside container we can do lots of work. For this example, we will install Apache Deamon. First Start The Docker Container Using Container ID
[root@localhost ~]# docker start 7d81872f6a2b
7d81872f6a2b
[root@localhost ~]# docker ps -l    ----------- Get ContainerID
CONTAINER ID      IMAGE    COMMAND          CREATED             STATUS       PORTS    NAMES
7d81872f6a2b      centos   "/bin/bash"     About 2 minute ago   Up 7 seconds         desperate_kare

Now As you can see Docker Container has started and now we will do our service installation.

[root@localhost ~]# docker attach 7d81872f6a2b
[root@7d81872f6a2b /]#  ----------This Shows You are connected with Container
[root@7d81872f6a2b /]# yum install httpd -y
Loaded plugins: fastestmirror, ovl
Determining fastest mirrors
* base: mirror.nbrc.ac.in
* extras: mirror.nbrc.ac.in
* updates: mirror.nbrc.ac.in
Resolving Dependencies
--> Running transaction check
---> Package httpd.x86_64 0:2.4.6-45.el7.centos.4 will be installed
--> Processing Dependency: httpd-tools = 2.4.6-45.el7.centos.4 for package: httpd-2.4.6-45.el7.centos.4.x86_64
--> Processing Dependency: system-logos >= 7.92.1-1 for package: httpd-2.4.6-45.el7.centos.4.x86_64
--> Processing Dependency: /etc/mime.types for package: httpd-2.4.6-45.el7.centos.4.x86_64
--> Processing Dependency: libaprutil-1.so.0()(64bit) for package: httpd-2.4.6-45.el7.centos.4.x86_64
--> Processing Dependency: libapr-1.so.0()(64bit) for package: httpd-2.4.6-45.el7.centos.4.x86_64
---> Package mailcap.noarch 0:2.1.41-2.el7 will be installed
--> Finished Dependency Resolution
 
Dependencies Resolved
 
===============================================================================================================================================================================================
Package Arch Version Repository Size
===============================================================================================================================================================================================
Installing:
httpd x86_64 2.4.6-45.el7.centos.4 updates 2.7 M
Installing for dependencies:
httpd-tools x86_64 2.4.6-45.el7.centos.4 updates 84 k
mailcap noarch 2.1.41-2.el7 base 31 k
 
Transaction Summary
===============================================================================================================================================================================================
Install 1 Package (+5 Dependent packages)
 
Total download size: 24 M
Installed size: 32 M
Downloading packages:
warning: /var/cache/yum/x86_64/7/base/packages/apr-1.4.8-3.el7.x86_64.rpm: Header V3 RSA/SHA256 Signature, key ID f4a80eb5: NOKEY
Public key for apr-1.4.8-3.el7.x86_64.rpm is not installed
(1/6): apr-1.4.8-3.el7.x86_64.rpm | 103 kB 00:00:00
Public key for httpd-tools-2.4.6-45.el7.centos.4.x86_64.rpm is not installed 0% [ ] 0.0 B/s | 103 kB --:--:-- ETA
(2/6): httpd-tools-2.4.6-45.el7.centos.4.x86_64.rpm | 84 kB 00:00:00
(3/6): mailcap-2.1.41-2.el7.noarch.rpm | 31 kB 00:00:00
(4/6): apr-util-1.5.2-6.el7.x86_64.rpm | 92 kB 00:00:00
(5/6): httpd-2.4.6-45.el7.centos.4.x86_64.rpm | 2.7 MB 00:00:09
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Total 743 kB/s | 24 MB 00:00:33
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
 
Installing : httpd-tools-2.4.6-45.el7.centos.4.x86_64 3/6
 
Installing : mailcap-2.1.41-2.el7.noarch 5/6
Installing : httpd-2.4.6-45.el7.centos.4.x86_64 6/6
Verifying : httpd-tools-2.4.6-45.el7.centos.4.x86_64 4/6
Verifying : httpd-2.4.6-45.el7.centos.4.x86_64 5/6
Verifying : centos-logos-70.0.6-3.el7.centos.noarch 6/6
 
Installed:
httpd.x86_64 0:2.4.6-45.el7.centos.4
 
Dependency Installed:
apr.x86_64 0:1.4.8-3.el7 apr-util.x86_64 0:1.5.2-6.el7 centos-logos.noarch 0:70.0.6-3.el7.centos httpd-tools.x86_64 0:2.4.6-45.el7.centos.4 mailcap.noarch 0:2.1.41-2.el7
 
Complete!
[root@7d81872f6a2b /]# exit

We have Successfully Installed A service Inside The Container.

3.   Commit Changes To The Container

 

                   As we a have container with Apache installed inside. Now we will commit this container a new Image and we will save this as our new Docker Image. First, We need to get exit from this Container and then follow more steps.
[root@localhost ~]# docker commit 7d81872f6a2b centos-apache
sha256:c260cf77d362b89cc00bed107250166ecd548752d50ef78d5c9dcd0f7c114bdb -- Output

Here, 7d81872f6a2b is Container ID and centos-apache is our new Image. Now we can confirm that we have a new image by the following command.

[root@localhost ~]# docker images
REPOSITORY             TAG    IMAGE ID     CREATED            SIZE
centos-apache          latest c260cf77d362 About a minute ago 327.5 MB
docker.io/hello-world  latest 1815c82652c0 2 weeks ago        1.84 kB
docker.io/centos       latest 3bee3060bfc8 3 weeks ago        192.5 MB

 

4. Verifying Image With Installed Apache

                  Now we can test our newly created image and check that all the changes we did commit inside. In this case, Apache service has been installed), so execute the following command in order to generate a new container, and tell us that we have installed Apache
[root@localhost ~]# docker run centos-apache /bin/bash -c "whereis httpd" 
 
httpd: /usr/sbin/httpd /usr/lib64/httpd /etc/httpd /usr/share/httpd

 

 

5. Removing A Container

                  Now we will remove this container because we don’t need it and to do the same, we require contained ID so run following command to get ContainerID and delete that container.
[root@localhost ~]# docker ps -a   -- To Get Container ID
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
95ddcedfbea4  centos-apache "/bin/bash -c 'wherei" 17 seconds ago Exited (0) 10 seconds ago furious_brahmagupta
[root@localhost ~]# docker rm 95ddcedfbea4 


6. Running A Sevice Inside Container

                   Now we have our own image and we want to run Apache server from our new docker image centos-apache and to do that first thing we need to do is to create a new container now along with we will map host-container ports and enter container shell by issuing following command.

[root@localhost ~]# docker run -it -p 81:80 centos-apache /bin/bash 
[root@3a5c5be3e947 /]# httpd &
[1] 15    -----------  Press CTRL+p then CTRL+q

-p option is to open host port to container port( host port can be arbitrary and no other host services should listen to it), the container port must be exactly the port that the inside daemon is listening to. Ctrl-p + Ctrl-q keys are used to detach container from console.
Now we can check work and get the state of your running container with following commands
[root@localhost ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
3a5c5be3e947 centos-apache "/bin/bash" 9 minutes ago Up 9 minutes 0.0.0.0:81->80/tcp silly_hawking

OR

[root@localhost ~]# netstat -tlpn | grep :81
tcp6 0 0 :::81 :::* LISTEN 9157/docker-proxy-c

 

7. Check Your Work

                       In order to visit the page served by the Apache Container, open a browser your LAN and type the IP address of your machine using the HTTP protocol.
Here You Can see its working on port 81

8. Stop A Container

                 We have learned most of the basic operation on Docker now this is the final step To stop the container. To do that run the following command followed by container ID or name.
[root@localhost ~]# docker ps ---- Getting Container Name Or ContainerID
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
3a5c5be3e947 centos-apache "/bin/bash" 24 minutes ago Up 24 minutes 0.0.0.0:81->80/tcp silly_hawking
[root@localhost ~]# docker stop silly_hawking  ---- Stopping Container By Name
silly_hawking
[root@localhost ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES   ---- No Container Is Running

Getting Familiar With Docker Commands Docker Terms: Docker

So Let’s dig out Command in Docker

              In Docker, everything is based on Images. An image is a combination of a file system and parameters. So most of our command will move around images.

Command 1: Create an Instance of Container

This command is used to create an instance of a container from an image.
#docker run hello-world
·         The Docker command tells the Docker program on the Operating System that something needs to be done.
·         The run command is used to mention that we want to create an instance of an image, called a container.
·          “hello-world” represents the image from which the container is made.


Command 2: Docker Information

This Command will show all the detailed information.
[root@localhost ~]# docker info
Containers: 3
Running: 0
Paused: 0
Stopped: 3
Images: 1
Server Version: 1.12.6
Storage Driver: devicemapper
.................................................................
.............................................................
Docker Root Dir: /var/lib/docker
Debug Mode (client): false
Debug Mode (server): false
Registry: https://index.docker.io/v1/
Insecure Registries:
 127.0.0.0/8
Registries: docker.io (secure)

 

Command 3: Docker Version

 

This command will help you to check out the running version of Docker of client end and server end.
[root@localhost ~]# docker version
Client:
 Version: 1.12.6
 API version: 1.24
 Package version: docker-1.12.6-28.git1398f24.el7.centos.x86_64
 Go version: go1.7.4
 Git commit: 1398f24/1.12.6
 Built: Fri May 26 17:28:18 2017
 OS/Arch: linux/amd64
 
Server:
 Version: 1.12.6
 API version: 1.24
 Package version: docker-1.12.6-28.git1398f24.el7.centos.x86_64
 Go version: go1.7.4
 Git commit: 1398f24/1.12.6
 Built: Fri May 26 17:28:18 2017
 OS/Arch: linux/amd64

 

Comand 4: List Docker Commands

           To get a list of all the command that works on docker on the console, you may hit below command on terminal. All the command and arguments will get populated on the terminal.
[root@localhost ~]# docker

Note: You Cab Use Run ‘docker COMMAND –help‘ for more information on a command

Command 5: Login Docker HUB or Docker Registry

                 Docker Registry or Docker HUB is used for searching and to pull Docker images(like CentOs, Ubuntu etc.) from the Docker HUB. Also, you can push and update your images to Docker HUB for future use and there are other many things you can do with Docker HUB.
You need an account on Docker HUB to get logged in. If you don’t have account you can create Following is the Command to Login into Docker HUB or Docker Registry:

[root@localhost ~]# docker login
Username: <Your Docker Login Username>
Password: <Type In Your Password>
Login succeeded.

 

Command 5: To Seach Images With Doker HUB


               Soon After logging into Docker HUB, you are eligible for PULL, PUSH, Search, Update docker image from Docker HUB. These images can be used for creating containers. Docker Hub has lots of community free images created for you like Ubuntu image mongo image and a much more great deal of free images from its repositories. Following command is used to search centOS images from the repository.

[root@localhost ~]# docker search centos
INDEX NAME DESCRIPTION STARS OFFICIAL AUTOMATED
docker.io docker.io/centos The official build of CentOS. 3432 [OK] 
docker.io docker.io/jdeathe/centos-ssh CentOS-6 6.9 x86_64 / CentOS-7 7.3.1611 x8... 74 [OK]
docker.io docker.io/nimmis/java-centos This is docker images of CentOS 7 with dif... 26 [OK]
docker.io docker.io/gluster/gluster-centos Official GlusterFS Image [ CentOS-7 + Glu... 19 [OK]
docker.io docker.io/kinogmt/centos-ssh CentOS with SSH 15 [OK]
docker.io docker.io/egyptianbman/docker-centos-nginx-php A simple and highly configurable docker co... 9 [OK]

Command 6: Download Docker image

         After logging in and searching out images from docker you can pull these image i=on yu local system using the following command.
[root@localhost ~]#docker pull centos
Using default tag: latest
Trying to pull repository docker.io/library/centos ... 
latest: Pulling from docker.io/library/centos
d5e46245fe40: Pull complete 
Digest: sha256:aebf12af704307dfa0079b3babdca8d7e8ff6564696882bcb5d11f1d461f9ee9

 

Command 7: List Docker Images On Local System

      Now when you have lots of downloaded docker images you can look all the docker images present on your local system by the following command.
[root@localhost ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
docker.io/hello-world latest 1815c82652c0 13 days ago 1.84 kB
docker.io/centos latest 3bee3060bfc8 3 weeks ago 192.5 MB
TAG − This is used to logically tag images.

Image ID − This is used to uniquely identify the image.

Created − The number of days since the image was created.

Virtual Size − The size of the image.

 

Command 8: Remove Docker Image

             When you have lots of running which are obsolete or you no longer need any Docker image then you can remove that image using the following command.
Syntex: docker rmi ImageName
[root@localhost ~]# docker rmi ubuntu
Untagged: ubuntu:latest
Untagged: docker.io/ubuntu@sha256:a0ee7647e24c8494f1cf6b94f1a3cd127f423268293c25d924fbe18fd82db5a4
Deleted: sha256:d355ed3537e94e76389fd78b77241eeba58a11b8faa501594bc82d723eb1c7f2
Deleted: sha256:dd864b96a38e849779c42a04159bbb39c7ab47253bf222049b471d8f26b60d14
Deleted: sha256:80e85c818fa0447c96a42501ca7457ad83e5834aa76f22c366342106889b7411
Deleted: sha256:11a2a269cf6ec2cefcb4e24370b8b2d7a4875450bafd3a70bd42eb787481d798
Deleted: sha256:1118f33a0ee7a874a04318248a886b2bdaf44cba286644ab7ded870aefe64b62
Deleted: sha256:cb11ba6054003d39da5c681006ea346e04fb3444086331176bf57255f149c670

 

Command 9: Run A Docker Container

The concept is little catchy, whenever a command is sent for execution in the Docker Image, a container in obtained. When this command execution is finished,  the container gets stopped (a non-running or exited container state). It Means at every command execution into the same image a new container is created again and again and exited.
All these created containers remain on host filesystem. You can delete them by using the docker rm command. To run or create a container use the following command:
Syntex: docker run [local image] [command to run into container]
[root@localhost ~]# docker run centos cat /etc/redhat-release
CentOS Linux release 7.3.1611 (Core)

 

Command 10: List Running Docker Containers

     Whenever a command execution is performed on a Docker Image a container is created and gets stopped after execution but it remains in exited or non-running state. The following command will display a list of the running and stopped (non-running) containers:
[root@localhost ~]# docker ps -l
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
a636b6753136 centos "cat /etc/redhat-rele" 5 minutes ago Exited (0) 4 minutes ago hungry_mayer
Note: ContainerID will be used in many actions. This command also gives you information like CONTAINER ID, IMAGE, COMMAND, CREATED, STATUS, PORTS, NAMES.

 

Command 11: Start A Container

      
                Now We have a ContainerID so we can start the container again with the command that was used to create it, by using the following command
Syntex: docker start ContainerID
[root@localhost ~]# docker start a636b6753136
a636b6753136

 

Command 12: Listing of Containers (Expended)

                 In a production environment there are many running containers and to list them we have command. This command is used to get the currently running containers.
[root@localhost home]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
7e0cab13b5f3 centos "/bin/sh" 12 seconds ago Up 5 seconds sleepy_wing

               This Can also be used with ‘-a’ argument and this command will list all of the containers on the system

[root@localhost home]# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
7e0cab13b5f3 centos "/bin/sh" 43 seconds ago Up 35 seconds sleepy_wing
05bd33e0b71e centos "/bin/sh" 3 hours ago Exited (0) 3 hours ago tiny_swartz
2b8b51d81869 centos "/bin/sh" 3 hours ago Exited (0) 3 hours ago infallible_bhaskara
 

 

Command 13: Stop A Docker

          Now if our container is working/running and we got its ID by issuing docker ‘ps’ command previously. Now to stop that container following command

Syntex: docker stop container ID or auto-generated name.
[root@localhost ~]# docker stop hungry_mayer



Command 14: Add Name To Docker Container On Local

                consider a situation when you have good numbers of containers and you can’t remember so you don’t have to remember the container ID. You can give a unique name for every container using the –name option as this following example shows:
Syntex: docker run –name unique_name Image Command
[root@localhost ~]# docker run --name unique_name centos cat /etc/redhat-release

 

Command 15: Use of Name To (start, stop, remove, top, stats)

           Now as we have given a unique name to the container so we can do a lot of work with container unique name like following.
[root@localhost ~]# docker start unique_name 
[root@localhost ~]# docker stats unique_name 
[root@localhost ~]# docker top unique_name

Note: Sometimes there is no output because the command was in execution which was used to create the container.

 

Command 16: Start Docker Container Interactive Shell

         To start an interactive session with into a container shell, and want to run commands as you do on any other Linux session, please run following command
[root@localhost ~]# docker run -it centos /bin/sh
sh-4.2# bash
[root@3e278670bbc1 /]#

Note: Run bash command to get bash shell
Here, Centos is the name of the image we download from Docker Hub
-it is used to mention that we want to run in interactive mode.
/bin/bash is used to run the bash shell once CentOS is up and running.

 

Command 17: Quit Docker Container Interactive Shell

           Now if you want to run quit this interactive session from the container with the host. You can do this by typing exit in an interactive shell. The exit command terminates all the container processes and stops it.
[root@3e278670bbc1 /]# exit
exit
sh-4.2# exit
exit
[root@localhost ~]#

 

Command 18: Keep Docker Shell Session Active

                      As the previous command kill all the running process of a container after exiting interactive shell mode. Now if you don’t want to kill the running container process and want to keep the container in running state. Also, want to exit the interactive shell session and return to the Host Terminal, you can do this by pressing Ctrl+p and Ctrl+q keys.

[root@d15866d0dc29 /]#   "<Press Ctrl+p> and then <Press Ctrl+q>"
[root@localhost ~]#

 

Command 19: To Reconnect With Running Container

          Well with the previous command we kept a docker running even after exiting the interactive shell now to reconnect that interactive shell we need the container ID or name of that container. Use the ‘docker ps’ command to get the ConatinerID or name and use the following command to get reconnected.

[root@localhost ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
d15866d0dc29 centos "/bin/sh" 10 minutes ago Up 10 minutes naughty_montalcini
Now Use this ContainerID or Name to Reconnect Container.
Syntex: docker attach <container id>
[root@localhost ~]# docker attach d15866d0dc29
[root@d15866d0dc29 /]#



Command 20: To Stop A Running Container

          To stop and kill a docker from the host, use the following command

Syntax: docker kill <container id>
[root@localhost home]# docker kill 9ac0ec22a0a2
9ac0ec22a0a2

 

 

Command 21: Inspect A Docker

                    This command is used see the details of an image or container. This Command provides lots of information about the Docker Image.

Syntax: docker inspect Repository

[root@localhost ~]# docker inspect centos
[
 {
 "Id": "sha256:3bee3060bfc81c061ce7069df35ce090593bda584d4ef464bc0f38086c11371d",
 "RepoTags": [
 "docker.io/centos:latest"
 ],
 "RepoDigests": [
.....................
........................
 },
 "RootFS": {
 "Type": "layers",
 "Layers": [
 "sha256:dc1e2dcdc7b6ff86d785fa16cf97464d263d04346a191c57b5ca8a66b4155861"
 ]
 }
 }
]

Repository − This is the name of the Image.

Command 22: Docker Logs

               When there is a production, we always need logs for data analysis and get logs of container from the host machine we need to run following command but to do this we require a ContainerID
Syntex: docker logs ContainerID
[root@localhost ~]# docker logs 2b8b51d81869

 

 

Command 23: Get Image ID’s Only

        If you require image ID only for any purpose you may issue the following command to get IDs
[root@localhost home]# docker images -q
1815c82652c0
3bee3060bfc8

As you can see this command is used to return only the Image IDs of the images.
q− It tells the Docker command to return the Image ID’s only

Command 24: Docker History

                docker history is the command to check all the commands which were fired/ran with an image via a container.
Syntax: docker history ImageID
This command will show all the commands that were run with the CentOS image.
[root@localhost home]# docker history centos
IMAGE CREATED CREATED BY SIZE COMMENT
3bee3060bfc8 3 weeks ago /bin/sh -c #(nop) CMD ["/bin/bash"] 0 B 
<missing> 3 weeks ago /bin/sh -c #(nop) LABEL name=CentOS Base Ima 0 B 
<missing> 3 weeks ago /bin/sh -c #(nop) ADD file:d22a9c627d1d1f32a8 192.5 MB

ImageID − This is the Image ID for which you want to see all the commands that were run against it.

Thursday, December 28, 2017

How to check RMAN backup status and timings




SQL> col STATUS format a9
SQL> col hrs format 999.99
SQL> select SESSION_KEY, INPUT_TYPE, STATUS,to_char(START_TIME,'mm/dd/yy hh24:mi') start_time,to_char(END_TIME,'mm/dd/yy hh24:mi') end_time,elapsed_seconds/3600 hrs from V$RMAN_BACKUP_JOB_DETAILS order by session_key;

This command will give us backup startup and end time.

Tablespace Growth History and Forecast 

For 10g and 11g database growth history and forecast see script Database Growth History and Forecast for 10g and 11g.
For 12c and above; Tablespace and Database growth history and forecast, please use following scripts
Tablespace Growth History and Forecast for 12c and Above.
Database Growth History and Forecast for 12c and Above.
For segments space usage history and forecast, see this document
Starting Oracle 10G, Oracle records tablespaces usage (allocated, used etc.) in AWR which can be retrieved by querying the data dictionary view dba_hist_tbspc_space_usage. Following scripts can be used to view the history of tablespace(s) usage and predict the expected growth for the future. Growth forecast is based on daily growth in the past.

Things to note:
1) This script is based on AWR. If your AWR retention period is 7 days, this script can only tell the growth history of last 7 days and predict based on last 7 days growth. I would recommend to change AWR retention to at least 35 days - this will also be more helpful in case of performance tuning situation as you will have a longer window from the past to look into for performance comparisons.
2) You may edit this scrip according to your requirement to forecast for a period  which suites your requirements. By default it will predict expected growth for next 30, 60 and 90 days.
3) Save this code in an sql script.
4) Log in as user SYS on SQLPLUS and execute the script or copy and paste the following code. You will be prompted for the tablespace name

Script for Single Tablespace

##############################################
set serverout on
set verify off
set lines 200
set pages 2000
DECLARE
v_ts_id number;
not_in_awr EXCEPTION;
v_ts_name varchar2(200) := UPPER('&Tablespace_Name');
v_ts_block_size number;
v_begin_snap_id number;
v_end_snap_id number;
v_begin_snap_date date;
v_end_snap_date date;
v_numdays number;
v_ts_begin_size number;
v_ts_end_size number;
v_ts_growth number;
v_count number;
v_ts_begin_allocated_space number;
v_ts_end_allocated_space number;
BEGIN
SELECT ts# into v_ts_id FROM v$tablespace where name = v_ts_name;
SELECT count(*) INTO v_count FROM dba_hist_tbspc_space_usage where tablespace_id=v_ts_id;
IF v_count = 0 THEN 
RAISE not_in_awr;
END IF ;
SELECT block_size into v_ts_block_size FROM dba_tablespaces where tablespace_name = v_ts_name;
SELECT min(snap_id), max(snap_id), min(trunc(to_date(rtime,'MM/DD/YYYY HH24:MI:SS'))), max(trunc(to_date(rtime,'MM/DD/YYYY HH24:MI:SS')))
into v_begin_snap_id,v_end_snap_id, v_begin_snap_date, v_end_snap_date from dba_hist_tbspc_space_usage where tablespace_id=v_ts_id;
v_numdays := v_end_snap_date - v_begin_snap_date;

SELECT round(max(tablespace_size)*v_ts_block_size/1024/1024,2) into v_ts_begin_allocated_space from dba_hist_tbspc_space_usage where tablespace_id=v_ts_id and snap_id = v_begin_snap_id;
SELECT round(max(tablespace_size)*v_ts_block_size/1024/1024,2) into v_ts_end_allocated_space from dba_hist_tbspc_space_usage where tablespace_id=v_ts_id and snap_id = v_end_snap_id;
SELECT round(max(tablespace_usedsize)*v_ts_block_size/1024/1024,2) into v_ts_begin_size from dba_hist_tbspc_space_usage where tablespace_id=v_ts_id and snap_id = v_begin_snap_id;
SELECT round(max(tablespace_usedsize)*v_ts_block_size/1024/1024,2) into v_ts_end_size from dba_hist_tbspc_space_usage where tablespace_id=v_ts_id and snap_id = v_end_snap_id;
v_ts_growth := v_ts_end_size - v_ts_begin_size;
DBMS_OUTPUT.PUT_LINE(CHR(10));
DBMS_OUTPUT.PUT_LINE('Tablespace Block Size: '||v_ts_block_size);
DBMS_OUTPUT.PUT_LINE('---------------------------');
DBMS_OUTPUT.PUT_LINE(CHR(10));
DBMS_OUTPUT.PUT_LINE('Summary');
DBMS_OUTPUT.PUT_LINE('========');
DBMS_OUTPUT.PUT_LINE('1) Allocated Space: '||v_ts_end_allocated_space||' MB'||' ('||round(v_ts_end_allocated_space/1024,2)||' GB)');
DBMS_OUTPUT.PUT_LINE('2) Used Space: '||v_ts_end_size||' MB'||' ('||round(v_ts_end_size/1024,2)||' GB)');
DBMS_OUTPUT.PUT_LINE('3) Used Space Percentage: '||round(v_ts_end_size/v_ts_end_allocated_space*100,2)||' %');
DBMS_OUTPUT.PUT_LINE(CHR(10));
DBMS_OUTPUT.PUT_LINE('History');
DBMS_OUTPUT.PUT_LINE('========');
DBMS_OUTPUT.PUT_LINE('1) Allocated Space on '||v_begin_snap_date||': '||v_ts_begin_allocated_space||' MB'||' ('||round(v_ts_begin_allocated_space/1024,2)||' GB)');
DBMS_OUTPUT.PUT_LINE('2) Current Allocated Space on '||v_end_snap_date||': '||v_ts_end_allocated_space||' MB'||' ('||round(v_ts_end_allocated_space/1024,2)||' GB)');
DBMS_OUTPUT.PUT_LINE('3) Used Space on '||v_begin_snap_date||': '||v_ts_begin_size||' MB'||' ('||round(v_ts_begin_size/1024,2)||' GB)' );
DBMS_OUTPUT.PUT_LINE('4) Current Used Space on '||v_end_snap_date||': '||v_ts_end_size||' MB'||' ('||round(v_ts_end_size/1024,2)||' GB)' );
DBMS_OUTPUT.PUT_LINE('5) Total growth during last '||v_numdays||' days between '||v_begin_snap_date||' and '||v_end_snap_date||': '||v_ts_growth||' MB'||' ('||round(v_ts_growth/1024,2)||' GB)');
IF (v_ts_growth <= 0 OR v_numdays <= 0) THEN
DBMS_OUTPUT.PUT_LINE(CHR(10));
DBMS_OUTPUT.PUT_LINE('!!! NO DATA GROWTH WAS FOUND FOR TABLESPCE '||V_TS_NAME||' !!!');
ELSE
DBMS_OUTPUT.PUT_LINE('6) Per day growth during last '||v_numdays||' days: '||round(v_ts_growth/v_numdays,2)||' MB'||' ('||round((v_ts_growth/v_numdays)/1024,2)||' GB)');
DBMS_OUTPUT.PUT_LINE(CHR(10));
DBMS_OUTPUT.PUT_LINE('Expected Growth');
DBMS_OUTPUT.PUT_LINE('===============');
DBMS_OUTPUT.PUT_LINE('1) Expected growth for next 30 days: '|| round((v_ts_growth/v_numdays)*30,2)||' MB'||' ('||round(((v_ts_growth/v_numdays)*30)/1024,2)||' GB)');
DBMS_OUTPUT.PUT_LINE('2) Expected growth for next 60 days: '|| round((v_ts_growth/v_numdays)*60,2)||' MB'||' ('||round(((v_ts_growth/v_numdays)*60)/1024,2)||' GB)');
DBMS_OUTPUT.PUT_LINE('3) Expected growth for next 90 days: '|| round((v_ts_growth/v_numdays)*90,2)||' MB'||' ('||round(((v_ts_growth/v_numdays)*90)/1024,2)||' GB)');
END IF;

EXCEPTION
WHEN NO_DATA_FOUND THEN
DBMS_OUTPUT.PUT_LINE(CHR(10));
DBMS_OUTPUT.PUT_LINE('!!! TABLESPACE DOES NOT EXIST !!!');
WHEN NOT_IN_AWR THEN
DBMS_OUTPUT.PUT_LINE(CHR(10));
DBMS_OUTPUT.PUT_LINE('!!! TABLESPACE USAGE INFORMATION NOT FOUND IN AWR !!!');

END;
/
##############################################

Sample Output

Enter value for tablespace_name: TEST


Tablespace Block Size: 8192
---------------------------


Summary
========
1) Allocated Space: 2048 MB (2 GB)
2) Used Space: 1558.44 MB (1.52 GB)
3) Used Space Percentage: 76.1 %


History
========
1) Allocated Space on 06-DEC-14: 2048 MB (2 GB)
2) Current Allocated Space on 10-JAN-15: 2048 MB (2 GB)
3) Used Space on 06-DEC-14: 1273 MB (1.24 GB)
4) Current Used Space on 10-JAN-15: 1558.44 MB (1.52 GB)
5) Total growth during last 35 days between 06-DEC-14 and 10-JAN-15: 285.44 MB (.28 GB)
6) Per day growth during last 35 days: 8.16 MB (.01 GB)


Expected Growth
===============
1) Expected growth for next 30 days: 244.66 MB (.24 GB)
2) Expected growth for next 60 days: 489.33 MB (.48 GB)
3) Expected growth for next 90 days: 733.99 MB (.72 GB)

PL/SQL procedure successfully completed.


/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/

Script for All Tablespace (Except UNDO and TEMP)
set serverout on
set verify off
set lines 200
set pages 2000
DECLARE
v_ts_id number;
not_in_awr EXCEPTION;
v_ts_block_size number;
v_begin_snap_id number;
v_end_snap_id number;
v_begin_snap_date date;
v_end_snap_date date;
v_numdays number;
v_ts_begin_size number;
v_ts_end_size number;
v_ts_growth number;
v_count number;
v_ts_begin_allocated_space number;
v_ts_end_allocated_space number;
cursor v_cur is select tablespace_name from dba_tablespaces where contents='PERMANENT';

BEGIN
FOR v_rec in v_cur
LOOP
BEGIN
SELECT ts# into v_ts_id FROM v$tablespace where name = v_rec.tablespace_name;
SELECT count(*) INTO v_count FROM dba_hist_tbspc_space_usage where tablespace_id=v_ts_id;
IF v_count = 0 THEN 
RAISE not_in_awr;
END IF ;
SELECT block_size into v_ts_block_size FROM dba_tablespaces where tablespace_name = v_rec.tablespace_name;
SELECT min(snap_id), max(snap_id), min(trunc(to_date(rtime,'MM/DD/YYYY HH24:MI:SS'))), max(trunc(to_date(rtime,'MM/DD/YYYY HH24:MI:SS')))
into v_begin_snap_id,v_end_snap_id, v_begin_snap_date, v_end_snap_date from dba_hist_tbspc_space_usage where tablespace_id=v_ts_id;
v_numdays := v_end_snap_date - v_begin_snap_date;

SELECT round(max(tablespace_size)*v_ts_block_size/1024/1024,2) into v_ts_begin_allocated_space from dba_hist_tbspc_space_usage where tablespace_id=v_ts_id and snap_id = v_begin_snap_id;
SELECT round(max(tablespace_size)*v_ts_block_size/1024/1024,2) into v_ts_end_allocated_space from dba_hist_tbspc_space_usage where tablespace_id=v_ts_id and snap_id = v_end_snap_id;
SELECT round(max(tablespace_usedsize)*v_ts_block_size/1024/1024,2) into v_ts_begin_size from dba_hist_tbspc_space_usage where tablespace_id=v_ts_id and snap_id = v_begin_snap_id;
SELECT round(max(tablespace_usedsize)*v_ts_block_size/1024/1024,2) into v_ts_end_size from dba_hist_tbspc_space_usage where tablespace_id=v_ts_id and snap_id = v_end_snap_id;
v_ts_growth := v_ts_end_size - v_ts_begin_size;
DBMS_OUTPUT.PUT_LINE(CHR(10));
DBMS_OUTPUT.PUT_LINE(v_rec.tablespace_name||' Tablespace');
DBMS_OUTPUT.PUT_LINE('--------------------');
DBMS_OUTPUT.PUT_LINE('Tablespace Block Size: '||v_ts_block_size);
DBMS_OUTPUT.PUT_LINE('---------------------------');
DBMS_OUTPUT.PUT_LINE(CHR(10));
DBMS_OUTPUT.PUT_LINE('Summary');
DBMS_OUTPUT.PUT_LINE('========');
DBMS_OUTPUT.PUT_LINE('1) Allocated Space: '||v_ts_end_allocated_space||' MB'||' ('||round(v_ts_end_allocated_space/1024,2)||' GB)');
DBMS_OUTPUT.PUT_LINE('2) Used Space: '||v_ts_end_size||' MB'||' ('||round(v_ts_end_size/1024,2)||' GB)');
DBMS_OUTPUT.PUT_LINE('3) Used Space Percentage: '||round(v_ts_end_size/v_ts_end_allocated_space*100,2)||' %');
DBMS_OUTPUT.PUT_LINE(CHR(10));
DBMS_OUTPUT.PUT_LINE('History');
DBMS_OUTPUT.PUT_LINE('========');
DBMS_OUTPUT.PUT_LINE('1) Allocated Space on '||v_begin_snap_date||': '||v_ts_begin_allocated_space||' MB'||' ('||round(v_ts_begin_allocated_space/1024,2)||' GB)');
DBMS_OUTPUT.PUT_LINE('2) Current Allocated Space on '||v_end_snap_date||': '||v_ts_end_allocated_space||' MB'||' ('||round(v_ts_end_allocated_space/1024,2)||' GB)');
DBMS_OUTPUT.PUT_LINE('3) Used Space on '||v_begin_snap_date||': '||v_ts_begin_size||' MB'||' ('||round(v_ts_begin_size/1024,2)||' GB)' );
DBMS_OUTPUT.PUT_LINE('4) Current Used Space on '||v_end_snap_date||': '||v_ts_end_size||' MB'||' ('||round(v_ts_end_size/1024,2)||' GB)' );
DBMS_OUTPUT.PUT_LINE('5) Total growth during last '||v_numdays||' days between '||v_begin_snap_date||' and '||v_end_snap_date||': '||v_ts_growth||' MB'||' ('||round(v_ts_growth/1024,2)||' GB)');
IF (v_ts_growth <= 0 OR v_numdays <= 0) THEN
DBMS_OUTPUT.PUT_LINE(CHR(10));
DBMS_OUTPUT.PUT_LINE('!!! NO DATA GROWTH WAS FOUND FOR TABLESPACE '||v_rec.tablespace_name||' !!!');
ELSE
DBMS_OUTPUT.PUT_LINE('6) Per day growth during last '||v_numdays||' days: '||round(v_ts_growth/v_numdays,2)||' MB'||' ('||round((v_ts_growth/v_numdays)/1024,2)||' GB)');
DBMS_OUTPUT.PUT_LINE(CHR(10));
DBMS_OUTPUT.PUT_LINE('Expected Growth');
DBMS_OUTPUT.PUT_LINE('===============');
DBMS_OUTPUT.PUT_LINE('1) Expected growth for next 30 days: '|| round((v_ts_growth/v_numdays)*30,2)||' MB'||' ('||round(((v_ts_growth/v_numdays)*30)/1024,2)||' GB)');
DBMS_OUTPUT.PUT_LINE('2) Expected growth for next 60 days: '|| round((v_ts_growth/v_numdays)*60,2)||' MB'||' ('||round(((v_ts_growth/v_numdays)*60)/1024,2)||' GB)');
DBMS_OUTPUT.PUT_LINE('3) Expected growth for next 90 days: '|| round((v_ts_growth/v_numdays)*90,2)||' MB'||' ('||round(((v_ts_growth/v_numdays)*90)/1024,2)||' GB)');
END IF;
DBMS_OUTPUT.PUT_LINE('/\/\/\/\/\/\/\/\/\/\/\/ END \/\/\/\/\/\/\/\/\/\/\/\');

EXCEPTION
WHEN NOT_IN_AWR THEN
DBMS_OUTPUT.PUT_LINE(CHR(10));
DBMS_OUTPUT.PUT_LINE(v_rec.tablespace_name||' Tablespace');
DBMS_OUTPUT.PUT_LINE('--------------------');
DBMS_OUTPUT.PUT_LINE('Tablespace Block Size: '||v_ts_block_size);
DBMS_OUTPUT.PUT_LINE('---------------------------');
DBMS_OUTPUT.PUT_LINE(CHR(10));
DBMS_OUTPUT.PUT_LINE('!!! TABLESPACE USAGE INFORMATION NOT FOUND IN AWR !!!');
DBMS_OUTPUT.PUT_LINE('/\/\/\/\/\/\/\/\/\/\/\/ END \/\/\/\/\/\/\/\/\/\/\/\');
NULL;
END;
END LOOP;
END;
/



Reference- Salman DBA

Friday, December 15, 2017

Oracle 12.1.0.2 silent install and de-install


After Oracle Enterprise Linux setup we must set up some settings shown bellow:
Edit “/etc/hosts” file and add fully qualified name of your server.
[root@agcns Desktop]# vi /etc/hosts
127.0.0.1      localhost localhost.localdomain 
192.168.8.157  agcns agcns.localdomain
Then install oracle-rdbms-server-12cR1-preinstall package to perform all your prerequisite setup
[root@agcns Desktop]# yum install oracle-rdbms-server-12cR1-preinstall -y
Add lines bellow to the /etc/security/limits.conf  file.
oracle   soft   nofile    1024
oracle   hard   nofile    65536
oracle   soft   nproc    16384
oracle   hard   nproc    16384
oracle   soft   stack    10240
oracle   hard   stack    32768
Install  packages bellow if they are not already installed.
yum install binutils -y
yum install compat-libcap1 -y
yum install compat-libstdc++-33 -y
yum install compat-libstdc++-33.i686 -y
yum install gcc -y
yum install gcc-c++ -y
yum install glibc -y
yum install glibc.i686 -y
yum install glibc-devel -y
yum install glibc-devel.i686 -y
yum install ksh -y
yum install libgcc -y
yum install libgcc.i686 -y
yum install libstdc++ -y
yum install libstdc++.i686 -y
yum install libstdc++-devel -y
yum install libstdc++-devel.i686 -y
yum install libaio -y
yum install libaio.i686 -y
yum install libaio-devel -y
yum install libaio-devel.i686 -y
yum install libXext -y
yum install libXext.i686 -y
yum install libXtst -y
yum install libXtst.i686 -y
yum install libX11 -y
yum install libX11.i686 -y
yum install libXau -y
yum install libXau.i686 -y
yum install libxcb -y
yum install libxcb.i686 -y
yum install libXi -y
yum install libXi.i686 -y
yum install make -y
yum install sysstat -y
yum install unixODBC -y
yum install unixODBC-devel -y
Set the password for the oracle user.
[root@agcns Desktop]# passwd oracle
Changing password for user oracle.
New password: 
Retype new password: 
passwd: all authentication tokens updated successfully.
change   /etc/security/limits.d/90-nproc.conf  like below.
*     -   nproc 16384
root soft nproc unlimited
Set  SELINUX to permissive, disable firewall and then reboot server:
[root@agcns]# vi /etc/selinux/config
SELINUX=permissive
[root@agcns]# service iptables stop
[root@agcns]# chkconfig iptables off
[root@agcns]# reboot
Create the ORACLE_HOME directory in which the Oracle software will be installed.
[root@agcns ~]# mkdir -p /u01/app/oracle/product/12.1.0.2/db_1
[root@agcns ~]# chown -R oracle:oinstall /u01
[root@agcns ~]# chmod -R 775 /u01
Switch to oracle account and unzip Oracle Installation zip files:
[oracle@agcns]$ unzip linuxamd64_12c_database_1of2.zip
[oracle@agcns]$ unzip linuxamd64_12c_database_2of2.zip
Edit bash_profile and add lines  bellow to this file:
[oracle@agcns]$ vi /home/oracle/.bash_profile
export PATH
export TMP=/tmp
export TMPDIR=$TMP
export ORACLE_HOSTNAME=agcns.localdomain
export ORACLE_UNQNAME=gcdb
export ORACLE_BASE=/u01/app/oracle
export ORACLE_HOME=$ORACLE_BASE/product/12.1.0.2/db_1
export ORACLE_SID=gcdb
export PATH=/usr/sbin:$PATH
export PATH=$ORACLE_HOME/bin:$PATH
export LD_LIBRARY_PATH=$ORACLE_HOME/lib:/lib:/usr/lib export CLASSPATH=$ORACLE_HOME/jlib:$ORACLE_HOME/rdbms/jlib
To perform silent installation  we must create and  use oraInst.loc and response file.
[root@agcns ~]# vi /etc/oraInst.loc
inventory_loc=/u01/app/oraInventory
inst_group=oinstall

[root@agcns ~]# chown oracle:oinstall /etc/oraInst.loc 
[root@agcns ~]# chmod 664 /etc/oraInst.loc

[oracle@agcns database]$ ./runInstaller -silent \
> -responseFile /tmp/database/response/db_install.rsp \
> oracle.install.option=INSTALL_DB_SWONLY \
> UNIX_GROUP_NAME=oinstall \
> INVENTORY_LOCATION=/u01/app/oracle/oraInventory \
> SELECTED_LANGUAGES=en \
> ORACLE_HOME=/u01/app/oracle/product/12.1.0.2/db_1 \
> ORACLE_BASE=/u01/app/oracle \
> oracle.install.db.InstallEdition=EE \
> oracle.install.db.isCustomInstall=false \
> oracle.install.db.DBA_GROUP=dba \
> oracle.install.db.OPER_GROUP=dba \
> oracle.install.db.BACKUPDBA_GROUP=dba \
> oracle.install.db.DGDBA_GROUP=dba \
> oracle.install.db.KMDBA_GROUP=dba \
> SECURITY_UPDATES_VIA_MYORACLESUPPORT=false \
> DECLINE_SECURITY_UPDATES=true
Starting Oracle Universal Installer...

Checking Temp space: must be greater than 500 MB. Actual 18421 MB Passed
Checking swap space: must be greater than 150 MB. Actual 3919 MB Passed
Preparing to launch Oracle Universal Installer from /tmp/OraInstall2016-09-07_08-06-29PM. Please wait ...[oracle@agcns database]$ 
[oracle@agcns database]$ 
[oracle@agcns database]$ You can find the log of this install session at:
 /u01/app/oracle/oraInventory/logs/installActions2016-09-07_08-06-29PM.log
The installation of Oracle Database 12c was successful.
Please check '/u01/app/oracle/oraInventory/logs/silentInstall2016-09-07_08-06-29PM.log' for more details.

As a root user, execute the following script(s):
 1. /u01/app/oracle/product/12.1.0.2/db_1/root.sh


Successfully Setup Software.



[oracle@agcns logs]$ su -
Password: 
[root@agcns ~]# /u01/app/oracle/product/12.1.0.2/db_1/root.sh
Check /u01/app/oracle/product/12.1.0.2/db_1/install/root_agcns.localdomain_2016-09-07_20-12-10.log for the output of root script
[root@agcns ~]# cat /u01/app/oracle/product/12.1.0.2/db_1/install/root_agcns.localdomain_2016-09-07_20-12-10.log 
Performing root user operation for Oracle 12c 

The following environment variables are set as:
 ORACLE_OWNER= oracle
 ORACLE_HOME= /u01/app/oracle/product/12.1.0.2/db_1
 Copying dbhome to /usr/local/bin ...
 Copying oraenv to /usr/local/bin ...
 Copying coraenv to /usr/local/bin ...


Creating /etc/oratab file...
Entries will be added to the /etc/oratab file as needed by
Database Configuration Assistant when a database is created
Finished running generic part of root script.
Now product-specific root actions will be performed.
[root@agcns ~]# 


[oracle@agcns ~]$ sqlplus / as sysdba

SQL*Plus: Release 12.1.0.1.0 Production on Wed Sep 7 20:14:43 2016

Copyright (c) 1982, 2013, Oracle. All rights reserved.

Connected to an idle instance.

SQL> 


De-Installing Oracle Database

To remove installed oracle software, you must run the de-install utility by invoking the runInstallerwith the deinstall keyword:.
[oracle@agcns database]$ ./runInstaller -deinstall -home /u01/app/oracle/product/12.1.0.2/db_1/
Checking for required space in /tmp directory ...
Please wait ...
./runInstaller: line 167: [: 61%: integer expression expected
Space check on /tmp directory passed...
Bootstrapping the deinstall components...Done
Location of logs /tmp/deinstall_bootstrap/logs/
                      <<<<< OUTPUT TRIMMED >>>>>>
####################### CLEAN OPERATION SUMMARY #######################
Cleaning the config for CCR
As CCR is not configured, so skipping the cleaning of CCR configuration
CCR clean is finished
Successfully deleted directory '/u01/app/oracle/product/12.1.0.2/db_1' on the local node.
Successfully deleted directory '/u01/app/oraInventory' on the local node.
Oracle Universal Installer cleanup was successful.


Run 'rm -rf /etc/oraInst.loc' as root on node(s) 'agcns' at the end of the session.

Run 'rm -rf /opt/ORCLfmap' as root on node(s) 'agcns' at the end of the session.
Run 'rm -rf /etc/oratab' as root on node(s) 'agcns' at the end of the session.
Oracle deinstall tool successfully cleaned up temporary directories.
#######################################################################

[oracle@agcns database]$ su -
Password: 
[root@agcns ~]# rm -rf /opt/ORCLfmap
[root@agcns ~]# rm -rf /etc/oratab
[root@agcns ~]# rm -rf /etc/oraInst.loc




Credit by:-Valeh Agayev's Oracle blog

Dataguard commands and SQL scripts


PHYSICAL STANDBY COMMANDS
To start redo apply in foreground:
SQL> ALTER DATABASE RECOVER MANAGED STANDBY DATABASE;
To stop redo apply process on the Standby database (to stop MRP):
SQL> ALTER DATABASE RECOVER MANAGED STANDBY DATABASE CANCEL;
To start real-time redo apply:
SQL> ALTER DATABASE RECOVER MANAGED STANDBY DATABASE USING CURRENT LOGFILE DISCONNECT FROM SESSION;
To start redo apply in background:
SQL> ALTER DATABASE RECOVER MANAGED STANDBY DATABASE DISCONNECT FROM SESSION;
or
SQL> RECOVER MANAGED STANDBY DATABASE DISCONNECT;
To check redo apply  and Media recovery service status:
SQL> SELECT PROCESS,STATUS, THREAD#,SEQUENCE#, BLOCK#, BLOCKS FROM V$MANAGED_STANDBY ;
If managed standby recovery is not running or not started with real-time apply, restart managed recovery with real-time apply enabled:
SQL> ALTER DATABASE RECOVER MANAGED STANDBY DATABASE CANCEL;
SQL> ALTER DATABASE RECOVER MANAGED STANDBY DATABASE USING CURRENT LOGFILE DISCONNECT;
To gather Data Guard configuration information(standby)
SQL> SELECT DATABASE_ROLE,OPEN_MODE, PROTECTION_MODE FROM V$DATABASE 

DATABASE_ROLE OPEN_MODE PROTECTION_MODE
---------------- -------------------- --------------------
PHYSICAL STANDBY MOUNTED MAXIMUM PERFORMANCE

SQL> SELECT RECOVERY_MODE FROM V$ARCHIVE_DEST_STATUS WHERE RECOVERY_MODE!='IDLE';

RECOVERY_MODE
-----------------------
MANAGED REAL TIME APPLY
To calculate the Redo bytes per second
SQL> SELECT SUM (BLOCKS * BLOCK_SIZE) / 1024 / 1024 / 60 / 60 / 30 REDO_MB_PER_SEC
 FROM GV$ARCHIVED_LOG
 WHERE FIRST_TIME BETWEEN TO_DATE ('01.05.2016', 'DD.MM.YYYY')
 AND TO_DATE ('01.06.2016', 'DD.MM.YYYY')
To check status of Data Guard synchronization(standby):
SQL> SELECT NAME, VALUE FROM V$DATAGUARD_STATS;

NAME VALUE
--------------------- -------------------------------
transport lag          +00 00:00:00
apply lag              +00 00:00:00
apply finish time      +00 00:00:00.000
estimated startup time 32
To verify there is no log file gap between the primary and the standby database:
SQL> SELECT STATUS, GAP_STATUS FROM V$ARCHIVE_DEST_STATUS WHERE DEST_ID = 3;

STATUS GAP_STATUS
--------- ------------------------
VALID NO GAP

To verify that the primary database can be switched to the standby role:
A value of TO STANDBY or SESSIONS ACTIVE indicates that the primary database can be switched to the standby role. If neither of these values is returned, a switchover is not possible because redo transport is either misconfigured or is not functioning properly.
SQL> SELECT SWITCHOVER_STATUS FROM V$DATABASE; 

SWITCHOVER_STATUS
--------------------
TO STANDBY
To convert the primary database into a physical standby :
Before switchover the current control file is backed up to the current SQL session trace file and it possible to reconstruct a current control file, if necessary.
SQL> ALTER DATABASE COMMIT TO SWITCHOVER TO PHYSICAL STANDBY WITH SESSION SHUTDOWN;

Database altered.
To verify Managed Recovery is running on the standby :
SQL> SELECT PROCESS FROM V$MANAGED_STANDBY WHERE PROCESS LIKE 'MRP%'; 

PROCESS
---------
MRP0
To show information about the protection mode, the protection level, the role of the database, and switchover status:
SQL> SELECT DATABASE_ROLE, DB_UNIQUE_NAME INSTANCE, OPEN_MODE, PROTECTION_MODE, PROTECTION_LEVEL, SWITCHOVER_STATUS FROM V$DATABASE;

DATABASE_ROLE     INSTANCE    OPEN_MODE    PROTECTION_MODE     PROTECTION_LEVEL     SWITCHOVER_STATUS
---------------- ---------- ------------ -------------------- -------------------- -------------------- --------------------
PRIMARY           TESTCDB    READ WRITE    MAXIMUM PERFORMANCE MAXIMUM PERFORMANCE   TO STANDBY
On the standby database, query the V$ARCHIVED_LOG view to identify existing files in the archived redo log.
SQL> SELECT SEQUENCE#, FIRST_TIME, NEXT_TIME FROM V$ARCHIVED_LOG ORDER BY SEQUENCE#;
Or
SQL> SELECT THREAD#, MAX(SEQUENCE#) AS "LAST_APPLIED_LOG" FROM V$LOG_HISTORY GROUP BY THREAD#;
On the standby database, query the V$ARCHIVED_LOG view to verify the archived redo log files were applied.
SELECT SEQUENCE#,APPLIED FROM V$ARCHIVED_LOG ORDER BY SEQUENCE#;


To determine which log files were not received by the standby site.
SQL> SELECT LOCAL.THREAD#, LOCAL.SEQUENCE#
FROM (SELECT THREAD#, SEQUENCE#
FROM V$ARCHIVED_LOG
WHERE DEST_ID = 1) LOCAL
WHERE LOCAL.SEQUENCE# NOT IN (SELECT SEQUENCE#
FROM V$ARCHIVED_LOG
WHERE DEST_ID = 2 AND THREAD# = LOCAL.THREAD#);

Archivelog difference: Run this on the primary database. (not for real-time apply):
SQL> ALTER SESSION SET NLS_DATE_FORMAT = 'DD-MON-YYYY HH24:MI:SS';
SQL> 
SELECT A.THREAD#,
 B.LAST_SEQ,
 A.APPLIED_SEQ,
 A.LAST_APP_TIMESTAMP,
 B.LAST_SEQ - A.APPLIED_SEQ ARC_DIFF
 FROM ( SELECT THREAD#,
 MAX (SEQUENCE#) APPLIED_SEQ,
 MAX (NEXT_TIME) LAST_APP_TIMESTAMP
 FROM GV$ARCHIVED_LOG
 WHERE APPLIED = 'YES'
 GROUP BY THREAD#) A,
 ( SELECT THREAD#, MAX (SEQUENCE#) LAST_SEQ
 FROM GV$ARCHIVED_LOG
 GROUP BY THREAD#) B
 WHERE A.THREAD# = B.THREAD#;

 THREAD#   LAST_SEQ    APPLIED_SEQ  LAST_APP_TIMESTAMP   ARC_DIFF
---------- ---------- -----------   --------------------- ----------
 1         21282      21281         09-IYUL-2016 12:06:5     1
 2         23747      23746         09-IYUL-2016 12:16:13    1

2 rows selected.


To check archive log apply  on primary database:
SQL> SET LINESIZE 150
SET PAGESIZE 999
COL NAME FORMAT A60
COL DEST_TYPE FORMAT A10
COL ARCHIVED FORMAT A10
COL APPLIED FORMAT A10

SELECT SEQUENCE#,
NAME,
DEST_ID ,
CASE WHEN STANDBY_DEST = 'YES' THEN 'Standby' ELSE 'Local' END
AS DEST_TYPE ,
ARCHIVED ,
APPLIED
FROM V$ARCHIVED_LOG
WHERE SEQUENCE# > (SELECT MAX (SEQUENCE#)
FROM V$ARCHIVED_LOG
WHERE STANDBY_DEST = 'YES' AND APPLIED = 'YES')
ORDER BY SEQUENCE# , DEST_ID ;


 SEQUENCE#  NAME                                                          DEST_ID  DEST_TYPE  ARCHIVED APPLIED
---------- -------------------------------------------------------------- -------  ---------- -------- --------
 23748      +FRA/TESTCDB/ARCHIVELOG/2016_07_09/thread_2_seq_23748.10041.9   1      Local        YES       NO
 23748      +DATA/TESTCDB/ARCHIVELOG/2016_07_09/thread_2_seq_23748.10062.   2      Local        YES       NO
 23748      TESTSTB                                                         3      Standby      YES       NO

3 rows selected.



DG BROKER COMMANDS

How to configure Data Guard broker:
1.Start the DMON process on both the primary and standby databases:

SQL> ALTER SYSTEM SET DG_BROKER_START=TRUE SCOPE=BOTH;
System altered.

2.Set the log_archive_dest_2 settings from both the Primary and Standby databases
to be nothing , then try to create the broker configuration (it will automatically 
set the log_archive_dest_n when you'll add a database to the configuration)

SQL> ALTER SYSTEM SET LOG_ARCHIVE_DEST_2='';
System altered.

Connect DGMGRL on the primary DB and create the configuration 

[oracle@primary ~]$ dgmgrl
DGMGRL for Linux: Version 12.1.0.2.0 - 64bit Production
Copyright (c) 2000, 2013, Oracle. All rights reserved.
Welcome to DGMGRL, type "help" for information.
DGMGRL> connect sys/test
Connected as SYSDG.

DGMGRL> CREATE CONFIGURATION 'TEST' AS PRIMARY DATABASE IS 'DB12C' CONNECT IDENTIFIER IS DB12C;
Configuration "TEST" created with primary database "DB12C"

Next add a standby database to the Data Guard broker configuration:

DGMGRL> ADD DATABASE 'db12c_stby' AS CONNECT IDENTIFIER IS 'db12c_stby';
Database "db12c" added

Enable dataguard broker configuration 

DGMGRL> enable configuration;
Enabled.

DGMGRL> show configuration;

Configuration - TEST

 Protection Mode: MaxPerformance
 Members:
 db12c - Primary database
 DB12C_STBY - Physical standby database 

Fast-Start Failover: DISABLED

Configuration Status:
SUCCESS (status updated 40 seconds ago)

To remove DG broker configuration:
DGMGRL> remove configuration;
Removed configuration
Rename the database name in the Data Guard broker as follows:
DGMGRL> edit database 'db12c_stby' rename to 'STBY';
To turn off redo transport to all remote destinations on the primary database:
 DGMGRL> edit database 'DB12C' SET STATE="LOG-TRANSPORT-OFF";
To stop and start redo transport services to specific standby databases:
DGMGRL> edit database 'db12c_stby' SET PROPERTY 'LogShipping'='OFF';
Property "LogShipping" updated
DGMGRL> SHOW DATABASE 'db12c_stby' 'LogShipping';
 LogShipping = 'OFF'
DGMGRL> edit database 'db12c_stby' SET PROPERTY 'LogShipping'='ON';
Property "LogShipping" updated
DGMGRL> SHOW DATABASE 'db12c_stby' 'LogShipping';
 LogShipping = 'ON'
To change the state of the standby database to read-only and back APPLY-ON:
DGMGRL> EDIT DATABASE 'db12c' SET STATE='READ-ONLY';
Succeeded.
DGMGRL> show database db12c

Database - db12c

 Role: PHYSICAL STANDBY
 Intended State: READ-ONLY
<<OUTPUT TRIMMED>>
Database Status:
SUCCESS

To change back:

DGMGRL> shutdown 
DGMGRL> startup mount;
DGMGRL> show database db12c

Database - db12c
 Role: PHYSICAL STANDBY
 Intended State: OFFLINE
  <<OUTPUT TRIMMED>>

DGMGRL> EDIT DATABASE DB12C SET STATE = APPLY-ON;
Succeeded.
DGMGRL> show database db12c

Database - db12c

 Role: PHYSICAL STANDBY
 Intended State: APPLY-ON
 <<OUTPUT TRIMMED>>





LOGICAL STANDBY COMMANDS
To Restart SQL apply on logical standby
SQL> ALTER DATABASE START LOGICAL STANDBY APPLY IMMEDIATE;
To Stop SQL apply on logical standby
SQL> ALTER DATABASE STOP LOGICAL STANDBY APPLY;
Run the following SQL against the logical standby to start real-time SQL apply if the SQL apply failed with an error, and you are 100% certain that the transaction is safe to skip
SQL> ALTER DATABASE START LOGICAL STANDBY APPLY IMMEDIATE SKIP FAILED TRANSACTION;
To see unsupported tables for logical standby:
SQL> SELECT * FROM DBA_LOGSTDBY_UNSUPPORTED_TABLE ORDER BY OWNER, TABLE_NAME;
To know which archive log sequences are at what stage for logical standby?
SQL> SELECT 'RESTART' "TYPE",
 P.RESTART_SCN "SCN",
 TO_CHAR (P.RESTART_TIME, 'yyyy/mm/dd hh24:mi:ss') "TIME",
 L.SEQUENCE# "SEQ#"
 FROM V$LOGSTDBY_PROGRESS P, DBA_LOGSTDBY_LOG L
 WHERE P.RESTART_SCN >= L.FIRST_CHANGE# AND P.RESTART_SCN < L.NEXT_CHANGE#
UNION
SELECT 'RESTART',
 P.RESTART_SCN,
 TO_CHAR (P.RESTART_TIME, 'yyyy/mm/dd hh24:mi:ss'),
 L.SEQUENCE#
 FROM V$LOGSTDBY_PROGRESS P, V$STANDBY_LOG L
 WHERE P.RESTART_SCN >= L.FIRST_CHANGE# AND P.LATEST_SCN <= L.LAST_CHANGE#
UNION
SELECT 'APPLIED',
 P.APPLIED_SCN,
 TO_CHAR (P.APPLIED_TIME, 'yyyy/mm/dd hh24:mi:ss'),
 L.SEQUENCE#
 FROM V$LOGSTDBY_PROGRESS P, DBA_LOGSTDBY_LOG L
 WHERE P.APPLIED_SCN >= L.FIRST_CHANGE# AND P.APPLIED_SCN < L.NEXT_CHANGE#
UNION
SELECT 'APPLIED',
 P.APPLIED_SCN,
 TO_CHAR (P.APPLIED_TIME, 'yyyy/mm/dd hh24:mi:ss'),
 L.SEQUENCE#
 FROM V$LOGSTDBY_PROGRESS P, V$STANDBY_LOG L
 WHERE P.APPLIED_SCN >= L.FIRST_CHANGE# AND P.LATEST_SCN <= L.LAST_CHANGE#
UNION
SELECT 'MINING',
 P.MINING_SCN,
 TO_CHAR (P.MINING_TIME, 'yyyy/mm/dd hh24:mi:ss'),
 L.SEQUENCE#
 FROM V$LOGSTDBY_PROGRESS P, DBA_LOGSTDBY_LOG L
 WHERE P.MINING_SCN >= L.FIRST_CHANGE# AND P.MINING_SCN < L.NEXT_CHANGE#
UNION
SELECT 'MINING',
 P.MINING_SCN,
 TO_CHAR (P.MINING_TIME, 'yyyy/mm/dd hh24:mi:ss'),
 L.SEQUENCE#
 FROM V$LOGSTDBY_PROGRESS P, V$STANDBY_LOG L
 WHERE P.MINING_SCN >= L.FIRST_CHANGE# AND P.LATEST_SCN <= L.LAST_CHANGE#
UNION
SELECT 'SHIPPED',
 P.LATEST_SCN,
 TO_CHAR (P.LATEST_TIME, 'yyyy/mm/dd hh24:mi:ss'),
 L.SEQUENCE#
 FROM V$LOGSTDBY_PROGRESS P, DBA_LOGSTDBY_LOG L
 WHERE P.LATEST_SCN >= L.FIRST_CHANGE# AND P.LATEST_SCN < L.NEXT_CHANGE#
UNION
SELECT 'SHIPPED',
 P.LATEST_SCN,
 TO_CHAR (P.LATEST_TIME, 'yyyy/mm/dd hh24:mi:ss'),
 L.SEQUENCE#
 FROM V$LOGSTDBY_PROGRESS P, V$STANDBY_LOG L
 WHERE P.LATEST_SCN >= L.FIRST_CHANGE# AND P.LATEST_SCN <= L.LAST_CHANGE#;
To know is the SQL Apply up to date
SQL> SELECT TO_CHAR(LATEST_TIME,'yyyy/mm/dd hh24:mi:ss') "LATEST_TIME", 
TO_CHAR(APPLIED_TIME,'yyyy/mm/dd hh24:mi:ss') "APPLIED_TIME", 
APPLIED_SCN, LATEST_SCN 
FROM V$LOGSTDBY_PROGRESS;
To know is the Logical standby applying changes? Run the following SQL against the Logical standby database:
SQL> SELECT REALTIME_APPLY, STATE FROM V$LOGSTDBY_STATE;
If the value of STATE is “NULL” or “SQL APPLY NOT ON” then the Sql Apply is not running.The value of REALTIME_APPLY should be Y to allow for real time apply from the standby redo logs. To know what major Sql Apply events have occurred, run the following SQL against the Logical standby database:
SQL> SELECT TO_CHAR (EVENT_TIME, 'YYYY/MM/DD HH24:MI:SS') "EVENT_TIME",
STATUS, EVENT
FROM DBA_LOGSTDBY_EVENTS
ORDER BY EVENT_TIME;
To know what major Dataguard events have occurred, run the following SQL against the Logical standby database:
SQL> SELECT TO_CHAR (TIMESTAMP, 'yyyy/mm/dd hh24:mi:ss') "TIME",
ERROR_CODE "ERROR", DEST_ID "DEST", MESSAGE
FROM V$DATAGUARD_STATUS
WHERE timestamp > TRUNC (SYSDATE + 6 / 24)
ORDER BY timestamp DESC;


To know where are the archive logs going and are there any achieving issues, run the following SQL against either the logical standby or primary database:
SQL> SELECT DEST_ID "DID",
STATUS, DESTINATION, ARCHIVER, VALID_NOW, VALID_TYPE, VALID_ROLE, ERROR
FROM V$ARCHIVE_DEST
WHERE STATUS <> 'INACTIVE';

Credit:-Valeh Agayev's Oracle blog