Docker_WordPress

Docker_WordPress

We are going to setup the WordPress site with ubuntu image.

 

Host setting:

CentOS Linux release 7.1.1503 (Core)
Linux rhel7 3.10.0-229.el7.x86_64 #1 SMP Fri Mar 6 11:36:42 UTC 2015 x86_64 x86_64 x86_64 GNU/Linux
 

Prerequisite of host server:

  • Docker must installed.

You can check using below command.

[root@rhel7 ~]# docker –version

Docker version 1.12.6, build 88a4867/1.12.6

 

Then pull Ubuntu image for a lab setup.

# docker pull ubuntu

Check docker image downloaded or not.
# docker images
REPOSITORY                              TAG                 IMAGE ID            CREATED             SIZE
docker.io/ubuntu                        latest              ea4c82dcd15a        11 days ago         85.85 MB

 

Now start two containers with ubuntu image.

  • First for web application with port map 82 to 80 and
  • second for database with port map 3306 to 3306.
# docker run -it –name ubuntu_apache -p 82:80 docker.io/ubuntu
# docker run -it –name ubuntu_mysql -d  -p 3306:3306 docker.io/ubuntu

 

Check docker process are start and running.

[root@rhel7 ~]# docker ps -a

CONTAINER ID        IMAGE                                  COMMAND                  CREATED             STATUS                   PORTS                    NAMES
0b834a2e1484        docker.io/ubuntu                       "/bin/bash"              3 hours ago         Up 3 hours               0.0.0.0:3306->3306/tcp   ubuntu_mysql
c92a3e450ca1        docker.io/ubuntu                       "/bin/bash"              13 days ago         Up 5 hours               0.0.0.0:82->80/tcp       ubuntu_apache

Here you can see port configuration.

0.0.0.0:3306->3306/tcp   and  0.0.0.0:82->80/tcp

 

Now configure web application container.

Login to web application container with below command.

List “CONTAINER ID“

[root@rhel7 ~]# docker ps -a
CONTAINER ID        IMAGE                                  COMMAND                  CREATED             STATUS                   PORTS                    NAMES
0b834a2e1484        docker.io/ubuntu                       "/bin/bash"              3 hours ago         Up 3 hours               0.0.0.0:3306->3306/tcp   ubuntu_mysql
c92a3e450ca1        docker.io/ubuntu                       "/bin/bash"              13 days ago         Up 5 hours               0.0.0.0:82->80/tcp       ubuntu_apache

Here we can see “CONTAINER ID” of “ubuntu_apache” is “c92a3e450ca1”.

 

Now login into the container.

[root@rhel7 ~]# docker exec -it c92a3e450ca1 bash

Now we have prompt look like “root@c92a3e450ca1:/#”.

 

Next we install all Prerequisite(Apache, PHP, PHP-Mysql) in ubuntu container.

root@c92a3e450ca1:/# apt-get update
root@c92a3e450ca1:/# apt install apache2
root@c92a3e450ca1:/# apt-get install php libapache2-mod-php php-mysql php-pear php-fpm

 

Check apache is accessible on port “82” or not.

  root@c92a3e450ca1:/# service apache2 restart

Access URL on the browser.

 

Now deploy WordPress source code in the container.

Copy WordPress zip file to container.

# docker cp  wordpress-4.9.8.tar.gz  c92a3e450ca1:/var/www/html/

Then login into container and unzip source code.

[root@rhel7 ~]# docker exec -it c92a3e450ca1 bash
                root@c92a3e450ca1:/# cd /var/www/html
root@c92a3e450ca1:/# gunzip wordpress-4.9.8.tar.gz
root@c92a3e450ca1:/# tar xvf wordpress-4.9.8.tar

 

Now configure Database container.

Log in to Database container with below command.

List “CONTAINER ID“

[root@rhel7 ~]# docker ps -a
CONTAINER ID        IMAGE                                  COMMAND                  CREATED             STATUS                   PORTS                    NAMES
0b834a2e1484        docker.io/ubuntu                       "/bin/bash"              3 hours ago         Up 3 hours               0.0.0.0:3306->3306/tcp   ubuntu_mysql
c92a3e450ca1        docker.io/ubuntu                       "/bin/bash"              13 days ago         Up 5 hours               0.0.0.0:82->80/tcp       ubuntu_apache

Here we can see “CONTAINER ID” of “ubuntu_mysql” is “0b834a2e1484”.

Now login into a container.

[root@rhel7 ~]# docker exec -it 0b834a2e1484 bash

Now we have prompt look like “root@0b834a2e1484:/#”.

 

Next, we install all Prerequisite(Mysql) in ubuntu container and configure it.

root@0b834a2e1484:/# apt-get update
root@0b834a2e1484:/# apt install mysql-server

 

Add this line to access MySql in a network or on IP.

root@0b834a2e1484:/# cat /etc/mysql/my.cnf
[mysqld]
bind-address    = 0.0.0.0

 

Now start MySql service and configure it.

root@0b834a2e1484:/# service mysql restart

 

To set root account password and other setting

root@0b834a2e1484:/# mysql_secure_installation 

 

Now login into a database. After that create one database with user access to setup WordPress site.

Here database is “feenix” user is “bnm” and password is “Redhat@12345

root@0b834a2e1484:/# mysql -u root -p
Enter password:
mysql> create database feenix;
mysql> grant all privileges on *.* to 'bnm'@'%' identified by 'Redhat@12345';
mysql> FLUSH PRIVILEGES;
mysql> commit;

 

Now again restart Mysql service.

root@0b834a2e1484:/# service mysql restart

 

In a web application container.

Now right time to update database information in WordPress “wp-config-sample.php”.

