The Jenkins master setup on AWS Cloud instance - Ubuntu 18.04 detailed execution steps that performed are collected and posted in this post.
Jenkins install on Ubuntu instance of AWS |
Login to your AWS console, go to EC2 Dashboard and perform the following steps
- Create a Security Group
- Key pair for instance
- Create Ubuntu AMI instance
- Elastic IPs Configure and associate
- Install Java, Nginx, and Jenkins
- Configure Nginx proxy
1. Create a security group
Security Group which will allow the protocol: SSH, TCP ICMP, HTTP, HTTPSUsing security group we can specify the network allow to access. Go to the EC2 dashboard. "Create a security group" button. The Security Group name it as 'my_sg01'. Outbound tab keeps as it is, goto the inbound tab and define for incoming traffic.
Secure Shell ->22-> My IP
HTTP web traffic ->80 -> anywhere
HTTPS web secure traffic -> 443 -> anywhere
Tag it "my_sg01", which is a best pratice to tag our configuration for the security group.
2. Keypair for the Ubuntu instance
A cryptographic system for encrypt and decrypt. which will be used to not to enter password while connecting to the instance. AWS only have a way to connect with keypair. Same keypair can be used for multiple instances. when you download a keypair .pem file which is private potion of the ec2 instances.
In Windows, if you wish to use PuTTY then we need to generate the ppk file from the download.em file. which can be used to SSH authentication for the PuTTY. If you are connect from git bash you can change the pem file permission 600.
example:
chmod 600 jenkins-master.pem
3. Create Ubuntu instance for Jenkins Master
In the EC2 dashboard choose the "Instances", click on the 'Launch Instance' button, and search for 'Ubuntu 18'Click on the select button, here we choose free tier eligible for Ubuntu instance that is available so proceed with 'continue' button. Select the 't2.micro' from the list of instances. Select the Security Group that we created earlier use it and go with the default disk space,
Configure instance details and review it and launch it. At the time of launch key pair details choose 'from the existing key pair, which we configured earlier.
4. Elastic IP config and associate
Most restarting instances will have different Public DNS the solution is you can use an Elastic IP address. In the EC2 dashboard in the left pane, you could find the link 'Elastic IPs' click on the 'allocate new address' button. and then click on the 'allocate' button. After 'IP' configure, go to the 'actions' -> Associate address'. Choose the 'jenkins-master' instance.AWS resources required for Jenkins Master setup |
Now go to the instance check the public DNS name and connect with the ppk, user as ubuntu using PuTTY.
5. Install Java, NGINX, Jenkins
All the installations we will do with root user, let's switch thensudo -i
Let's install Jenkins first, get the GPG keys of the Jenkins repository :
wget -q -O - https://pkg.jenkins.io/debian/jenkins.io.key | sudo apt-key add - echo deb http://pkg.jenkins.io/debian-stable binary/ > /etc/apt/sources.list.d/jenkins.list apt update apt upgradeafter all upgrade changes applied, we can install the prerequisite software JDK 8 for Jenkins Master and Jenkins run behind the reverse proxy with NGINX.
First, we will install the Open-Jdk8
apt install -y openjdk-8-jdk
Install NGINX
apt install -y nginx
Last but not least, Install Jenkins
apt install -y jenkins
To confirm that nginx web server is up and running with systemctl command:
systemctl status nginx |grep Active
Similarly check for the Jenkins
systemctl status jenkins |grep Active
Note that Jenkins process Active but exited, we can ignore for now and proceed how to make this accessible with the webserver.
Configure NGINX webserver
The reason for using NGINX web server in Jenkins master installation, act as reverse proxy:
USER-> NGINX reverse proxy ->Jenkins and vice versa also works
Why do we need NGINX in Jenkins Master setup?
- Application server security
- Reverse proxy generates logs we get much more information.
- Simple logging
- Simple SSL termination for Jenkins is made from NGINX
How NGINX works?
Use the public DNS name in the browser will load the NGINX web page.Nginx reverse proxy for Jenkins Master |
6. Configure Jenkins on NGINX proxy
Make sure you are on root usersudo -i
First, disable the links of Nginx server's documents path, it doesn't remove anything!
unlink /etc/nginx/sites-enabled/default
Now let's configure for Jenkins server on NGINX server.
vi /etc/nginx/config.d/jenkins.conf
upstream jenkins { server 127.0.0.1:8080; } server { listen 80 default_server; listen [::]:80 default_server; location / { proxy_pass http://jenkins; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; } }
root@ip-172-31-12-187:~# nginx -t nginx: the configuration file /etc/nginx/nginx.conf syntax is ok nginx: configuration file /etc/nginx/nginx.conf test is successful
That's what expected to see 'successful'!
Now reload the nginx service:
systemctl reload nginx
Open the NGINX url either using public DNS or Elastic IP in the browser again it will be redirected to Jenkins 'Unlock Jenkins' page. Wow!!, proceed further steps as you know regular as we did in the last Jenkins installation post.
1 comment:
Thanks Pavan .. this article really helps
Post a Comment