Skip to content

Instantly share code, notes, and snippets.

@buihuuloc
Forked from mevrians/jenkins-ec2-centos.sh
Created March 18, 2020 13:41
Show Gist options
  • Select an option

  • Save buihuuloc/74477041af9ed4cfe43c74a89c5a3bad to your computer and use it in GitHub Desktop.

Select an option

Save buihuuloc/74477041af9ed4cfe43c74a89c5a3bad to your computer and use it in GitHub Desktop.
Install Jenkins on EC2 Centos Server (Amazon)
#!/bin/bash
# Install stable version
sudo wget -O /etc/yum.repos.d/jenkins.repo http://pkg.jenkins-ci.org/redhat-stable/jenkins.repo
sudo rpm --import https://jenkins-ci.org/redhat/jenkins-ci.org.key
sudo yum install jenkins
# Install Java version 1.8
wget --no-cookies --no-check-certificate --header "Cookie: gpw_e24=http%3A%2F%2Fwww.oracle.com%2F; oraclelicense=accept-securebackup-cookie" "http://download.oracle.com/otn-pub/java/jdk/8u144-b01/090f390dda5b47b9b721c7dfaa008135/jre-8u144-linux-x64.rpm"
sudo yum localinstall jre-8u144-linux-x64.rpm
wget --no-cookies --no-check-certificate --header "Cookie: gpw_e24=http%3A%2F%2Fwww.oracle.com%2F; oraclelicense=accept-securebackup-cookie" "http://download.oracle.com/otn-pub/java/jdk/8u144-b01/090f390dda5b47b9b721c7dfaa008135/jdk-8u144-linux-x64.rpm"
sudo yum localinstall jdk-8u144-linux-x64.rpm
# Verify java version by command: java -version
# Start jenkins: by default, jenkins server will listen on port 8080
sudo service jenkins start
# Verify Jenkins service by command: sudo service jenkins status
# OPTIONAL: To run jenkins server on port 80 (by default, jenkins user does not have permission to listen on por 80 - so do not try to modify the jenkins configuration)
# Instal nginx
sudo yum install nginx
# Update nginx configuration to have jenkins on port 80
sudo vi /etc/nginx/nginx.conf
# Find and replace:
#
# location / {
# }
#
# by
#
# location / {
# proxy_pass http://127.0.0.1:8080;
# proxy_redirect off;
# proxy_set_header Host $host;
# proxy_set_header X-Real-IP $remote_addr;
# proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
# proxy_set_header X-Forwarded-Proto $scheme;
# }
#
# Start nginx service
sudo service nginx start
# Access jenkins server at: https://YOUR_SERVER
# Note: first admin password: sudo more /var/lib/jenkins/secrets/initialAdminPassword
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment