Prerequisites
- AWS account with appropriate permissions
- Basic understanding of AWS EC2 and security groups
- SSH client for connecting to the instance
EC2 Instance Setup
Launch EC2 Instance
Create a new EC2 instance with the following specifications:Instance Configuration:
- AMI: Ubuntu Server 22.04 LTS or Ubuntu Server 20.04 LTS
- Instance Type: t2.medium or larger (minimum 2 GB RAM recommended)
- Storage: 20 GB or more
- Go to AWS EC2 Console
- Click “Launch Instance”
- Select Ubuntu Server as the AMI
- Choose instance type (t2.medium recommended for Jenkins)
- Configure instance details (use default VPC settings)
- Add storage (minimum 20 GB)
Configure Security Group
Set up security group rules to allow necessary traffic:Inbound Rules:
| Type | Protocol | Port Range | Source | Description |
|---|---|---|---|---|
| SSH | TCP | 22 | Your IP | SSH access |
| Custom TCP | TCP | 8080 | 0.0.0.0/0 | Jenkins Web UI |
| HTTP | TCP | 80 | 0.0.0.0/0 | Deployed application |
Create or Select Key Pair
Create a new key pair or select an existing one:
- Create a new key pair if you don’t have one
-
Download the
.pemfile and store it securely -
Set appropriate permissions:
Software Installation
After connecting to your EC2 instance, install the required software.Install Jenkins
Add Jenkins repository and install:Start and enable Jenkins:Verify Jenkins is running:
Configure Docker Permissions for Jenkins
Add Jenkins user to the Docker group to allow Jenkins to run Docker commands:
This is a critical step. Without these permissions, your Jenkins pipeline will fail when trying to build or run Docker containers.
Jenkins Initial Configuration
Unlock Jenkins
Retrieve the initial admin password:Copy the password and paste it into the Jenkins unlock screen.
Install Suggested Plugins
When prompted, select “Install suggested plugins” and wait for the installation to complete.Additionally, install these required plugins:
- Docker Pipeline
- GitHub Integration Plugin
- Pipeline Plugin (should be included in suggested plugins)
Create Admin User
Set up your admin user account:
- Username
- Password
- Full name
- Email address
Verify Installation
Confirm all services are running correctly:Accessing Your Application
Once your pipeline deploys the application, access it at:Replace
<ec2-public-ip> with your actual EC2 instance public IP address throughout this guide.Security Best Practices
Use Elastic IP
Assign an Elastic IP to your instance to maintain a consistent public IP address.
Regular Updates
Keep your system, Jenkins, and Docker updated with security patches.
Restrict SSH Access
Limit SSH access to specific IP addresses in your security group.
Enable HTTPS
Configure SSL/TLS for Jenkins using a reverse proxy like Nginx.
Next Steps
With your EC2 instance configured:- Create a new Jenkins pipeline project
- Connect your GitHub repository
- Configure GitHub webhooks
- Run your first pipeline build