Tuesday, February 28, 2023

Docker Commands:

 [root@ip-172-31-34-29 ~]# history

    1  yum update -y

    2  yum install docker

    3  docker --version

    4  systemctl status docker

    5  systemctl start docker

    6  systemctl status docker

    7  ps -aef|Grep docker

    8  ps -ef|grep docker

    9  docker --version

   10  docker pull nginx

   11  docker pull ubuntu

   12  docker images

   13  docker pull httpd

   14  docker run  -d -p 80:80 nginx

   15  docker ps

   16  touch index.html

   17  echo "kishor">index.html

   18  cat index.html

   19  docker cp index.html 6ea34f03afd1:/var/www/html/

   20  docker cp index.html 6ea34f03afd1:/usr/share/nginx/html/

   21  docker ps

   22  history

Sunday, February 26, 2023

Docker

 [root@ip-172-31-6-122 ~]# history

    1  yum update

    2  yum install docker

    3  systemctl start docker

    4  docker ps

    5  systemctl status docker

    6  docker run -d nginx

    7  docker ps

    8  docker run -d --name myweb nginx

    9  docker ps

   10  docker container ls

   11  docker  images

   12  docker pull httpd

   13  docker images

   14  docker ps

   15  history



Docker is a set of platforms as a service (PaaS) products that use the Operating system level visualization to deliver software in packages called containers. Containers are isolated from one another and bundle their own software, libraries, and configuration files; they can communicate with each other through well-defined channels

 

Docker V/S VM:



 

Docker Architecture:

 



 

 

Docker Engine

It is the core part of the whole Docker system. Docker Engine is an application which follows client-server architecture. It is installed on the host machine. There are three components in the Docker Engine:

  • Server: It is the docker daemon called dockerd. It can create and manage docker images. Containers, networks, etc.
  • Rest API: It is used to instruct docker daemon what to do.
  • Command Line Interface (CLI): It is a client which is used to enter docker commands.

 

Docker Client

Docker users can interact with Docker through a client. When any docker commands runs, the client sends them to dockerd daemon, which carries them out. Docker API is used by Docker commands. Docker client can communicate with more than one daemon.

Docker Registries

It is the location where the Docker images are stored. It can be a public docker registry or a private docker registry. Docker Hub is the default place of docker images, its stores’ public registry. You can also create and run your own private registry.

When you execute docker pull or docker run commands, the required docker image is pulled from the configured registry. When you execute docker push command, the docker image is stored on the configured registry.

Docker Objects

When you are working with Docker, you use images, containers, volumes, networks; all these are Docker objects.

Images

Docker images are read-only templates with instructions to create a docker container. Docker image can be pulled from a Docker hub and used as it is, or you can add additional instructions to the base image and create a new and modified docker image. You can create your own docker images also using a dockerfile. Create a dockerfile with all the instructions to create a container and run it; it will create your custom docker image.

Docker image has a base layer which is read-only, and the top layer can be written. When you edit a dockerfile and rebuild it, only the modified part is rebuilt in the top layer.

Containers

After you run a docker image, it creates a docker container. All the applications and their environment run inside this container. You can use Docker API or CLI to start, stop, delete a docker container.

Below is a sample command to run a ubuntu docker container:

docker run -i -t ubuntu /bin/bash

Volumes

The persisting data generated by docker and used by Docker containers are stored in Volumes. They are completely managed by docker through docker CLI or Docker API. Volumes work on both Windows and Linux containers. Rather than persisting data in a container’s writable layer, it is always a good option to use volumes for it. Volume’s content exists outside the lifecycle of a container, so using volume does not increase the size of a container.

You can use -v or –mount flag to start a container with a volume. In this sample command, you are using geekvolume volume with geekflare container.

docker run -d --name geekflare  -v geekvolume:/app nginx:latest

Networks

Docker networking is a passage through which all the isolated container communicate. There are mainly five network drivers in docker:

  1. Bridge: It is the default network driver for a container. You use this network when your application is running on standalone containers, i.e. multiple containers communicating with same docker host.
  2. Host: This driver removes the network isolation between docker containers and docker host. It is used when you don’t need any network isolation between host and container.
  3. Overlay: This network enables swarm services to communicate with each other. It is used when the containers are running on different Docker hosts or when swarm services are formed by multiple applications.
  4. None: This driver disables all the networking.
  5. macvlan: This driver assigns mac address to containers to make them look like physical devices. The traffic is routed between containers through their mac addresses. This network is used when you want the containers to look like a physical device, for example, while migrating a VM setup

 

 

Install Docker:

Create EC2 instance:

Login on ec2 instance as a root.

Execute below command:

#yum update -y

#yum install docker

#systemctl start docker

#systemctl status docker


Thursday, February 23, 2023

Tomcat installation and configuration on linux server

1. Create one EC2 instance: 

2.Login on ec2 instance and swith to root user.

Command: #sudo su -

3.Install java

Command:  #yum install java  

4. Set JAVA_HOME

Command: #export JAVA_HOME=/usr/lib/jvm/java-17-amazon-corretto.x86_64

