Skip to content

Instantly share code, notes, and snippets.

@thomd
Last active April 14, 2018 13:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thomd/8708966d6b55e5b32c8da9b1fb7fa48f to your computer and use it in GitHub Desktop.
Save thomd/8708966d6b55e5b32c8da9b1fb7fa48f to your computer and use it in GitHub Desktop.
Install Jenkins on AWS Ubuntu with Ngins as Proxy
#!/usr/bin/env bash
# Install Jenkins and Nginx as proxy on AWS
# [source: https://serversforhackers.com/c/installing-jenkins]
#
#
# USAGE
#
# curl -sSL https://gist.githubusercontent.com/thomd/8708966d6b55e5b32c8da9b1fb7fa48f/raw/aws-nginx-jenkins.sh | sudo sh
# open http://<IP>
#
# Unlock Jenkins:
#
# sudo cat /var/lib/jenkins/secrets/initialAdminPassword
#
#
# Git Server Access for Github
#
# cat ~/.ssh/id_rsa.pub
# ssh -T git@github.com # test and add github.com to known_hosts
#
# ----- jenkins port 8080 ---------------------------------------------------------------
sudo apt-get update
sudo apt-get install -y vim curl wget tmux unzip htop ntp software-properties-common
wget -q -O - https://pkg.jenkins.io/debian/jenkins-ci.org.key | sudo apt-key add -
echo 'deb http://pkg.jenkins.io/debian-stable binary/' | sudo tee /etc/apt/sources.list.d/jenkins.list
sudo apt-get update
sudo apt-get install -y jenkins
# ----- nginx proxy port 80 --------------------------------------------------------------
sudo add-apt-repository -y ppa:nginx/stable
sudo apt-get update
sudo apt-get install -y nginx
sudo rm /etc/nginx/sites-enabled/default
cat <<EOF > /etc/nginx/sites-available/jenkins
server {
listen 80 default_server;
server_name localhost;
location / {
proxy_pass http://localhost:8080;
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_connect_timeout 150;
proxy_send_timeout 100;
proxy_buffers 4 32k;
client_max_body_size 8m;
client_body_buffer_size 128k;
}
}
EOF
sudo ln -s /etc/nginx/sites-available/jenkins /etc/nginx/sites-enabled/jenkins
sudo service nginx configtest
sudo service nginx reload
# ----- Docker Support [Optional] ---------------------------------------------------------
curl -sSL https://get.docker.com/ | sudo sh
sudo usermod -aG docker jenkins
sudo su
curl -L https://github.com/docker/compose/releases/download/1.10.0/docker-compose-`uname -s`-`uname -m` > /usr/local/bin/docker-compose
chmod +x /usr/local/bin/docker-compose
exit
sudo service jenkins restart
# ----- server git access -----------------------------------------------------------------
sudo su jenkins
mkdir ~/.ssh
cd ~/.ssh
ssh-keygen -t rsa -b 4096 -f id_rsa -N '' -C "jenkins-ci"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment