Jenkins-master-slave

Launch EC2 instance

To launch two EC2 ubuntu22 instance - one is master, another one is slave.

image

Install java in both master and slave

sudo apt-get update -y
sudo apt-get upgrade -y
sudo apt-get install openjdk-11-jre
java -version

Install Jenkins on master node

curl -fsSL https://pkg.jenkins.io/debian/jenkins.io-2023.key | sudo tee \
  /usr/share/keyrings/jenkins-keyring.asc > /dev/null
echo deb [signed-by=/usr/share/keyrings/jenkins-keyring.asc] \
  https://pkg.jenkins.io/debian binary/ | sudo tee \
  /etc/apt/sources.list.d/jenkins.list > /dev/null
sudo apt-get update -y
sudo apt-get install jenkins -y
sudo systemctl status jenkins.service

Access Jenkins console

http://:8080 [You can get the ec2-instance-public-ip-address from your AWS EC2 console page]

Note: If you are not interested in allowing All Traffic to your EC2 instance

  1. Delete the inbound traffic rule for your instance
  2. Edit the inbound traffic rule to only allow custom TCP port 8080

After you login to Jenkins, - Run the command to copy the Jenkins Admin Password - sudo cat /var/lib/jenkins/secrets/initialAdminPassword - Enter the Administrator password

215959008-3ebca431-1f14-4d81-9f12-6bb232bfbee3

Click on Install suggested plugin

215959294-047eadef-7e64-4795-bd3b-b1efb0375988

Wait for the Jenkins to Install suggested plugins

215959398-344b5721-28ec-47a5-8908-b698e435608d

Create First Admin User or Skip the step [If you want to use this Jenkins instance for future use-cases as well, better to create admin user]

215959757-403246c8-e739-4103-9265-6bdab418013e

Add a new slave node to Jenkins master node

Jenkins - Manage Jenkins - Nodes - New node

image

Jenkins Installation is Successful. You can now starting using the Jenkins

215961440-3f13f82b-61a2-4117-88bc-0da265a67fa7

image

SSH to Jenkins slave node and create a new directory

sudo mkdir /opt/jenkins
sudo chmod 755 /opt/jenkins -R

image

Create SSH Keygen in slave node

SSH to slave machine and perform below commands

ssh-keygen

copy a id_rsa (privatekey) for adding username with key in Jenkins credentials

copy a id_rsa.pub (publickey) and paste in below location of same slave node

sudo nano .ssh/authorized_keys
copy/paste the id_rsa.pub key here
save and exit

image

Jenkins console

image

image

Enter username - ubuntu Enter privatekey directly

image

image

Then save it.