Skip to content

Instantly share code, notes, and snippets.

@stevemcquaid
Last active January 22, 2019 17:54
Show Gist options
  • Save stevemcquaid/73bc5324886a8fe05c52 to your computer and use it in GitHub Desktop.
Save stevemcquaid/73bc5324886a8fe05c52 to your computer and use it in GitHub Desktop.
Configures Jenkins on CentOS
### Copyright GoDaddy 2014
### Created by: Steve McQuaid - smcquaid@godaddy.com
### centos-jenkins.sh
### This file will configure a Centos VM on Openstack to install jenkins (& java dependency), git, jenkins plugin repository, &Nginx Reverse Proxy to serve Jenkins on Port 80.
### @TODO - Solve bug in Docker
### @TODO - Pre-configure example job
###fixes minor annoyance which will prevent git from authenticating with new host (for git enterprise)
### this must be run as root
echo "Adding github.secureserver.net to list of known hosts..."
ssh -o "StrictHostKeyChecking no" git@github.secureserver.net
echo "Configuring package manager to install Jenkins.."
### Be careful - sometimes the mirror is down on this
sudo wget -O /etc/yum.repos.d/jenkins.repo http://pkg.jenkins-ci.org/redhat/jenkins.repo
sudo rpm --import http://pkg.jenkins-ci.org/redhat/jenkins-ci.org.key
echo "Installing Java..."
sudo yum -y install java-1.6.0-openjdk
echo "Installing Git from source for latest version..."
sudo yum -y install curl-devel
#sudo yum -y install git ### We do not want to use the default centos repo version of git since it is an older version of git not compatable with jenkins credendials
sudo yum -y groupinstall "Development Tools"
sudo yum -y install zlib-devel perl-ExtUtils-MakeMaker asciidoc xmlto openssl-devel
wget -O git.zip https://github.com/git/git/archive/master.zip
unzip git.zip
## @TODO - Figure out a way to: $ make configure; and: $ make install; without changing directory
cd git-master
make configure
./configure --prefix=/usr/local
make all doc
echo "This may take awhile..."
sudo make install install-doc install-html
cd .. #return to directory
echo "Installing Jenkins..."
sudo yum -y install jenkins
### Don't need to install nginx.
# echo "Installing Nginx"
# wget http://nginx.org/packages/centos/6/noarch/RPMS/nginx-release-centos-6-0.el6.ngx.noarch.rpm
# sudo rpm -ivh nginx-release-centos-6-0.el6.ngx.noarch.rpm
# sudo yum -y install nginx
# sudo chkconfig nginx on ### Assure nginx starts on restart
# sudo service nginx start
# echo "Configuring reverse proxy..."
# ### Stop Jenkins from binding to all interfaces, bind to the local loopback address
# #sudo sed -i "s,^JENKINS_ARGS=\".*,JENKINS_ARGS=\"--httpListenAddress=127.0.0.1\"," /etc/sysconfig/jenkins
# sudo rm /etc/nginx/conf.d/default.conf
# sudo touch /etc/nginx/conf.d/jenkins-nginx.conf
# ### Get IP address
# IPADDR=$(/sbin/ifconfig eth0 | grep 'inet addr:' | cut -d: -f2 | awk '{ print $1}')
# sudo tee -a /etc/nginx/conf.d/jenkins-nginx.conf >/dev/null <<EOF
# server {
# listen 80;
# server_name ci.godaddy.com;
# location / {
# proxy_pass http://$IPADDR: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_read_timeout 100;
# proxy_buffers 4 32k;
# client_max_body_size 8m;
# client_body_buffer_size 128k;
# }
# }
# EOF
# sudo service nginx restart ### Restart nginx
sudo service jenkins start ### Start jenkins
echo "Installing Docker"
sudo rpm -Uvh http://mirrors.kernel.org/fedora-epel/6/i386/epel-release-6-8.noarch.rpm
sudo yum -y install docker-io
# sudo yum -y update docker-io
# export DOCKER_HOST=tcp://localhost:2375 ###@TODO - Above line should be added to /etc/profile
### Start docker at boot
sudo service docker start
sudo chkconfig docker on ###This used to break the pipe
#### Add permissions so jenkins can access docker non-sudo
sudo groupadd docker
sudo gpasswd -a jenkins docker
sudo service docker restart
echo "Adding plugin availablity listing"
### Be careful - sometimes the mirror is down on this
wget -O default.js http://updates.jenkins-ci.org/update-center.json
sed '1d;$d' default.js > default.json
curl -X POST -H "Accept: application/json" -d @default.json http://localhost:8080/updateCenter/byId/default/postBack --verbose
### @TODO need to setup ssh keys
echo "Configuring SSH keys for Jenkins//Git Integration"
su -s /bin/bash jenkins <<'EOF'
ssh-keygen -f ~/.ssh/id_rsa -t rsa -N ''
EOF
echo "Attempting to start Jenkins..."
sudo service jenkins restart
echo "Jenkins installation complete!"
echo "Welcome to your new CI server!"
echo "To access your new installation go to: http://$IPADDR"
### Notes:
### Jenkins will be launched as a daemon up on start. See /etc/init.d/jenkins for more details.
### The 'jenkins' user is created to run this service. If you change this to a different user via the config file,
### you must change the owner of /var/log/jenkins, /var/lib/jenkins, and /var/cache/jenkins.
### Log file will be placed in /var/log/jenkins/jenkins.log. Check this file if you are troubleshooting Jenkins.
### /etc/sysconfig/jenkins will capture configuration parameters for the launch.
### By default, Jenkins listen on port 8080. I changed this to be port 80. Access this port with your browser
### to start configuration.
### Note that the built-in firewall may have to be opened to access this port from other computers.
### (See http://www.cyberciti.biz/faq/disable-linux-firewall-under-centos-rhel-fedora/ for instructions how to
### disable the firewall permanently)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment