Table of contents
- Step 1: Sign in to AWS Console
- Step 2: Launch EC2 Instance
- Step 3: Connect to EC2 Instance
- Step 4: Install Jenkins on the New EC2 Instance
- Step 5: Configure Jenkins on the New Instance
- Step 6: Connect New Instance to Jenkins Master
- Step 7: Verify Connection
- Step 1: Generate SSH Key Pair on Jenkins Master
- Step 2: Prepare the SSH Key for Agent
- Step 3: Configure Jenkins Master
- Step 4: Configure Jenkins Agent Node
- Step 5: Verify Connection
- Step 1: Access Jenkins Dashboard
- Step 2: Navigate to Nodes Section
- Step 3: Check Node Status
- Step 4: View Node Details
- Step 5: Verify Connectivity
- Step 6: Troubleshooting
Step 1: Sign in to AWS Console
Navigate to the AWS Management Console and sign in to your account.
Step 2: Launch EC2 Instance
Click on the EC2 service.
Select "Launch Instance."
Choose an Amazon Machine Image (AMI) based on your requirements.
Select an Instance Type.
Configure Instance Details (network settings, subnet, etc.).
Add storage as needed.
Configure Security Group to allow inbound traffic for Jenkins (port 8080 by default).
Review and Launch the instance.
Step 3: Connect to EC2 Instance
Once the instance is running, note down its Public IP address.
Access the instance via SSH using a terminal or SSH client.
kotlinCopy codessh -i your_key.pem ec2-user@<your-instance-public-ip>
Step 4: Install Jenkins on the New EC2 Instance
Update system packages:
sqlCopy codesudo yum update -y
Install Jenkins:
arduinoCopy codesudo wget -O /etc/yum.repos.d/jenkins.repo http://pkg.jenkins-ci.org/redhat/jenkins.repo sudo rpm --import https://pkg.jenkins.io/redhat/jenkins.io.key sudo yum install jenkins -y
Start Jenkins service:
bashCopy codesudo systemctl start jenkins sudo systemctl enable jenkins
Step 5: Configure Jenkins on the New Instance
Open a web browser and enter the New EC2 Instance's Public IP followed by port 8080 (default Jenkins port).
vbnetCopy codehttp://<your-instance-public-ip>:8080
Follow the setup process to unlock Jenkins using the initial admin password (located at
/var/lib/jenkins/secrets/initialAdminPassword
).Customize Jenkins by installing plugins and setting up admin credentials.
Step 6: Connect New Instance to Jenkins Master
Log in to the Jenkins Master.
Go to
Manage Jenkins
>Manage Nodes and Clouds
>New Node
.Enter a Node name, select "Permanent Agent," and click "OK."
Configure the New EC2 Instance settings:
Set the Remote Root Directory and Labels.
Choose Launch Method as "Launch agent by connecting it to the master."
Specify the New EC2 Instance's details (IP, credentials, etc.).
Save the configuration.
Step 7: Verify Connection
Go back to the Jenkins dashboard.
Check if the New Node (EC2 Instance) appears under
Manage Nodes and Clouds
.Run a test job or pipeline on the New Node to ensure the connection is successful.
Step 1: Generate SSH Key Pair on Jenkins Master
Access Jenkins Master: Log in to the Jenkins Master server where Jenkins is installed.
Generate SSH Key Pair: Open a terminal or command prompt.
mathematicaCopy codessh-keygen -t rsa -b 4096 -C "jenkins_agent"
Follow the prompts to create the SSH key pair. Keep the default file location or specify a location as needed.
Step 2: Prepare the SSH Key for Agent
Copy the Public Key: Retrieve the public key generated in the previous step.
bashCopy codecat ~/.ssh/id_rsa.pub
Copy the entire content of the public key.
Authorize SSH Access on Agent: Connect to the new EC2 instance (Agent) using SSH.
kotlinCopy codessh ec2-user@<your-agent-public-ip>
Create an
.ssh
directory if not present.bashCopy codemkdir ~/.ssh chmod 700 ~/.ssh
Open the
authorized_keys
file using a text editor.javascriptCopy codenano ~/.ssh/authorized_keys
Paste the copied public key into this file and save it.
Step 3: Configure Jenkins Master
Add SSH Credentials to Jenkins: Open Jenkins Dashboard. Go to
Credentials
>System
>Global credentials
>Add Credentials
. SelectSSH Username with private key
. Fill in the required fields:Username: (e.g.,
jenkins_agent
)Private Key: Choose
Enter directly
and paste the contents of the private key (id_rsa
).
Step 4: Configure Jenkins Agent Node
Create a Jenkins Node for the Agent: Go to Jenkins Dashboard. Navigate to
Manage Jenkins
>Manage Nodes and Clouds
>New Node
. Enter Node Name, select "Permanent Agent," and click "OK."Configure Node for SSH Connection: Fill in the Node details:
Remote Root Directory
Labels
Launch Method: Select
Launch agent via execution of command on the master
.Launch command:
vbnetCopy codessh -i /path/to/private/key jenkins_agent@<your-agent-public-ip> java -jar /path/to/slave.jar
Replace
/path/to/private/key
with the path to the private key on the Jenkins Master.
Save Configuration.
Step 5: Verify Connection
Start the Jenkins Agent: Go back to Jenkins Dashboard. Check the newly created Node. Click on it and select
Launch Agent
.Monitor Jenkins Logs: Check Jenkins logs for the Agent connection status.
- You should see the Agent connecting and becoming online in the Jenkins dashboard.
Run a Test Job: Create a simple Jenkins job and assign it to the newly connected Node. Execute the job and verify that it runs on the Agent successfully.
๐ Verifying Node Status in Jenkins
Step 1: Access Jenkins Dashboard
- Log in to Jenkins: Open a web browser and enter the URL for your Jenkins instance. Log in using your credentials.
Step 2: Navigate to Nodes Section
Go to Nodes Page: On the Jenkins Dashboard, locate and click on
Manage Jenkins
.Access Nodes and Clouds: From the dropdown, select
Manage Nodes and Clouds
.
Step 3: Check Node Status
Find the Agent Node: Look for the Node representing your connected EC2 instance (Agent) in the list of Nodes. The name of the Node you created for the Agent should be visible.
Node Status:
Online Status: If the Agent successfully connected, it should display an "Online" status indicator.
Offline or Disconnected: If the status is "Offline" or "Disconnected," there might be connectivity issues or misconfiguration.
Step 4: View Node Details
Inspect Node Configuration: Click on the Node representing your Agent to view its details.
Check the labels, launch method, and other configuration settings.
Verify the Remote Root Directory and any other parameters set during configuration.
Check Node Log: Look for any logs or information related to the Node's connectivity status.
- It might provide insights into any errors or issues encountered during the connection attempt.
Step 5: Verify Connectivity
Test Job Execution: Create or select a Jenkins job and assign it explicitly to the connected Node.
- Execute the job and observe if it runs on the connected EC2 instance.
Monitor Job Execution: Check the Console Output or Build History of the job to confirm that it's running on the intended Node.
Step 6: Troubleshooting
Addressing Offline Nodes: If the Node appears offline or disconnected:
Double-check the SSH key configuration on both Jenkins Master and the Agent.
Ensure the correct IP address, credentials, and launch command in Jenkins Node configuration.
Review firewall settings and security groups on AWS EC2 for proper port access.
Inspect Logs: Examine Jenkins logs for any error messages related to the Agent connection.
- Logs might provide clues about connectivity issues or misconfigurations.