Launch EC2 Instances:
- Start by launching two EC2 instances on AWS. One will serve as the master node, and the other as the agent node.
Install Jenkins and Java on Master:
- SSH into the master instance and install Jenkins and Java. You can follow the official Jenkins documentation for installation instructions.
Install Java on Agent:
- Similarly, SSH into the agent instance and install Java. Ensure that the same version of Java is installed on both the master and agent nodes.
Generate SSH Key Pair:
- On the master node, generate an SSH key pair using the
ssh-keygen
command. This will create a public and private key pair.
- On the master node, generate an SSH key pair using the
Authorize Agent:
- Copy the public key generated on the master node (
~/.ssh/id_rsa.pub
) and paste it into theauthorized_keys
file on the agent node. This allows the master node to authenticate with the agent node via SSH.
- Copy the public key generated on the master node (
Open Port 8080:
- In the security group settings for both EC2 instances, open port 8080 to allow inbound traffic for Jenkins.
Configure Jenkins Master:
- Access the Jenkins web interface on the master node by navigating to
http://<master-instance-public-ip>:8080
. Follow the on-screen instructions to complete the setup process.
- Access the Jenkins web interface on the master node by navigating to
Add Agent in Jenkins:
Configure Agent:
- On the agent configuration page, enter the connection details, such as the agent's hostname and credentials. Select "Launch agent via execution of command on the master" and specify the command to launch the agent. Ensure that the SSH private key of the master node is provided.
Save and Connect Agent:
- Save the agent configuration and Jenkins will attempt to connect to the agent using SSH. If successful, the agent node will be listed as online in the Jenkins dashboard.
Deploy Nginx on Agent:
- Finally, you can deploy Nginx on the agent node using a Jenkins pipeline job. Write a Jenkinsfile using Groovy syntax to define the steps of the deployment process. This can include tasks such as downloading Nginx, configuring it, and starting the service.
By following these steps, you should have successfully connected a Jenkins agent via SSH and deployed Nginx on the agent node using a pipeline job.