5. check java home is setup succesfully or not

 Command: #echo $JAVA_HOME

/usr/lib/jvm/java-17-amazon-corretto.x86_64

6. Set path

command: #export  PATH=$PATH:$JAVA_HOME

7. Check java home addedd succesfully in path or not

Commnad: # echo $PATH

O/P:

/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin:/usr/lib/jvm/java-17-amazon-corretto.x86_64

-----------------------

8. Create middleware directory under opt

mkdir /opt/middleware


9. Go to middleware directory and download apache tomcat.

#cd /opt/middleware

#wget https://dlcdn.apache.org/tomcat/tomcat-9/v9.0.72/bin/apache-tomcat-9.0.72.tar.gz


10. Extract tomcat and add admin user in  tomcat-users.xml file

#tar -xvf apache-tomcat-9.0.72.tar.gz

cd apache-tomcat-9.0.72/conf

#ls -l

vi  tomcat-users.xml

<role rolename="tomcat"/>

<role rolename="manager-gui"/>

<role rolename="admin-gui"/>

<role rolename="manager-script"/>

<role rolename="manager-jmx"/>

<user username="admin" password="admin" roles="tomcat,manager-gui,admin-gui,manager-script,manager-jmx"/>


---

11.Go to /opt/middleware/apache-tomcat-9.0.72/webapps/manager/META-INF and /opt/middleware/apache-tomcat-9.0.72/webapps/host-manager/META-INF and comment out below content

 <!--

  <Valve className="org.apache.catalina.valves.RemoteAddrValve"

         allow="127\.\d+\.\d+\.\d+|::1|0:0:0:0:0:0:0:1" />

  <Manager sessionAttributeValueClassNameFilter="java\.lang\.(?:Boolean|Integer|Long|Number|String)|org\.apache\.catalina\.filters\.CsrfPreventionFilter\$LruCache(?:\$1)?|java\.util\.(?:Linked)?HashMap"/> -->


12. Start tomcat

[root@ip-172-31-15-218 bin]# pwd

/opt/middleware/apache-tomcat-9.0.72/bin

[root@ip-172-31-15-218 bin]# ./startup.sh

#ps -ef|grep java 

#ps -ef|grep tomcat


13. Deploy application on tomcat.

[root@ip-172-31-15-218 webapps]# pwd

/opt/middleware/apache-tomcat-9.0.72/webapps

#wget https://github.com/AKSarav/SampleWebApp/raw/master/dist/SampleWebApp.war

Note : context path is SampleWebApp

#ls -l  ==> you will see your war and respective directory.


14.go browser and access your application: 

http://public-ip:8080/SampleWebApp




Monday, February 20, 2023

Jenkins Pipeline

 Scripted Pipeline:

  • Written in Groovy language
  • Provides a lot of power and flexibility
  • Allows for more complex pipeline structures and branching logic
  • Requires advanced knowledge of Groovy
  • Can be more challenging to maintain and manage
  • Uses imperative programming style with more code control and more verbose

Declarative Pipeline:

  • Written in a simpler, more structured syntax
  • Provides a simpler and more opinionated way of defining pipelines
  • Allows for easier error-checking and validation
  • Offers a simplified structure with less verbose code
  • Supports stage-level directives like when, parallel, input, and environment
  • Provides a more standardized structure that is easier to read and understand


Declarative Pipeline:
pipeline {
  agent any
  environment {
    DB_NAME = 'my_database'
    DB_USER = 'my_user'
    DB_PASS = 'my_password'
  }
  stages {
    stage('Build') {
      steps {
        sh 'mvn clean package'
      }
    }
    stage('Test') {
      steps {
        sh 'mvn test'
      }
    }
    stage('Deploy') {
      when {
        branch 'master'
      }
      steps {
        withCredentials([usernamePassword(credentialsId: 'my-credentials', usernameVariable: 'USERNAME', passwordVariable: 'PASSWORD')]) {
          sh './deploy.sh ${DB_NAME} ${DB_USER} ${DB_PASS} ${USERNAME} ${PASSWORD}'
        }
      }
    }
  }
  post {
    always {
      cleanWs()
    }
    success {
      slackSend message: "Build Succeeded: ${currentBuild.fullDisplayName}", color: 'good'
    }
    failure {
      slackSend message: "Build Failed: ${currentBuild.fullDisplayName}", color: 'danger'
    }
  }
}

Jenkins Declarative and Scripted pipeline reference:

https://www.jenkins.io/doc/book/pipeline/

Access local tomcat applications globally

Access local web and application server globally.

Steps 1) Download node JS from https://nodejs.org/en/ and install it.

C:\Users\Kishor>node --version
v18.14.1


Step 2) Install localtunnel.

C:\Users\Kishor>npm install -g localtunnel

added 22 packages in 3s

3 packages are looking for funding
  run `npm fund` for details
npm notice
npm notice New minor version of npm available! 9.3.1 -> 9.5.0
npm notice Changelog: https://github.com/npm/cli/releases/tag/v9.5.0
npm notice Run npm install -g npm@9.5.0 to update!
npm notice

