├── Ansible └── Ansible_installation.MD ├── Docker ├── DockerHub.MD ├── Docker_Commands.MD ├── Docker_Installation_Steps.MD └── install_apache_dockerfile.txt ├── Jenkins ├── Ansible_integration.MD ├── Git_plugin_install.MD ├── Installation.MD ├── junit_plugin_setup.MD └── maven_install.MD ├── Nexus └── Nexus_Installation.MD ├── Nginx └── nginx_installation.MD ├── ProjectDemos ├── Project-01.MD ├── Project-02.MD ├── Project-3.MD ├── Project-4.MD └── images │ └── Project-4.png ├── README.md ├── SonarQube ├── SonarQube_Installation.MD └── Sonar_Integration_with_Jenkins.MD └── Tomcat └── tomcat_installation.MD /Ansible/Ansible_installation.MD: -------------------------------------------------------------------------------- 1 | # Ansible Installation 2 | 3 | Ansible is an open source automation platform. It is very, very simple to setup and yet powerful. Ansible can help you with configuration management, application deployment, task automation. 4 | 5 | ### Follow this in **[YouTube](https://www.youtube.com/watch?v=79xFyOc_eEY) 6 | 7 | ### Prerequisites 8 | 9 | 1. An AWS EC2 instance 10 | 11 | ### Installation steps: 12 | 13 | Add a EPEL (Extra Packages for Enterprise Linux)third party repository to get packages for Ansible 14 | ```sh 15 | rpm -Uvh https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm 16 | ``` 17 | 18 | Install Ansible 19 | ```sh 20 | yum install ansible -y 21 | ``` 22 | 23 | Check Ansible version 24 | 25 | ```sh 26 | ansible --version 27 | ``` 28 | 29 | Create a new user for ansible administration & grant admin access to user (Master and Slave) 30 | ```sh 31 | useradd ansadmin 32 | passwd ansadmin 33 | # below command addes ansadmin to sudoers file. But strongly recommended to use "visudo" command if you are aware vi or nano editor. 34 | echo "ansadmin ALL=(ALL) ALL" >> /etc/sudoers 35 | ``` 36 | 37 | Using keybased authentication is advised. If you are still at learning stage use password based authentication (Master & Slave) 38 | ```sh 39 | # sed command replaces "PasswordAuthentication no to yes" without editing file 40 | sed -ie 's/PasswordAuthentication no/PasswordAuthentication yes/' /etc/ssh/sshd_config 41 | ``` 42 | Login as a ansadmin user on master and generate ssh key (Master) 43 | ```sh 44 | ssh-keygen 45 | ``` 46 | Copy keys onto all ansible client nodes (Master) 47 | ```sh 48 | ssh-copy-id 49 | ``` 50 | 51 | Update target servers information on /etc/ansible/hosts file (Master) 52 | ```sh 53 | echo "" > /etc/ansible/hosts 54 | ``` 55 | Run ansible command as ansadmin user it should be successful (Master) 56 | ```sh 57 | ansible all -m ping 58 | ``` 59 | -------------------------------------------------------------------------------- /Docker/DockerHub.MD: -------------------------------------------------------------------------------- 1 | ## What is Docker Hub Registry 2 | 3 | Docker Hub is a cloud-based registry service which allows you to link to code repositories, build your images and test them, stores manually pushed images, and links to Docker Cloud so you can deploy images to your hosts. It provides a centralized resource for container image discovery, distribution and change management, user and team collaboration, and workflow automation throughout the development pipeline. 4 | 5 | ##### Ref URL : https://docs.docker.com/docker-hub/ 6 | 7 | 1. Create a docker hub account in https://hub.docker.com/ 8 | 9 | 2. Pull a docker image 10 | 11 | ```sh 12 | docker pull ubuntu 13 | ``` 14 | 15 | 3. pull a docker image with old version 16 | 17 | ```sh 18 | docker pull ubuntu:16.04 19 | ``` 20 | 21 | 4. create a custom tag to docker image 22 | ```sh 23 | docker tag ubuntu:latest valaxy/ubuntu:demo 24 | ``` 25 | 26 | 5. login to your docker hub registry 27 | ``sh 28 | docker login 29 | ``` 30 | 6. docker push valaxy/ubuntu:demo 31 | ``` 32 | 33 | ### testing 34 | 35 | 1. Remove all images in docker server 36 | ```sh 37 | docker image rm -f 38 | ``` 39 | 40 | 2. Pull your custom image from your docker account 41 | ```sh 42 | docker pull valaxy/ubuntu:demo 43 | ``` 44 | 45 | -------------------------------------------------------------------------------- /Docker/Docker_Commands.MD: -------------------------------------------------------------------------------- 1 | 2 | 1. how to search a docker image in hub.docker.com 3 | ```sh 4 | docker search httpd 5 | ``` 6 | 2. Download a docker image from hub.docker.com 7 | ```sh 8 | docker image pull : 9 | ``` 10 | 11 | 3. List out docker images from your local system 12 | ```sh 13 | docker image ls 14 | ``` 15 | 16 | 4. Create/run/start a docker container from image 17 | ```sh 18 | docker run -d --name : 19 | 20 | d - run your container in back ground (detached) 21 | ``` 22 | 23 | 5. Expose your application to host server 24 | ```sh 25 | docker run -d -p : --name : 26 | 27 | docker run -d --name httpd_server -p 8080:80 httpd:2.2 28 | ``` 29 | 30 | 6. List out running containers 31 | ```sh 32 | docker ps 33 | ``` 34 | 35 | 7. List out all docker container (running, stpooed, terminated, etc...) 36 | ```sh 37 | docker ps -a 38 | ``` 39 | 40 | 8. run a OS based container which interactive mode (nothing but login to container after it is up and running) 41 | 42 | ```sh 43 | docker run -i -t --name centos_server centos:latest 44 | i - interactive 45 | t - Terminal 46 | ``` 47 | 48 | 9. Stop a container 49 | ```sh 50 | docker stop 51 | ``` 52 | 53 | 10. Start a container which is in stopped or exit state 54 | 55 | ```sh 56 | docker start 57 | ``` 58 | 11. Remove a container 59 | 60 | ```sh 61 | docker rm 62 | ``` 63 | 64 | 12. login to a docker container 65 | ```sh 66 | docker exec -it /bin/bash 67 | ``` 68 | -------------------------------------------------------------------------------- /Docker/Docker_Installation_Steps.MD: -------------------------------------------------------------------------------- 1 | # Installing Docker on Amazon Linux server 2 | 3 | 1.Update packages 4 | ```sh 5 | yum update -y 6 | ``` 7 | 2.Install docker 8 | ```sh 9 | yum install docker -y 10 | ``` 11 | 12 | # Docker Installation on CentOS server 13 | ##### Referance URL : https://docs.docker.com/install/linux/docker-ce/centos/#install-using-the-repository 14 | ### PREREQUISITES 15 | 16 | Please follow below steps to install docker CE on CentoOS server instance. For RedHat only Docker EE available 17 | 18 | 1.Install required packages. 19 | 20 | ```sh 21 | sudo yum install -y yum-utils \ 22 | device-mapper-persistent-data \ 23 | lvm2 24 | 25 | ``` 26 | 27 | 2.Use the following command to set up the stable repository. 28 | 29 | ```sh 30 | sudo yum-config-manager \ 31 | --add-repo \ 32 | https://download.docker.com/linux/centos/docker-ce.repo 33 | ``` 34 | 35 | ### INSTALLING DOCKER CE 36 | 37 | 1.Install the latest version of Docker CE. 38 | ```sh 39 | sudo yum install docker-ce 40 | ``` 41 | 42 | If prompted to accept the GPG key, verify that the fingerprint matches 43 | 060A 61C5 1B55 8A7F 742B 77AA C52F EB6B 621E 9F35, and if so, accept it. 44 | 45 | 2.Start Docker. 46 | ```sh 47 | sudo systemctl start docker 48 | ``` 49 | 50 | 3.Verify that docker is installed correctly by running the hello-world image. 51 | ```sh 52 | sudo docker run hello-world 53 | ``` 54 | -------------------------------------------------------------------------------- /Docker/install_apache_dockerfile.txt: -------------------------------------------------------------------------------- 1 | FROM ubuntu:12.04 2 | 3 | MAINTAINER Valaxy Technologies valaxytech@gmail.com 4 | 5 | LABEL version="1.1.0" \ 6 | app_name="Training registration application" \ 7 | release_date="9-Sep-2018" 8 | RUN apt-get update && apt-get install -y apache2 && apt-get clean 9 | 10 | ENV APACHE_RUN_USER www-data 11 | ENV APACHE_RUN_GROUP www-data 12 | ENV APACHE_LOG_DIR /var/log/apache2 13 | 14 | EXPOSE 80 15 | 16 | COPY index.html /var/www/html 17 | CMD ["/usr/sbin/apache2", "-D", "FOREGROUND"] 18 | 19 | 20 | 21 | 22 | 23 | 24 | -------------------------------------------------------------------------------- /Jenkins/Ansible_integration.MD: -------------------------------------------------------------------------------- 1 | # Ansible integration with Jenkins 2 | 3 | Follow this on **[YouTube](https://www.youtube.com/watch?v=nE4b9mW2ym0)** 4 | 5 | ### Prerequisites: 6 | 1. Ansible server **[Get Help Here](https://www.youtube.com/watch?v=79xFyOc_eEY)** 7 | 2. Jenkins Server **[Get Help Here](https://www.youtube.com/watch?v=M32O4Yv0ANc)** 8 | 9 | ### Part-01 Integration Setps 10 | 11 | Install "publish Over SSH" 12 | - `Manage Jenkins` > `Manage Plugins` > `Available` > `Publish over SSH` 13 | 14 | Enable connection between Ansible and Jenkins 15 | - `Manage Jenkins` > `Configure System` > `Publish Over SSH` > `SSH Servers` 16 | 17 | - SSH Servers: 18 | - Hostname:`` 19 | - username: `ansadm` 20 | - password: `*******` 21 | 22 | Test the connection "Test Connection" 23 | -------------------------------------------------------------------------------- /Jenkins/Git_plugin_install.MD: -------------------------------------------------------------------------------- 1 | # Configure Git pulgin on Jenkins 2 | Git is one of the most popular tool for version contorl system. you can pull code from git repositories using jenkins if you use github plugin. 3 | 4 | #### Follow this artical in **[YouTube](https://www.youtube.com/watch?v=wgfsVmHnAiM)** 5 | 6 | #### Prerequisites 7 | 1. Jenkins server **[Get Help Here](https://www.youtube.com/watch?v=M32O4Yv0ANc) 8 | 9 | #### Install Git on Jenkins server 10 | Install git packages on jenkins server 11 | ```sh 12 | yum install git -y 13 | ``` 14 | 15 | #### Setup Git on jenkins console 16 | - Install git plugin without restart 17 | - `Manage Jenkins` > `Jenkins Plugins` > `available` > `github` 18 | 19 | - Configure git path 20 | - `Manage Jenkins` > `Global Tool Configuration` > `git` 21 | 22 | #### Next Steps 23 | 24 | - [x] [Configure Users & Groups in Jenkins](https://youtu.be/jZOqcB32dYM) 25 | - [x] [Secure your Jenkins Server](https://youtu.be/19FmJumnkDc) 26 | - [x] [Jenkins Plugin Installation](https://youtu.be/p_PqPBbjaZ4) 27 | - [x] [Jenkins Master-Slave Configuration](https://youtu.be/hwrYURP4O2k) 28 | -------------------------------------------------------------------------------- /Jenkins/Installation.MD: -------------------------------------------------------------------------------- 1 | # Install Jenkins on AWS EC2 2 | Jenkins is a self-contained Java-based program, ready to run out-of-the-box, with packages for Windows, Mac OS X and other Unix-like operating systems. As an extensible automation server, Jenkins can be used as a simple CI server or turned into the continuous delivery hub for any project. 3 | 4 | 5 | ### Prerequisites 6 | 1. EC2 RHEL 7.x Instance [Get help here](https://www.youtube.com/watch?v=KDtS6BzJo3A) 7 | - With Internet Access 8 | - Security Group with Port `8080` open for internet 9 | 1. Java v1.8.x 10 | 11 | ## Install Java 12 | We will be using open java for our demo, Get latest version from http://openjdk.java.net/install/ 13 | ```sh 14 | yum install java-1.8* 15 | #yum -y install java-1.8.0-openjdk 16 | ``` 17 | 18 | ### Confirm Java Version 19 | Lets install java and set the java home 20 | ```sh 21 | java -version 22 | find /usr/lib/jvm/java-1.8* | head -n 3 23 | #JAVA_HOME=/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.191.b12-1.el7_6.x86_64 24 | export JAVA_HOME 25 | PATH=$PATH:$JAVA_HOME 26 | # To set it permanently update your .bash_profile 27 | source ~/.bash_profile 28 | ``` 29 | _The output should be something like this,_ 30 | ``` 31 | [root@~]# java -version 32 | openjdk version "1.8.0_151" 33 | OpenJDK Runtime Environment (build 1.8.0_151-b12) 34 | OpenJDK 64-Bit Server VM (build 25.151-b12, mixed mode) 35 | ``` 36 | 37 | ## Install Jenkins 38 | You can install jenkins using the rpm or by setting up the repo. We will setup the repo so that we can update it easily in future. 39 | Get latest version of jenkins from https://pkg.jenkins.io/redhat-stable/ 40 | ```sh 41 | yum -y install wget 42 | wget -O /etc/yum.repos.d/jenkins.repo https://pkg.jenkins.io/redhat-stable/jenkins.repo 43 | rpm --import https://pkg.jenkins.io/redhat-stable/jenkins.io.key 44 | yum -y install jenkins 45 | ``` 46 | 47 | ### Start Jenkins 48 | ```sh 49 | # Start jenkins service 50 | systemctl start jenkins 51 | 52 | # Setup Jenkins to start at boot, 53 | systemctl enable jenkins 54 | ``` 55 | 56 | #### Accessing Jenkins 57 | By default jenkins runs at port `8080`, You can access jenkins at 58 | ```sh 59 | http://YOUR-SERVER-PUBLIC-IP:8080 60 | ``` 61 | #### Configure Jenkins 62 | - The default Username is `admin` 63 | - Grab the default password 64 | - Password Location:`/var/lib/jenkins/secrets/initialAdminPassword` 65 | - `Skip` Plugin Installation; _We can do it later_ 66 | - Change admin password 67 | - `Admin` > `Configure` > `Password` 68 | - Configure `java` path 69 | - `Manage Jenkins` > `Global Tool Configuration` > `JDK` 70 | - Create another admin user id 71 | 72 | ### Test Jenkins Jobs 73 | 1. Create “new item” 74 | 1. Enter an item name – `My-First-Project` 75 | - Chose `Freestyle` project 76 | 1. Under Build section 77 | Execute shell : echo "Welcome to Jenkins Demo" 78 | 1. Save your job 79 | 1. Build job 80 | 1. Check "console output" 81 | 82 | -------------------------------------------------------------------------------- /Jenkins/junit_plugin_setup.MD: -------------------------------------------------------------------------------- 1 | # Configure Junit pulgin on Jenkins 2 | Junit is one of the most popular unit testing tool for java. install plugin to start with this 3 | 4 | #### Follow this artical in **[YouTube]()** 5 | 6 | #### Prerequisites 7 | 1. Jenkins server **[Get Help Here](https://www.youtube.com/watch?v=M32O4Yv0ANc) 8 | 9 | #### Setup maven on jenkins console 10 | - Install maven plugin without restart 11 | - `Manage Jenkins` > `Jenkins Plugins` > `available` > `junit` 12 | 13 | #### Next Steps 14 | 15 | - [x] [Configure Users & Groups in Jenkins](https://youtu.be/jZOqcB32dYM) 16 | - [x] [Secure your Jenkins Server](https://youtu.be/19FmJumnkDc) 17 | - [x] [Jenkins Plugin Installation](https://youtu.be/p_PqPBbjaZ4) 18 | - [x] [Jenkins Master-Slave Configuration](https://youtu.be/hwrYURP4O2k) 19 | -------------------------------------------------------------------------------- /Jenkins/maven_install.MD: -------------------------------------------------------------------------------- 1 | # Install & configure Maven build tool on Jenkins 2 | Maven is a code build tool which used to convert your code to artifact. this is widely used plugin to build in continuous integration 3 | 4 | 5 | #### Prerequisites 6 | 1. Jenkins server **[Get Help Here](https://www.youtube.com/watch?v=M32O4Yv0ANc) 7 | 8 | #### Install Maven on Jenkins 9 | Download maven packages https://maven.apache.org/download.cgi onto Jenkins server. In this case I am using /opt/maven as my installation directory 10 | - Link : https://maven.apache.org/download.cgi 11 | ```sh 12 | # Creating maven directory under /opt 13 | mkdir /opt/maven 14 | cd /opt/maven 15 | # downloading maven version 3.6.0 16 | wget http://mirrors.fibergrid.in/apache/maven/maven-3/3.6.0/binaries/apache-maven-3.6.0-bin.zip 17 | unzip /opt/maven/apache-maven-3.6.0-bin.zip 18 | ``` 19 | 20 | Setup M2_HOME and M2 paths in .bash_profile of user and add these to path variable 21 | ```sh 22 | vi ~/.bash_profile 23 | M2_HOME=/opt/maven/apache-maven-3.6.0 24 | M2=$M2_HOME/bin 25 | PAHT=:$M2_HOME:$M2 26 | ``` 27 | #### Check point 28 | logoff and login to check maven version 29 | Check maven version 30 | ```sh 31 | mvn –version 32 | ``` 33 | So far you have completed installation of maven software to support maven plugin on jenkins console. Let's jump onto jenkins to complete remining steps. 34 | 35 | #### Setup maven on jenkins console 36 | - Install maven plugin without restart 37 | - `Manage Jenkins` > `Jenkins Plugins` > `available` > `Maven Invoker` 38 | 39 | - Configure maven path 40 | - `Manage Jenkins` > `Global Tool Configuration` > `Maven` 41 | 42 | -------------------------------------------------------------------------------- /Nexus/Nexus_Installation.MD: -------------------------------------------------------------------------------- 1 | # Nexus Installation 2 | Nexus is one a artifact repository which helps to store your build outcomes. 3 | 4 | ### Follow this article in **[Youtube](https://www.youtube.com/watch?v=83AGz9huJGo) 5 | ### Prerequisites 6 | 7 | 1. EC2 instance with java 8 | 9 | ### Implementation steps 10 | 11 | Download and setup nexus stable version 12 | ```sh 13 | cd /opt 14 | wget https://sonatype-download.global.ssl.fastly.net/nexus/3/nexus-3.0.2-02-unix.tar.gz 15 | tar -zxvf nexus-3.0.2-02-unix.tar.gz 16 | mv /opt/nexus-3.0.2-02 /opt/nexus 17 | ``` 18 | 19 | As a good security practice, it is not advised to run nexus service as root. so create new user called nexus and grant sudo access to manage nexus services 20 | ```sh 21 | sudo adduser nexus 22 | # visudo \\ nexus ALL=(ALL) NOPASSWD: ALL 23 | sudo chown -R nexus:nexus /opt/nexus 24 | ``` 25 | 26 | Open /opt/nexus/bin/nexus.rc file, uncomment run_as_user parameter and set it as following. 27 | ```sh 28 | vi /opt/nexus/bin/nexus.rc 29 | run_as_user="nexus" (file shold have only this line) 30 | ``` 31 | 32 | Add nexus as a service at boot time 33 | ```sh 34 | sudo ln -s /opt/nexus/bin/nexus /etc/init.d/nexus 35 | ``` 36 | Login as a nexus user and start service 37 | ```sh 38 | su - nexus 39 | service nexus start 40 | ``` 41 | 42 | Login nexus server from browser on port 8081 43 | 44 | http://:8081 45 | 46 | Use default credentials to login 47 | 48 | username : admin 49 | password : admin123 50 | 51 | 52 | ### Troubleshooting 53 | 54 | service is not starting? 55 | - make sure you are trying to start service with nexus user. 56 | - check java installation 57 | 58 | Unable to access nexus URL? 59 | - make sure port 8081 is opened in security group. 60 | 61 | ### Next Steps 62 | - [x] [Configure Users & Groups in Jenkins](https://youtu.be/jZOqcB32dYM) 63 | - [x] [Secure your Jenkins Server](https://youtu.be/19FmJumnkDc) 64 | - [x] [Jenkins Plugin Installation](https://youtu.be/p_PqPBbjaZ4) 65 | - [x] [Jenkins Master-Slave Configuration](https://youtu.be/hwrYURP4O2k) 66 | -------------------------------------------------------------------------------- /Nginx/nginx_installation.MD: -------------------------------------------------------------------------------- 1 | 1. update your system 2 | ```sh 3 | # yum update 4 | ``` 5 | 6 | 2. Download Nginx latest version. version we use here is : 7 | 8 | 2. download latest version of nginx from http://nginx.org/en/download.html website 9 | ```sh 10 | # cd /opt 11 | # wget http://nginx.org/download/nginx-1.15.4.tar.gz 12 | # tar -zxvf nginx-1.15.4.tar.gz 13 | # mv nginx-1.15.4 /opt/nginx 14 | ``` 15 | 16 | 3. In order to compile our source code we need to install dependences. 17 | ```sh 18 | # yum groupinstall "Development Tools" 19 | # yum install pcre pcre-devel zlib zlib-devel openssl openssl-devel 20 | ``` 21 | 22 | 4. Run /opt/nginx/configure file with below parameters 23 | ```sh 24 | # cd /opt/nginx 25 | # ./configure --sbin-path=/usr/bin/nginx --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --with-pcre --pid-path=/var/run/nginx.pid --with-http_ssl_module 26 | ``` 27 | 28 | 5. Now compile and install nginx 29 | ```sh 30 | # make 31 | # make install 32 | ``` 33 | 34 | 6. Check nginx version and start service to use. 35 | ```sh 36 | # nginx -V 37 | # nginx 38 | ``` 39 | 40 | 6. Setup nginx as a system servicecreate a file /lib/systemd/system/nginx.service and copy below URL content into that and modify according to your file path locations. 41 | ```sh 42 | 43 | Ref URL : https://www.nginx.com/resources/wiki/start/topics/examples/systemd/ 44 | 45 | # vi /lib/systemd/system/nginx.service 46 | ``` 47 | 48 | copy below contant in to nginx.service file by changing PIDFile location 49 | 50 | ```sh 51 | [Unit] 52 | Description=The NGINX HTTP and reverse proxy server 53 | After=syslog.target network.target remote-fs.target nss-lookup.target 54 | 55 | [Service] 56 | Type=forking 57 | PIDFile=/var/run/nginx.pid 58 | ExecStartPre=/usr/bin/nginx -t 59 | ExecStart=/usr/bin/nginx 60 | ExecReload=/usr/sbin/nginx -s reload 61 | ExecStop=/bin/kill -s QUIT $MAINPID 62 | PrivateTmp=true 63 | 64 | [Install] 65 | WantedBy=multi-user.target 66 | ``` 67 | 7. Start nginx and test 68 | ```sh 69 | # systemctl start nginx 70 | # systemctl enable nginx 71 | # ps aux | grep nginx 72 | ``` 73 | -------------------------------------------------------------------------------- /ProjectDemos/Project-01.MD: -------------------------------------------------------------------------------- 1 | # Simple DevOps Project -01 2 | 3 | We know how to use work with each and Git, Jenkins independently. What if you want to collaborate these two? that is where Simple DevOps project helps you. Follow below steps if you are a new guy to DevOps. You love it. 4 | 5 | ### Follow this article in **[YouTube](https://www.youtube.com/watch?v=Z9G5stlXoyg)** 6 | #### Prerequisites 7 | 1. EC2 instance with tomcat installation **[installation steps video](https://youtu.be/m21nFreFw8A) 8 | 1. Jenkins server **[Get Help here](https://www.youtube.com/watch?v=M32O4Yv0ANc) 9 | 10 | ### Part-01 : Adding steps for Integration 11 | ### Steps to create Jenkin job 12 | 1. Login to Jenkins console 13 | 1. Create *Jenkins job*, Fill the following details, 14 | - *Source Code Management:* 15 | - Repository: `https://github.com/ValaxyTech/hello-world.git` 16 | - Branches to build : `*/master` 17 | - *Build:* 18 | - Root POM:`pom.xml` 19 | - Goals and options : `clean install package` 20 | 21 | ### Part-02: Adding Deployment Steps 22 | in this port we are going to install 'deploy to container' plugin. this is need to deploy on tomcat server which we are using. 23 | 24 | - Install maven plugin without restart 25 | - `Manage Jenkins` > `Jenkins Plugins` > `available` > `deploy to container` 26 | 27 | To deploy our build artifacts on tomcat server our Jenkins server need access. For this we should setup credentials. This option is available in Jenkins home page 28 | 29 | - setup credentials 30 | - `credentials` > `jenkins` > `Global credentials` > `add credentials` 31 | - Username : `deployer` 32 | - Password : `XXXXXXX` 33 | - id : `Tomcat_user` 34 | - Description: `Tomcat user to deploy on tomcat server` 35 | 36 | Modify the same job which created in part-01 and add deployment steps. 37 | - Post Steps 38 | - Deploy war/ear to container 39 | - WAR/EAR files : `**/*.war` 40 | - Containers : `Tomcat 8.x` 41 | - Credentials: `Tomcat_user` (which created in above step) 42 | - Tomcat URL : `http://:` 43 | 44 | Save and run the job now. 45 | 46 | ### Port-03 : Continuous Integration & Continuous Deployment (CI/CD) 47 | Now job is running fine but to make this as Continuous Integration and Continuous Deployment Tod do that go back and modify job as below. 48 | - Build Triggers 49 | - Poll SCM 50 | - schedule `*/2 * * * *` 51 | 52 | Save the job and modify the code in GitHub. Then you could see your job get trigger a build without any manual intervention. 53 | -------------------------------------------------------------------------------- /ProjectDemos/Project-02.MD: -------------------------------------------------------------------------------- 1 | # Simple DevOps Project -02 2 | 3 | Follow this on **[YouTube](https://www.youtube.com/watch?v=nE4b9mW2ym0)** 4 | 5 | ### Prerequisites: 6 | 1. Ansible server **[Get Help Here](https://www.youtube.com/watch?v=79xFyOc_eEY)** 7 | 2. Jenkins Server **[Get Help Here](https://www.youtube.com/watch?v=M32O4Yv0ANc)** 8 | 3. Tocmat Server **[Get Help Here](https://www.youtube.com/watch?v=m21nFreFw8A)** 9 | 10 | ### Part-01 Integration Setps 11 | 12 | Install "publish Over SSH" 13 | - `Manage Jenkins` > `Manage Plugins` > `Available` > `Publish over SSH` 14 | 15 | Enable connection between Ansible and Jenkins 16 | 17 | - `Manage Jenkins` > `Configure System` > `Publish Over SSH` > `SSH Servers` 18 | 19 | - SSH Servers: 20 | - Hostname:`` 21 | - username: `ansadm` 22 | - password: `*******` 23 | 24 | Test the connection "Test Connection" 25 | 26 | ### Part-02 - Execute job to connect 27 | 28 | create a copywarfile.yml on Ansible under /opt/playbooks 29 | 30 | ```sh 31 | # copywarfile.yml 32 | --- 33 | - hosts: all 34 | become: true 35 | tasks: 36 | - name: copy jar/war onto tomcat servers 37 | copy: 38 | src: /op/playbooks/wabapp/target/webapp.war 39 | dest: /opt/apache-tomcat-8.5.32/webapps 40 | ``` 41 | Add tomcat server details to /etc/ansible/hosts (if you are using other hosts file update server info there) 42 | ```sh 43 | echo "" >> /etc/ansible/hosts 44 | ``` 45 | Create *Jenkins job*, Fill the following details, 46 | 47 | - *Source Code Management:* 48 | - Repository: `https://github.com/ValaxyTech/hello-world.git` 49 | - Branches to build : `*/master` 50 | - *Build:* 51 | - Root POM:`pom.xml` 52 | - Goals and options : `clean install package` 53 | 54 | - *Add post-build steps* 55 | - Send files or execute commands over SSH 56 | - SSH Server : `ansible_server` 57 | - Source fiels: `webapp/target/*.war` 58 | - Remote directory: `//opt//playbooks` 59 | - *Add post-build steps* 60 | - Send files or execute commands over ssH 61 | - SSH Server : `ansible_server` 62 | - Exec command ansible-playbook /opt/playbooks/copywarfile.yml 63 | 64 | Execute job and you should be able to seen build has been deployed on Tomcat server. 65 | 66 | 67 | -------------------------------------------------------------------------------- /ProjectDemos/Project-3.MD: -------------------------------------------------------------------------------- 1 | ## Simple DevOps Project -3 2 | 3 | 4 | 1. Launch an EC2 instance for Docker host 5 | 6 | 2. Install docker on EC2 instance and start services 7 | ```sh 8 | yum install docker 9 | service docker start 10 | ``` 11 | 12 | 3. create a new user for Docker management and add him to Docker (default) group 13 | ```sh 14 | useradd dockeradmin 15 | passwd dockeradmin 16 | usermod -aG docker dockeradmin 17 | ``` 18 | 19 | 4. Write a Docker file under /opt/docker 20 | 21 | ```sh 22 | mkdir /opt/docker 23 | 24 | ### vi Dockerfile 25 | # Pull base image 26 | From tomcat:8-jre8 27 | 28 | # Maintainer 29 | MAINTAINER "valaxytech@gmail.com" 30 | 31 | # copy war file on to container 32 | COPY ./webapp.war /usr/local/tomcat/webapps 33 | ``` 34 | 35 | 5. Login to Jenkins console and add Docker server to execute commands from Jenkins 36 | Manage Jenkins --> Configure system --> Publish over SSH --> add Docker server and credentials 37 | 38 | 6. Create Jenkins job 39 | 40 | A) Source Code Management 41 | Repository : https://github.com/ValaxyTech/hello-world.git 42 | Branches to build : */master 43 | 44 | B) Build 45 | Root POM: pom.xml 46 | Goals and options : clean install package 47 | 48 | C) send files or execute commands over SSH 49 | Name: docker_host 50 | Source files : webapp/target/*.war 51 | Remove prefix : webapp/target 52 | Remote directory : //opt//docker 53 | Exec command : docker stop valaxy_demo; docker rm -f valaxy_demo; docker image rm -f valaxy_demo; cd /opt/docker; docker build -t valaxy_demo . 54 | 55 | D) send files or execute commands over SSH 56 | Name: docker_host 57 | Exec command : docker run -d --name valaxy_demo -p 8090:8080 valaxy_demo 58 | 59 | 7. Login to Docker host and check images and containers. (no images and containers) 60 | 61 | 8. Execute Jenkins job 62 | 63 | 9. check images and containers again on Docker host. This time an image and container get creates through Jenkins job 64 | 65 | 10. Access web application from browser which is running on container 66 | :8090 67 | -------------------------------------------------------------------------------- /ProjectDemos/Project-4.MD: -------------------------------------------------------------------------------- 1 | # Simple DevOps Project - 4 2 | 3 | 4 | 5 | In this project, we will be see how to *use Git, Jenkins, Ansible, DockerHub, Docker to DEPLOY on a docker container.,* 6 | 7 | *Follow this project in *[Youtube](https://youtu.be/MJ74RcL6jv8)** 8 | 9 | ![](https://github.com/ValaxyTech/DevOpsDemos/blob/master/SimpeDevOpsProjects/images/Project-4.png) 10 | 11 | #### PreRequisites 12 | 1. Jenkins - Get help [here](https://www.youtube.com/watch?v=M32O4Yv0ANc) 13 | 1. Ansible - Get help [here](https://www.youtube.com/watch?v=79xFyOc_eEY) 14 | 1. Setup ansible client and install docker. [here](https://www.youtube.com/watch?v=nMLQgXf8tZ0) 15 | 1. Docker Hub account 16 | 17 | #### Previous DevOps projects: 18 | 19 | 1. Simple DevOps project-1 [here](https://www.youtube.com/watch?v=Z9G5stlXoyg) 20 | 1. Simple DevOps project-2 [here](https://www.youtube.com/watch?v=nE4b9mW2ym0) 21 | 1. Simple DevOps project-3 [here](https://www.youtube.com/watch?v=nMLQgXf8tZ0) 22 | 23 | In *part-01* we create Docker image on ansible server through Jenkins job and pushed it onto DockerHub. 24 | 25 | ### Part-01 : Create an docker image 26 | 27 | 1. Login to Jenkins console 28 | 1. Create *Jenkins job*, Fill the following details, 29 | - *Source Code Management:* 30 | - Repository : `https://github.com/ValaxyTech/hello-world.git` 31 | - Branches to build : `*/master` 32 | - *Build:* 33 | - Root POM:`pom.xml` 34 | - Goals and options : `clean install package` 35 | - *Post Steps* 36 | - *Send files or execute commands over SSH* 37 | - Name: `ansible_server` 38 | - Source files : `webapp/target/*.war` 39 | - Remove prefix : `webapp/target` 40 | - Remote directory : `//opt//docker` 41 | 42 | - *Send files or execute commands over SSH* 43 | - Name: `ansible_server` 44 | - Source files : `Dockerfile` 45 | - Remote directory : `//opt//docker` 46 | - Exec Command: 47 | - `cd /opt/docker` 48 | - `docker build -t valaxy_demo .` 49 | - `docker tag valaxy_demo valaxy/valaxy_demo` 50 | - `docker push valaxy/valaxy_demo` 51 | - `docker rmi valaxy_demo valaxy/valaxy_demo` 52 | 53 | 1. Login to Docker host and check images and containers. (no images and containers) 54 | 55 | 1. login to docker hub and check. shouldn't find images with for valaxy_demo 56 | 57 | 1. Execute Jenkins job 58 | 59 | 1. check images in Docker hub. Now you could able to see new images pushed to Valaxy Docker_Hub 60 | 61 | #### Troubleshooting: 62 | 1. Docker should be installed on ansible server 63 | 1. Should login to "docker hub" on ansible server 64 | 1. Docker admin user should be part of `docker` group 65 | 66 | In *Part-02* we create *create_docker_container.yml* playbook. this get intiated by jenkins job, run by ansible and exected on dokcer_host 67 | 68 | ### Part-02 : Deploy Containers 69 | 70 | 1. Write a yml file to create a container (file name : create_docker_container.yml) 71 | ```yaml 72 | --- 73 | - hosts: web-servers 74 | become: true 75 | tasks: 76 | - name: stop previous version docker 77 | shell: docker stop valaxy_demo 78 | - name: remove stopped container 79 | shell: docker rm -f valaxy_demo 80 | - name: remove docker images 81 | shell: docker image rm -f valaxy/valaxy_demo 82 | 83 | - name: create docker image 84 | shell: docker run -d --name valaxy_demo -p 8090:8080 valaxy/valaxy_demo 85 | 86 | 1. Add this script to Jenkins job. 87 | - Chose *"configure"* to modify your jenkins job. 88 | - *Under post build actions* 89 | - Send files or execute commands over SSH 90 | - Exec Command: 91 | ```sh 92 | cd /opt/playbooks 93 | ansible-playbook create_docker_container.yml 94 | ``` 95 | 96 | 1. Execute Jenkins job. 97 | 98 | 1. You could see a new container on your docker host. can able access it from browser on port 8090 99 | 100 | Troubleshooting: 101 | Makesure you have opened required ports on AWS Security group for this server. 102 | 103 | In *Part-03* we try to improvise to store docker images previous versions 104 | 105 | ### Part-03 : Deploy with Version Control Containers 106 | 107 | So for we used latest docker image to build a container, but what happens if latest version is not working? 108 | One easiest solution is, maintaining version for each build. This can be achieved by using environment variables. 109 | 110 | here we use 2 variables 111 | - `BUILD_ID` - The current build id 112 | - `JOB_NAME` - Name of the project of this build. This is the name you gave your job when you first set it up. 113 | 114 | for more info Please refer [this URL](https://wiki.jenkins.io/display/JENKINS/Building+a+software+project) 115 | 116 | Lets modify jenkins job which was created in *Part-01* as below. 117 | 118 | 1. Create Jenkins job 119 | - *Source Code Management:* 120 | - Repository : `https://github.com/ValaxyTech/hello-world.git` 121 | - Branches to build : `*/master` 122 | - *Build:* 123 | - Root POM:`pom.xml` 124 | - Goals and options : `clean install package` 125 | 126 | - *Send files or execute commands over SSH* 127 | - Name: `ansible_server` 128 | - Source files : `webapp/target/*.war` 129 | - Remove prefix : `webapp/target` 130 | - Remote directory : `//opt//docker` 131 | 132 | - *Send files or execute commands over SSH* 133 | - Name: `ansible_server` 134 | - Source files : `Dockerfile` 135 | - Remote directory : `//opt//docker` 136 | - `cd /opt/docker` 137 | - `docker build -t $JOB_NAME:v1.$BUILD_ID .` 138 | - `docker tag $JOB_NAME:v1.$BUILD_ID valaxy/$JOB_NAME:v1.$BUILD_ID` 139 | - `docker tag $JOB_NAME:v1.$BUILD_ID valaxy/$JOB_NAME:latest` 140 | - `docker push valaxy/$JOB_NAME:v1.$BUILD_ID` 141 | - `docker push valaxy/$JOB_NAME:latest` 142 | - `docker rmi $JOB_NAME:v1.$BUILD_ID valaxy/$JOB_NAME:v1.$BUILD_ID` 143 | - `valaxy/$JOB_NAME:latest` 144 | ##### References 145 | [1] - [Jenkins Docs - Building Software Projects](https://wiki.jenkins.io/display/JENKINS/Building+a+software+project) 146 | -------------------------------------------------------------------------------- /ProjectDemos/images/Project-4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ValaxyTech/Simple-DevOps-Project/a82015c8593c8d16fd4240fbf9941efdfacea28c/ProjectDemos/images/Project-4.png -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # DevOpsDemos -------------------------------------------------------------------------------- /SonarQube/SonarQube_Installation.MD: -------------------------------------------------------------------------------- 1 | # SonarQube Installation 2 | 3 | SonarQube provides the capability to not only show health of an application but also to highlight issues newly introduced. With a Quality Gate in place, you can fix the leak and therefore improve code quality systematically. 4 | 5 | 6 | ### Prerequisites 7 | 1. EC2 instance with Java installed 8 | 1. MySQL Database Server or MyQL RDS instance. 9 | 10 | ### Installation 11 | 12 | Install MySQL client version 13 | 14 | ```sh 15 | # yum install mysql 16 | ``` 17 | Download stable SonarQube version from below website. 18 | - Website: https://www.sonarqube.org/downloads/ 19 | - Note: This Article written for SonarQube version 6.7.6 20 | 21 | Download & unzip SonarQube 6.7.6 22 | ```sh 23 | # cd /opt 24 | # wget https://sonarsource.bintray.com/Distribution/sonarqube/sonarqube-6.7.6.zip 25 | # unzip sonarqube-6.7.6.zip 26 | # mv /opt/sonarqube-6.7.6 /opt/sonar 27 | ``` 28 | Create new user give ownership to /opt/sonar directory 29 | ```sh 30 | # useradd sonar 31 | # password sonar 32 | # chown -R sonar:sonar /opt/sonar 33 | ``` 34 | Allow RDS instance security group to access SonarQube server 35 | 36 | Connect to RDS instance with database credentials 37 | ```sh 38 | mysql -h :3306 -u -p 39 | ``` 40 | Create a new sonar database 41 | ```sh 42 | CREATE DATABASE sonar CHARACTER SET utf8 COLLATE utf8_general_ci; 43 | ``` 44 | 45 | Create a local and a remote user 46 | ```sh 47 | CREATE USER sonar@localhost IDENTIFIED BY 'sonar'; 48 | CREATE USER sonar@'%' IDENTIFIED BY 'sonar'; 49 | ``` 50 | 51 | Grant database access permissions to users 52 | ```sh 53 | GRANT ALL ON sonar.* TO sonar@localhost; 54 | GRANT ALL ON sonar.* TO sonar@'%'; 55 | ``` 56 | 57 | check users and databases 58 | ```sh 59 | use mysql 60 | show databases; 61 | SELECT User FROM mysql.user; 62 | FLUSH PRIVILEGES; 63 | QUIT 64 | ``` 65 | So for you have configured required database information on RDS. Let’s Jump back to your EC2 instance and enable SonarQube properties file to connect his Database. 66 | 67 | ### ON EC2 Instance 68 | Edit sonar properties file to uncomment and provide required information for below properties. 69 | 70 | - File Name: /opt/sonar/conf/sonar.properties 71 | - sonar.jdbc.username=`sonar` 72 | - sonar.jdbc.password=`sonar` 73 | - sonar.jdbc.url=jdbc:mysql://`:3306`/sonar?useUnicode=true&characterEncoding=utf8&rewriteBatchedStatements=true&useConfigs=maxPerformance&useSSL=false 74 | - sonar.web.host=`0.0.0.0` 75 | - sonar.web.context=`/sonar` 76 | 77 | Switch to sonar user and start SonarQube service 78 | ```sh 79 | # su - sonar 80 | # cd /opt/sonar/bin/linux-x86-64/ 81 | # ./sonar.sh start 82 | ``` 83 | 84 | ##### Run SonarQube as a default service 85 | 86 | Implement SonarQube server as a service 87 | ```sh 88 | Copy sonar.sh to etc/init.d/sonar and modify it according to your platform. 89 | # sudo cp /opt/sonar/bin/linux-x86-64/sonar.sh /etc/init.d/sonar 90 | # sudo vi /etc/init.d/sonar 91 | ``` 92 | 93 | Add below values to your /etc/init.d/sonar file 94 | ```sh 95 | Insert/modify below values 96 | SONAR_HOME=/opt/sonar 97 | PLATFORM=linux-x86-64 98 | 99 | WRAPPER_CMD="${SONAR_HOME}/bin/${PLATFORM}/wrapper" 100 | WRAPPER_CONF="${SONAR_HOME}/conf/wrapper.conf" 101 | PIDDIR="/var/run" 102 | ``` 103 | 104 | Start SonarQube server 105 | ```sh 106 | # service sonar start 107 | ``` 108 | SonarQube application uses port 9000. access SonarQube from browser 109 | ```sh 110 | http://:9000/sonar 111 | ``` 112 | ### Troubleshooting 113 | 114 | 1. Check whether you enabled port 9000 in EC2 instance security group 115 | 2. Check whether you enabled EC2 instance IP range in RDS security group 116 | 117 | ### Next Step 118 | - [x] [Integrate SonarQube with Jenkins](https://www.youtube.com/watch?v=k-3krTRuAFA) 119 | -------------------------------------------------------------------------------- /SonarQube/Sonar_Integration_with_Jenkins.MD: -------------------------------------------------------------------------------- 1 | 2 | ## SonarQube Integration with Jenkins 3 | 4 | Integration SonarQube server with Jenkins is necessary to store your reports. Follow below steps to enable that. 5 | 6 | 7 | ### Prerequisites 8 | 1. SonarQube Server 9 | 1. Jenkins Server 10 | 11 | ### Implementation 12 | 13 | Login to Jenkins server and install sonarqube scanner. 14 | 15 | - SonarQube scanner URL : https://docs.sonarqube.org/display/SCAN/Analyzing+with+SonarQube+Scanner 16 | - Package : https://binaries.sonarsource.com/Distribution/sonar-scanner-cli/sonar-scanner-cli-3.3.0.1492-linux.zip 17 | - 18 | ```sh 19 | # wget https://binaries.sonarsource.com/Distribution/sonar-scanner-cli/sonar-scanner-cli-3.3.0.1492-linux.zip 20 | # unzip sonar-scanner-cli-3.3.0.1492-linux.zip 21 | # mv sonar-scanner-cli-3.3.0.1492-linux /opt/sonar_scanner 22 | ``` 23 | 24 | Set SonarQube server details in sonar-scanner property file 25 | 26 | - Sonar properties file: /opt/sonar_scanner/conf/sonar-scanner.properties 27 | - sonar.host.url=http://``:9000 28 | 29 | Login to Jenkins GUI console and install " SonarQube scanner" plugin 30 | 31 | - `Manage Jenkins` > `Manage Plugins` > `Avalable` > `SonarQube scanner` 32 | 33 | Configure SonarQube scanner home path 34 | 35 | - `Manage Jenkins` > `Global Tool Configuration` > `SonarQube Scanner` 36 | - Name : `sonar_scanner` 37 | - SONAR_RUNNER_HOME : `/opt/sonar_scanner` 38 | 39 | Configure SonarQube server name and authentication token 40 | - `Manage Jenkins` > `Configure Systems` > `SonarQube Servers` 41 | - Name : `SonarQube` 42 | - ServerURL : `http://:9000/sonar` 43 | - Server `authentication token` 44 | To Get Authentication code follow below steps. 45 | Login to SonarQube server as a admin `My Account` > `Security` > `Generate Token` 46 | 47 | Create a job to test SonarQube. Provide below sonar properties details in the job under build 48 | - Build: 49 | - `Execute SonarQube Scanner` > `Analysis properties` (it is mandatary). 50 | - sonar.projectKey=`DevOpsProject` 51 | - sonar.projectName=`DevOpsProject` 52 | - sonar.projectVersion=`1.0` 53 | - sonar.sources=`/var/lib/jenkins/workspace/$JOB_NAME//src` 54 | 55 | Execute job to get analysis report. 56 | 57 | 58 | -------------------------------------------------------------------------------- /Tomcat/tomcat_installation.MD: -------------------------------------------------------------------------------- 1 | # Tomcat installation on EC2 instance 2 | 3 | ### Prerequisites 4 | 1. EC2 instance with Java v1.8.x 5 | 6 | ### Install Apache Tomcat 7 | Download tomcat packages from https://tomcat.apache.org/download-80.cgi onto /opt on EC2 instance 8 | ```sh 9 | # create tomcat directory 10 | cd /opt 11 | wget http://mirrors.fibergrid.in/apache/tomcat/tomcat-8/v8.5.35/bin/apache-tomcat-8.5.35.tar.gz 12 | tar -xvzf /opt/apache-tomcat-8.5.35.tar.gz 13 | ``` 14 | give executing permissions to startup.sh and shutdown.sh which are under bin. 15 | ```sh 16 | chmod +x /opt/apache-tomcat-8.5.35/bin/startup.sh shutdown.sh 17 | ``` 18 | 19 | create link files for tomcat startup.sh and shutdown.sh 20 | ```sh 21 | ln -s /opt/apache-tomcat-8.5.35/bin/startup.sh /usr/local/bin/tomcatup 22 | ln -s /opt/apache-tomcat-8.5.35/bin/shutdown.sh /usr/local/bin/tomcatdown 23 | tomcatup 24 | ``` 25 | #### check point : 26 | access tomcat application from browser on prot 8080 27 | http://:8080 28 | 29 | Using unique ports for each application is a best practice in an environment. But tomcat and Jenkins runs on ports number 8080. Hence lets change tomcat port number to 8090. Change port number in conf/server.xml file under tomcat home 30 | ```sh 31 | cd /opt/apache-tomcat-8.5.35/conf 32 | # update port number in the "connecter port" field in server.xml 33 | # restart tomcat after configuration update 34 | tomcatdown 35 | tomcatup 36 | ``` 37 | #### check point : 38 | access tomcat application from browser on prot 8090 39 | http://:8090 40 | 41 | now application is accessible on port 8090. but tomcat application doesnt allow to login from browser. changing a default parameter in context.xml does address this issue 42 | ```sh 43 | #search for context.xml 44 | find / -name context.xml 45 | ``` 46 | above command gives 3 context.xml files. comment () `Value ClassName` field on files which are under webapp directory. 47 | After that restart tomcat services to effect these changes 48 | ```sh 49 | tomcatdown 50 | tomcatup 51 | ``` 52 | Update users information in the tomcat-users.xml file 53 | goto tomcat home directory and Add below users to conf/tomcat-user.xml file 54 | ```sh 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | ``` 63 | Restart serivce and try to login to tomcat application from the browser. This time it should be Successful 64 | 65 | --------------------------------------------------------------------------------