To launch two EC2 ubuntu22 instance - one is master, another one is slave.
sudo apt-get update -y
sudo apt-get upgrade -y
sudo apt-get install openjdk-11-jre
java -version
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
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
- Delete the inbound traffic rule for your instance
- 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
Wait for the Jenkins to Install suggested plugins
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]
Jenkins - Manage Jenkins - Nodes - New node
Jenkins Installation is Successful. You can now starting using the Jenkins
SSH to Jenkins slave node and create a new directory
sudo mkdir /opt/jenkins
sudo chmod 755 /opt/jenkins -R
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
Enter username - ubuntu Enter privatekey directly
Then save it.