Jenkins Tutorials - 2
Preethi Dovala
Vice President at JPMorgan Chase & Co. | Certified Kubernetes Application Developer(CKAD) | HashiCorp Certified Terraform Associate |Freelance Devops Instructor| AWS Certified Solutions Architect
TOPIC: Procedure to Change Jenkins Port to 8081
1. Connect to Your EC2 Instance:
???- Use SSH to connect to your EC2 instance.
???ssh -i <your-key-pair.pem> ec2-user@<your-ec2-public-ip>
2. Open the Jenkins Service Configuration File:
???- The configuration file for Jenkins is located at /lib/systemd/system/jenkins.service.
?sudo systemctl stop jenkins
???sudo systemctl status jenkins
???sudo vim /lib/systemd/system/jenkins.service
3. Find the Port Configuration:
???- Look for the line that starts with Environment="JENKINS_PORT=8080". If it doesn't exist, you can add it.
4. Change the Port Number:
???- Modify or add the line to use port 8081 instead of 8080:
plaintext
???Environment="JENKINS_PORT=8081"
5. Save and Exit the Editor:
???- Save the changes and exit the text editor. If you're using nano, you can do this by pressing Ctrl+X, then Y, and Enter.
6. Reload the Systemd Configuration:
???- After making changes to the service file, reload the systemd configuration to apply the changes:
???sudo systemctl daemon-reload
7. Start Jenkins:
???- start the Jenkins service to apply the changes:
???sudo systemctl start jenkins
8. Update the Security Group:
???- Go to the AWS Management Console.
???- Navigate to EC2 Dashboard > Instances.
???- Select your instance and note the security group.
???- Navigate to Security Groups under Network & Security.
???- Select your security group and edit inbound rules.
???- Add a custom TCP rule for port 8081:
?????- Type: Custom TCP
?????- Port Range: 8081
?????- Source: 0.0.0.0/0 (or restrict to your IP range)
9. Verify the Port Change:
???- Open a web browser and navigate to:
???????https://<your-ec2-public-ip>:8081
?????- Ensure that Jenkins is now accessible on port 8081.
### Summary
1. Connect to your EC2 instance.
2. Open and edit /lib/systemd/system/jenkins.service.
3. Add or modify Environment="JENKINS_PORT=8081".
4. Reload the systemd configuration with sudo systemctl daemon-reload.
5. Restart Jenkins with sudo systemctl restart jenkins.
6. Update your security group to allow inbound traffic on port 8081.
7. Verify Jenkins is accessible on port 8081.
By following these steps, you will successfully change the default port of Jenkins to 8081.