C:\Users\Kishor>lt --port 8080 
your url is: https://busy-dots-follow-103-115-203-227.loca.lt







Sunday, February 19, 2023

maven setup

 yum install maven

export JAVA_HOME=/usr/lib/jvm/java-17-amazon-corretto.x86_64

echo $PATH

echo $JAVA_HOME

export PATH=$JAVA_HOME/bin:$PATH

mvn --version

java -version


Sunday, February 12, 2023

Maven

Maven is a popular build automation tool used primarily for Java projects. It is an open-source tool developed by the Apache Software Foundation and is widely used for building, testing, and deploying software projects.

Maven provides a standard way to build and manage projects, making it easier for developers to collaborate on a project. It helps to manage the following aspects of a software project:

  1. Builds - Maven automates the build process and compiles, tests, and packages the code into a distributable format, such as a JAR or WAR file.

  2. Dependencies - Maven manages the dependencies of a project, automatically downloading and storing them in a local repository.

  3. Documentation - Maven can generate project documentation, such as reports and web sites, based on the project's metadata.

  4. Plugins - Maven provides a large number of plugins that can be used to extend its functionality, making it easier to integrate with other tools and technologies



Maven is a build automation tool that provides a standard way to build and manage projects in Java. In Maven, a build is divided into phases, and each phase represents a specific step in the build process. The default lifecycle in Maven is a pre-defined sequence of phases that builds, packages, and deploys a project.

The phases of the default Maven lifecycle are:

  1. validate - validate the project is correct and all necessary information is available
  2. compile - compile the source code of the project
  3. test - test the compiled source code using a suitable unit testing framework
  4. package - package the compiled code into a distributable format, such as a JAR or WAR file
  5. integration-test - process and deploy the package if necessary into an environment where integration tests can be run
  6. verify - run any checks to verify the package is valid and meets quality criteria
  7. install - install the package into the local repository, for use as a dependency in other projects locally
  8. deploy - done in the build environment, copies the final package to the remote repository for sharing with other developers and projects.

Note that not all phases are executed every time a build is run. The specific phases that are executed depend on the goals that are specified in the command used to run the build.


A Project Object Model (POM) file is an XML file used by Maven to define a project's build and configuration details. The POM file contains information about the project, its dependencies, the build process, and the plugins used to build and manage the project.

Here are some of the key fields in a POM file:

  1. project: This section contains the general information about the project, such as its name, description, and the URL for the project's homepage.

  2. parent: If the project is a module of a larger project, the parent section is used to specify the parent project and its POM file.

  3. packaging: Specifies the type of artifact that will be generated by the build process, such as a JAR or WAR file.

  4. dependencies: Lists the external libraries that the project depends on, including the groupId, artifactId, and version of each library. Maven will automatically download and manage these dependencies.

  5. build: Defines the build process, including the plugins used, the output directory, and any additional configuration options.

  6. plugins: Lists the plugins used by Maven to perform various tasks, such as compiling the source code, testing the code, and generating reports.

  7. profiles: Specifies different configurations for the build process, allowing for different settings to be used for different environments, such as development and production.

  8. properties: Defines properties that can be used throughout the POM file, making it easier to manage common values such as versions and URLs.

These are some of the key fields in a POM file, but it can also contain other information such as distribution management, reporting, and more. The structure and content of a POM file can vary based on the needs of the project, and the flexibility of the POM file is one of the key strengths of Maven.


<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>com.example</groupId> <artifactId>my-project</artifactId> <packaging>jar</packaging> <version>1.0-SNAPSHOT</version> <name>My Project</name> <url>http://maven.apache.org</url> <dependencies> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>3.8.1</version> <scope>test</scope> </dependency> </dependencies> </project>



Maven repositories are the locations where Maven stores the libraries and other dependencies that a project requires. There are three types of Maven repositories:

  1. Local Repository: A local repository is a repository that is stored on the developer's local machine. Maven automatically downloads and caches dependencies in the local repository, making it faster to build the project again in the future. The local repository is located in the .m2 directory in the user's home directory.

  2. Central Repository: The Central Repository is a publicly accessible repository that is maintained by the Apache Software Foundation. It contains a large number of popular libraries and is used by Maven as the default repository. When Maven cannot find a dependency in the local repository, it will look for it in the Central Repository.

  3. Remote Repository: A remote repository is a repository that is located on a remote server. Remote repositories are used to store internal or proprietary libraries that are not publicly accessible. Remote repositories can be hosted on a corporate network or in the cloud. Maven can be configured to use remote repositories by specifying their location in the settings.xml file.

Each repository has its own unique URL, and dependencies are retrieved from the repositories using their URL. When a project is built using Maven, it will first look for the required dependencies in the local repository. If the dependencies are not found, Maven will look for them in the Central Repository, and finally, in any specified remote repositories.


Maven Installation:

https://maven.apache.org/download.cgi






Maven Central Repository URL: https://repo.maven.apache.org/maven2/

Maven


Sample Game App Deployment on EKS cluster

 https://padmakshi.medium.com/setting-up-an-eks-cluster-and-deploying-a-game-application-a-step-by-step-guide-08790e0be117