⚙️
DevOps Mastery on AWS
  • 🤓Continuous Integration & Continuous Deployment on AWS Cloud
  • 🤖Jenkins
    • 🛠️Build Jenkins First Job
    • 🦸Launch 2nd EC2 instance
  • 🐳Docker
    • 📁DOCKERFILE
  • 🛺Ansible
    • 📖Ansible Playbook
  • 🏃‍♂️Continuos Integration with GitHub and Jenkins
  • 👷Project Structure & summary.
  • Basics
Powered by GitBook
On this page
  1. Jenkins

Launch 2nd EC2 instance

In this section we will launch another EC2 instance and copy the build file in it to another EC2 instance which was created by Jenkins.

PreviousBuild Jenkins First JobNextDocker

Last updated 3 years ago

Spin up an EC2 instance.

  1. Launch a Amazon Linux Instance (follow the same steps used to launch the first instance)

  1. Connect using SSH or Instance connect.

Now we need to authenticate a user to talk to another server so we can copy files and host it on Tomcat Server. We have ec2-user and root as users in our machine. We should never provide our root users credentials so we will use ec2-user here.

  1. Connect to your Tomcat server using Putty/Instance connect.

  2. type the following command to set passwd for ec2-user which we wil use in next step.

sudo su - //to change user to root
passwd ec2-user //to set password for ec2-user

Amazon is very conscious about security so it will so we need to edit a file named as

To enable SSH password authentication, you must SSH in as root to edit this file:

/etc/ssh/sshd_config

Then, change the line

PasswordAuthentication no

to

PasswordAuthentication yes

After making that change, restart the SSH service by running the following command as root:

sudo service sshd reload 

Follow the steps:

  1. In Jenkins Dashboard, goto Manage Jenkins>> Manage Plugins >> and search "Publish over SSH" plugin. This plugin will help us share files among different servers using SSH.

  2. Now GO to Manage Jenkins >> Configure system >> scroll down till you see " Publish over SSH " plugin section. Here we need to enter Tomcat server's details >> click on SSH servers >>

    1. Name = Tomcat Server

    2. Hostname = <public ip-adress>

    3. username = ec2-user

    4. Remote directry = .

  3. In advance section

    1. Enter the password

    2. Click on Test configuration. You will get a Success message.

  4. Now click on apply and save.

Perfect! Now we are all set and we can ping jenkins from Tomcat server. Lets create another job.

Follow the instructions:

Go to Dashboard

  1. Click on create New item >> Enter Name >> scroll down >> copy from (name of your first job to copy same settings)

  2. Scroll to the bottom and in "Add post-build action" >> Send build artifacts over SSH >>

Fill in the details :

  • source files = path to build file (webapp/target/webapp.war)

  • remove prefix = webapp/target (to not create these folders)

  • remote directory = .

APPLY and SAVE

It says success let us check in our Tomcat server

In Tomcat server run ls command

MAGIC!!!! Jenkins has successfully build/test provided build file and transferred it to Tomcat server. Isn't AUTOMATION amazing!

ALRIGHT! Let's run Build now and see the results :

In the Next Section we will learn about Docker and container

🤖
🦸
🐳
not allow us to directly allow SSH