Monday 11 July 2016

How to Install & Configure Docker in Centos/RHEL 6

Install & Configure Docker in Centos/RHEL 6


What is Docker?


Docker is all about making it easier to create, deploy, and run applications by using containers. Containers allow a developer to package up an application with all of the parts it needs, such as libraries and other dependencies, and ship it all out as one package. By doing so, thanks to the container, the developer can rest assured that the application will run on any other Linux machine regardless of any customized settings that machine might have that could differ from the machine used for writing and testing the code.

In a way, Docker is a bit like a virtual machine. But unlike a virtual machine, rather than creating a whole virtual operating system, Docker allows applications to use the same Linux kernel as the system that they're running on and only requires applications be shipped with things not already running on the host computer. This gives a significant performance boost and reduces the size of the application.



And importantly, Docker is open source. This means that anyone can contribute to Docker and extend it to meet their own needs if they need additional features that aren't available out of the box.



Requirements:-


1. Centos/RHEL 6.X
2. 2 GB RAM (Recommanded)
3. 50 GB HDD
4. Virtual IP on a Virtual NIC (** For production the Virtual IP Will be a Public IP)

** Here the Virtual IP is: 10.100.100.118 & the Virtual NIC is eth0:1

Step 1: Stop the Selinux, and Update the Date Time on the Server :



# vi /etc/sysconfig/selinux

SELINUX=disabled ###(Change enabled to disabled)

--- save & quit (:wq) ---

# service ntpd restart
# ntpdate pool.ntp.org
# chkconfig ntpd on

Step 2: Install & Configure Docker :



# yum -y install epel-release
# yum -y update
# yum -y install docker-io
# service docker start
# chkconfig docker on
# service iptables save

Note: ** Now the IPTales will save with all the Rules & Chains will save to the IPTables Main File.



Step 3: Download Images and Configure Docker Container :



Note: ** What kind of OS need that can be find by the Docker Search, Here using the centos6.6 Image for Example, For find a Image with the Version Run the Below Command-



# docker search <OS> (i.e., # docker search ubuntu)

** We are doing with Centos 6.6-
** To download an Image Run the Below Command

# docker pull centos:6.6

** To see the Downloaded Image Run the Below Command

# docker images

** To create a Docker Instance With a Dedicated IP and with the Port Binding for Accessing the VMs from Outside Do the Following things



# cd /etc/sysconfig/network-scripts/
# cp ifcfg-eth0 ifcfg-eth0:1
# vi ifcfg-eth0:1

### Delete All Lines and Add these Lines

DEVICE=eth0:1
TYPE=Ethernet
UUID=0c1b31b3-bcde-4a28-b2b0-581d3f01e33a
ONBOOT=yes
NM_CONTROLLED=no
BOOTPROTO=static
IPADDR=10.100.100.118
NETMASK=255.255.0.0
GATEWAY=10.100.1.1

---- save & quit (:wq) ----

# ifup eth0:1

** If the NIC doesn't comes up then Run the Below Command-



# service network restart

# ifconfig

** Check the NIC's once that every NIC is up.



** Now Create a Docker Container with the IP 10.100.100.118 with Port Bind to Host Port 5000 to Container's 22 Port-



# docker run -i -t -p <IP>:<Host Port>:<Container's Port> --privileged --name <Any Name> <Image name> <Command> ## --privileged is for run the container with a Root Privileges

# docker run -i -t -p 10.100.100.118:5000:22 --privileged --name NEWVM centos:6.6 /bin/bash

** After run this Command you will Enter into the Container



[root@df4b1cb88bd8 /]# yum -y install openssh*
[root@df4b1cb88bd8 /]# vi /etc/ssh/sshd_config

## Uncomment the Line at Line Number 42
PermitRootLogin yes

---- save & quit (:wq) ----

# service sshd restart
# chkconfig sshd on

** Set root Password; for here its Passw0rd



# passwd root
# netstat -tulpn |grep 22

** To check that the SSH port is Running and Open.



** Now connect the Container from Outside by the IP: 10.100.100.118 Port: 5000 User: root Pass: Passw0rd



Step 4: Set the Httpd for the Created Container with the Virtual IP with 8080 Port :



# service iptables save
# docker stop NEWVM
# docker commit NEWVM newimage02
# docker run -i -t -p 10.100.100.118:5000:22 -p 10.100.100.118:8080:80 --privileged --name NEWVM newimage02 /bin/bash

[root@df4b1cb88bd8 /]# service sshd restart
[root@df4b1cb88bd8 /]# exit

# service iptables save

** Connect the VM through SSH from Outside by the IP: 10.100.100.118 Port: 5000 User: root Pass: Passw0rd



[root@df4b1cb88bd8 /]# yum -y install httpd httpd-devel
[root@df4b1cb88bd8 /]# service httpd restart
[root@df4b1cb88bd8 /]# chkconfig httpd on

** Now check on Brwoser Apache Default Page Will come:



http://10.100.100.118:8080

Step 5: Set the MySLQ for the Created Container with the Virtual IP with 3030 Port :



# service iptables save
# docker stop NEWVM
# docker commit NEWVM newimage01
# docker rm NEWVM
# docker run -i -t -p 10.100.100.118:5000:22 -p 10.100.100.118:3030:3306 --privileged --name NEWVM newimage01 /bin/bash

