Sunday, September 1, 2019

Jenkins Master setup on AWS Instance Ubuntu 18.04

Hello, dear DevOps Enthusiast!

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, HTTPS
Using 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 then
 sudo -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 upgrade
after 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 user
 sudo -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.

Welcome to Jenkins!

Reference:

1 comment:

Karavadi sai said...

Thanks Pavan .. this article really helps

Categories

Kubernetes (24) Docker (20) git (13) Jenkins (12) AWS (7) Jenkins CI (5) Vagrant (5) K8s (4) VirtualBox (4) CentOS7 (3) docker registry (3) docker-ee (3) ucp (3) Jenkins Automation (2) Jenkins Master Slave (2) Jenkins Project (2) containers (2) docker EE (2) docker private registry (2) dockers (2) dtr (2) kubeadm (2) kubectl (2) kubelet (2) openssl (2) Alert Manager CLI (1) AlertManager (1) Apache Maven (1) Best DevOps interview questions (1) CentOS (1) Container as a Service (1) DevOps Interview Questions (1) Docker 19 CE on Ubuntu 19.04 (1) Docker Tutorial (1) Docker UCP (1) Docker installation on Ubunutu (1) Docker interview questions (1) Docker on PowerShell (1) Docker on Windows (1) Docker version (1) Docker-ee installation on CentOS (1) DockerHub (1) Features of DTR (1) Fedora (1) Freestyle Project (1) Git Install on CentOS (1) Git Install on Oracle Linux (1) Git Install on RHEL (1) Git Source based installation (1) Git line ending setup (1) Git migration (1) Grafana on Windows (1) Install DTR (1) Install Docker on Windows Server (1) Install Maven on CentOS (1) Issues (1) Jenkins CI server on AWS instance (1) Jenkins First Job (1) Jenkins Installation on CentOS7 (1) Jenkins Master (1) Jenkins automatic build (1) Jenkins installation on Ubuntu 18.04 (1) Jenkins integration with GitHub server (1) Jenkins on AWS Ubuntu (1) Kubernetes Cluster provisioning (1) Kubernetes interview questions (1) Kuberntes Installation (1) Maven (1) Maven installation on Unix (1) Operations interview Questions (1) Oracle Linux (1) Personal access tokens on GitHub (1) Problem in Docker (1) Prometheus (1) Prometheus CLI (1) RHEL (1) SCM (1) SCM Poll (1) SRE interview questions (1) Troubleshooting (1) Uninstall Git (1) Uninstall Git on CentOS7 (1) Universal Control Plane (1) Vagrantfile (1) amtool (1) aws IAM Role (1) aws policy (1) caas (1) chef installation (1) create deployment (1) create organization on UCP (1) create team on UCP (1) docker CE (1) docker UCP console (1) docker command line (1) docker commands (1) docker community edition (1) docker container (1) docker editions (1) docker enterprise edition (1) docker enterprise edition deep dive (1) docker for windows (1) docker hub (1) docker installation (1) docker node (1) docker releases (1) docker secure registry (1) docker service (1) docker swarm init (1) docker swarm join (1) docker trusted registry (1) elasticBeanStalk (1) global configurations (1) helm installation issue (1) mvn (1) namespaces (1) promtool (1) service creation (1) slack (1)