root@c92a3e450ca1:/# cd /var/www/html/wordpress/
root@c92a3e450ca1:/# vim wp-config-sample.php

 

 

Make a copy of “wp-config-sample.php” with a name of “wp-config.php”

root@c92a3e450ca1:/# cp  wp-config-sample.php wp-config.php

Now access URL on the browser. We have WordPress installation page which indicates web application server successfully communicate with a database server.  

 

After installation, we have a new WordPress website.

 

Shell_Script

Shell_Script

Shell script for simple addition, subtraction and multiplication using case and function.

####################################################################

#!/bin/sh
#Script depend on three argument. first two are values and last one is operation
#Add Function for each operation
add() {
        result=`expr $1 + $2`;
        echo "Addition of $1 and $2 :- $result";
}

sub() {
        result=`expr $1 – $2`;
        echo "Subtraction of $1 and $2 :- $result";
}

mult() {
        result=`expr $1 \* $2`;
        echo "Multiply of $1 and $2 :- $result";
}

#Checking case with third value.
#Pass two argument $1 and $2 to function
case $3 in
add )
    add $1 $2 ;;
sub )
    sub $1 $2 ;;
mult )
    mult $1 $2 ;;
all )
    add $1 $2 ;
    sub $1 $2 ;
    mult $1 $2 ;;
esac

—————————————————-

Output look like:-

[root@rhel7 Script]# ./cash.sh 2 30 all
Addition of 2 and 30 :- 32
Subtraction of 2 and 30 :- -28
Multiply of 2 and 30 :- 60

####################################################################       

PXE_With_Kick-Start

PXE_With_Kick-Start

 

PXE Boot with kick-start configuration.

 

Configure PXE server.

[root@feenixdv_pix tftpboot]# cat /etc/redhat-release

CentOS Linux release 7.1.1503 (Core)

Step 1 :-

Install CentOS/RHEL on the virtual machine or any physical machine.

Step 2 :-

Install some prerequisite on PXE Server.

  • vsftpd
  • DHCP
  • xinted
  • tftp-server
  • syslinux

Step 3 :-

To install these package configure local YUM repository with FTP.

YUM configuration:-

                1st copy all data from CDROM to “/var/ftp/pub” location

                Next update yum repo file.

[root@feenixdv_pix tftpboot]# mount /dev/cdrom /mnt/
                                [root@feenixdv_pix tftpboot]# cat /etc/yum.repos.d/my.repo
                         [FTP]
name= feenixdv
baseurl=ftp://192.168.43.206/pub
gpgcheck=0
enable=1

Note:- To use this setting “vsftpd” must be install first and start “vsftpd” service.

 

Step 4 :-

  • Install all package after yum configuration.

     

     

     

     

    • yum install dhcp –y
    • yum install tftp-server
    • yum install syslinux

xinted automation installed with syslinux.

Step 5 :-

Now configure DHCP server.

Copy “dhcpd.conf” from from example file.

cat /usr/share/doc/dhcp-4.2.5/dhcpd.conf.example > /etc/dhcp/dhcpd.conf

                update “/etc/dhcp/dhcpd.conf” according to network setting.

 

Step 6 :-

Now configure TFTP-SERVER server.

Then copy and create some configuration file for PXE installation.

[root@feenixdv_pix tftpboot]# cd /var/lib/tftpboot
[root@feenixdv_pix tftpboot]# cp /mnt/isolinux/* .  (Copy bootable file from CD)
[root@feenixdv_pix tftpboot]# mkdir pxelinux.cfg
[root@feenixdv_pix tftpboot]# vim pxelinux.cfg/default

Configure «default».

Step 7 :-

Now configure kick-start file.

                Copy this.

[root@feenixdv_pix tftpboot]# cp /root/anaconda-ks.cfg /var/ftp/pub/ks.cfg      

                Need to add url

Then copy “pxelinux.0” which was define in dhcpd.conf

cp /usr/share/syslinux/pxelinux.0 /var/lib/tftpboot/

Step 8 :-

Start all services and check on also.

[root@feenixdv_pix tftpboot]# systemctl restart vsftpd xinetd dhcpd

[root@feenixdv_pix tftpboot]# systemctl enable  vsftpd xinetd tftp.service dhcpd

Note:- Cross check firewall and selinux are disabled.

Now install new VM without in boobable media or source disk.

Some advance configuration in PXE for multiple version option.

For example we want to install RHEL5, RHEL6 and RHEL7 using PXE then first need to create same structure in “/var/ftp/pub” directory.

For RHEL5.

  • Create directory “/var/ftp/pub/rhel5”
  • Copy all package inside directory including ks.cfg, vmlinuz and initrd.img file.

Same for RHEL6 and RHEL7

Now update “/var/lib/tftpboot/pxelinux.cfg/default” and add below entry.

label RHEL_5
  menu label Install RedHat 5
  kernel rhel5/vmlinuz
  append initrd=rhel5/initrd.img ks=ftp://192.168.43.206/pub/rhel5/ks.cfg repo=ftp://192.168.43.206/pub/rhel5
  
label RHEL_6
  menu label Install RedHat 6
  kernel rhel6/vmlinuz
  append initrd=rhel6/initrd.img ks=ftp://192.168.43.206/pub/rhel6/ks.cfg repo=ftp://192.168.43.206/pub/rhe6
 
label RHEL_7
  menu label Install RedHat 7
  kernel rhel7/vmlinuz
  append initrd=rhel7/initrd.img ks=ftp://192.168.43.206/pub/rhel7/ks.cfg repo=ftp://192.168.43.206/pub/rhel7

Now again restart all services. After that we have below boot option on PXE boot.