[root@df4b1cb88bd8 /]# service sshd restart
[root@df4b1cb88bd8 /]# exit

# service iptables save

** Connect the VM through SSH from Outside by the IP: 10.100.100.118 Port: 5000 User: root Pass: Passw0rd



[root@df4b1cb88bd8 /]# yum -y install mysql-server mysql-devel
[root@df4b1cb88bd8 /]# service mysqld restart
[root@df4b1cb88bd8 /]# chkconfig mysqld on
[root@df4b1cb88bd8 /]# mysql_secure_installation

Step 6: Some Special Notes:-



** After Restarting the Docker Container/Main Server if the SSH not working with the Virtual/Public IP the have to login into the Docker and Restart the SSH once.



** To check the Docker Containers Lists-



# docker ps -a

# docker exec -it <Container Name> /bin/bash
[root@df4b1cb88bd8 /]# service sshd restart
[root@df4b1cb88bd8 /]# service httpd restart

Then check the SSH & Http Connections Again

** To take Backup of a Container or Create an Image from a Container Run the Following Command:-



# docker commit <Container Name/ID> <New Image Name>
# docker commit NEWVM image01

** To Check the Ports that Which Host Port Assign to Which Container's Port Run the Following Command:-



# docker port <Container Name/ID>
# docker port NEWVM


*** If Need to Open more that the Existing port for the Container then do the Following Things:-



# docker stop <Container Name/ID>
# docker commit <Container Name/ID> <New Image Name>
# docker rm <Container Name/ID>
# docker run -i -t -p <Virtual IP>:<Physical Host>:<Container's Port> -p <Virtual IP>:<Physical Host>:<Container's Port> -p <Virtual IP>:<Physical Host>:<Container's Port> --privileged --name <New Container Name> <The Saved Image Name> /bin/bash

** Then Check the Container As Previously Described



Thanks For Visiting on My Blog, For More Tutorials Keep Visiting My Blog.

How to Install & Configure Apache for both GUI & CLI mode on CentOS/RHEL 6.X

Install & Configure Apache for both GUI & CLI mode on CentOS/RHEL 6.X


What is ApacheGUI?


This tools is a free and open source package designed for system administrators to manage the functionality of Apache Web Server from a browser, such as edit configuration and web document files directly from browser, download, search or visualize Apache Logs in real time, install, edit or remove Apache modules, view runtime statistics or detailed graphs transactions of Apache HTTP Server.



Step 1: Stop the Selinux, and Update the Date Time on the Server :



# vi /etc/sysconfig/selinux

SELINUX=disabled ###(Change enabled to disabled)

--- save & quit (:wq) ---

# service iptables stop
# chkconfig iptabes off
# yum -y install ntpd
# service ntpd restart
# ntpdate pool.ntp.org
# chkconfig ntpd on

Step 2: Install Java of your choise. here installed open jdk you can install oracle java also:



# yum -y install httpd httpd-develjava

Step 3: Download ApacheGUI:



# cd /opt
# wget http://jaist.dl.sourceforge.net/project/apachegui/1.11-Linux-Solaris-Mac/ApacheGUI-1.11.0.tar.gz
# tar -zxvf ApacheGUI-1.11.0.tar.gz
# cd ApacheGUI/bin

Step 4.Start the server:



# ./run.sh
# service iptables stop

If you want to Change the server port from 9999.

# vi /opt/ApacheGUI/tomcat/conf/server.xml

find 9999 and change to any port you like.

Step 5. Configure Apache GUI:



Browse : http://Server-IP/Domain:9999/ApacheGUI/



Use following credentials to login into ApacheGUI tool If Asked

Username: admin
Password: admin

Step 6. Configure Apache GUI from Web Panel :


Next, the tool will prompt you on How Apache Web Server was installed?
Choose Package option, if you installed Apache on RHEL/CentOS using yum package management tool and hit OK to move forward.

Server Root: /etc/httpd
Primary Configuration File: /etc/httpd/conf/httpd.conf
Configuration Directory: /etc/httpd
Log Directory: /logs
Modules Directory: /etc/httpd/modules
Binary File: /usr/sbin/apachectl
Username: root
Password: redhat
Password: redhat

** After you finish hit on Submit button to apply configuration and you’re done.
** Now you can control Apache Web Server with all its configuration files and edit web documents directly from your browser

Step 7. Create init script for Apache GUI :



# vi /etc/init.d/apache-gui

#!/bin/sh
#
#
# System startup script for apache-gui
#
### BEGIN INIT INFO
# Provides: apache-gui
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: Start the apache-gui
# Description:       Start the apache-gui
### END INIT INFO
#
# chkconfig: 2345 20 80
# description: Runs the apache-gui
# processname: apache-gui
#
# Source function library
. /etc/init.d/functions

case "$1" in
    start)
    cd /opt/ApacheGUI/bin/
./run.sh
       ;;
    stop)
   cd /opt/ApacheGUI/bin/
./stop.sh
        ;;
restart)
cd /opt/ApacheGUI/bin/
./stop.sh
./run.sh
    *)
        echo $"Usage: $0 {start|stop}"
        exit 2
esac
exit $?

--- save & quit (:wq) ---

# chmod 755 /etc/init.d/apache-gui

** Start apchegui as the service now.

# service apache-gui start
# service apache-gui stop
# chkconfig apache-gui on

Thanks For Visiting on My Blog, For More Tutorials Keep Visiting My Blog.