Skip to content

Instantly share code, notes, and snippets.

@bigbigbang
Last active December 22, 2015 12:59
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 bigbigbang/6476386 to your computer and use it in GitHub Desktop.
Save bigbigbang/6476386 to your computer and use it in GitHub Desktop.
Installer for GitLab 6 on RHEL 6 (Red Hat Enterprise Linux and CentOS)
#!/bin/bash
# Installer for GitLab on RHEL 6 (Red Hat Enterprise Linux and CentOS)
#
##Export proxy settings
# Define the public hostname
export GL_HOSTNAME=$HOSTNAME
# Install from this GitLab branch
export GL_GIT_BRANCH="6-0-stable"
## Install epel-release
yum -y install http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm
# Exit on error
die()
{
# $1 - the exit code
# $2 $... - the message string
retcode=$1
shift
printf >&2 "%s\n" "$@"
exit $retcode
}
echo "### Check OS (we check if the kernel release contains el6)"
uname -r | grep "el6" || die 1 "Not RHEL or CentOS 6 (el6)"
## work in /tmp
cd /tmp/
yum -y groupinstall 'Development Tools'
### 'Additional Development'
yum -y install vim-enhanced httpd readline readline-devel ncurses-devel gdbm-devel glibc-devel \
tcl-devel openssl-devel curl-devel expat-devel db4-devel byacc \
sqlite-devel gcc-c++ libyaml libyaml-devel libffi libffi-devel \
libxml2 libxml2-devel libxslt libxslt-devel libicu libicu-devel \
system-config-firewall-tui python-devel redis sudo mysql-server wget \
mysql-devel crontabs logwatch logrotate sendmail-cf qtwebkit qtwebkit-devel \
perl-Time-HiRes perl-ExtUtils-CBuilder perl-ExtUtils-MakeMaker
yum remove -y git
service redis start
service mysqld start
## Install git 1.8.1.2
wget -O v1.8.1.2.tar.gz https://github.com/git/git/archive/v1.8.1.2.tar.gz
tar -xzvf ./v1.8.1.2.tar.gz
cd git-1.8.1.2/
make prefix=/usr/local all
make prefix=/usr/local install
# Ruby
yum -y install patch gcc-c++ readline-devel zlib-devel libffi-devel openssl-devel make autoconf automake libtool bison libxml2-devel libxslt-devel libyaml-devel
mkdir /home/ruby && cd /home/ruby
curl --progress ftp://ftp.ruby-lang.org/pub/ruby/ruby-1.9.3-p286.tar.gz | tar xz
cd ruby-1.9.3-p286
./configure
make
make install
#Rubygems
cd /home/
wget http://production.cf.rubygems.org/rubygems/rubygems-2.0.3.tgz
tar zxf rubygems-2.0.3.tgz
cd rubygems-2.0.3
ruby setup.rb --no-format-executable --no-document
## Install core gems
gem install bundler
## Create a git user for Gitlab
adduser --system --shell /bin/bash --create-home --comment 'GitLab' git
service mysqld start
# Create a user for GitLab. (change supersecret to a real password)
echo "CREATE USER 'gitlab'@'localhost' IDENTIFIED BY 'gitlab';" | mysql -u root
### Create the database
echo "CREATE DATABASE IF NOT EXISTS gitlabhq_production DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci;" | mysql -u root
# Grant the GitLab user necessary permissopns on the table.
echo "GRANT SELECT,LOCK TABLES,INSERT,UPDATE,DELETE,CREATE,DROP,INDEX,ALTER ON gitlabhq_production.* TO 'gitlab'@'localhost';"\
| mysql -u root
# GitLab shell
cd /home/git/
## Clone GitLab
su - git -c "git clone https://github.com/gitlabhq/gitlab-shell.git"
## Checkout
su - git -c "cd gitlab-shell;git checkout v1.7.1"
## configure
su - git -c "cp /home/git/gitlab-shell/config.yml.example /home/git/gitlab-shell/config.yml"
sed -i "s|gitlab_url: http://localhost/|gitlab_url: http://GL_HOSTNAME/|" /home/git/gitlab-shell/config.yml
## Run setup
su - git -c "/home/git/gitlab-shell/bin/install"
# GitLab
su - git -c "cd /home/git/"
## Clone GitLab
su - git -c "git clone https://github.com/gitlabhq/gitlabhq.git /home/git/gitlab"
## Checkout
su - git -c "cd gitlab;git checkout $GL_GIT_BRANCH"
## Configure GitLab
su - git -c "cd /home/git/gitlab"
### Copy the example GitLab config
su git -c "cp /home/git/gitlab/config/gitlab.yml.example /home/git/gitlab/config/gitlab.yml"
### Change gitlabhq hostname to GL_HOSTNAME
sed -i "s|host: localhost|host: GL_HOSTNAME|" /home/git/gitlab/config/gitlab.yml
### Change the from email address
sed -i "s|email_from: gitlab@localhost|email_from: gitlab@arkea.com|" /home/git/gitlab/config/gitlab.yml
#and support too
sed -i "s|support_email: gitlab@localhost|support_email: gitlab@arkea.com|" /home/git/gitlab/config/gitlab.yml
# Make sure GitLab can write to the log/ and tmp/ directories
chown -R git /home/git/gitlab/log/
chown -R git /home/git/gitlab/tmp/
chmod -R u+rwX /home/git/gitlab/log/
chmod -R u+rwX /home/git/gitlab/tmp/
#Create directory for satellites
su git -c "mkdir /home/git/gitlab-satellites"
# Create directories for sockets/pids and make sure GitLab can write to them
su git -c "mkdir /home/git/gitlab/tmp/pids/"
su git -c "mkdir /home/git/gitlab/tmp/sockets/"
chmod -R u+rwX /home/git/gitlab/tmp/pids/
chmod -R u+rwX /home/git/gitlab/tmp/sockets/
# Create public/uploads directory otherwise backup will fail
su git -c "mkdir /home/git/gitlab/public/uploads"
chmod -R u+rwX /home/git/gitlab/public/uploads
su git -c "cp /home/git/gitlab/config/unicorn.rb.example /home/git/gitlab/config/unicorn.rb"
sed -i "s|timeout 30|timeout 60|" /home/git/gitlab/config/database.yml
### Copy database congiguration
su git -c "cp /home/git/gitlab/config/database.yml.mysql /home/git/gitlab/config/database.yml"
### Set MySQL username and password in configuration file
sed -i "s|username: root|username: gitlab|" /home/git/gitlab/config/database.yml
sed -i "s|password: \"secure password\"|password: \"gitlab\"|" /home/git/gitlab/config/database.yml
## Install Charlock holmes
yum -y install libicu-devel
gem install charlock_holmes --version '0.6.9.4'
## For MySQL
cd /home/git/gitlab/
yum -y install mysql-devel
su git -c "bundle install --deployment --without development test postgres"
# Initialise Database and Activate Advanced Features
# Force it to be silent (issue 31)
export force=yes
su git -c "bundle exec rake gitlab:setup RAILS_ENV=production"
## Install init script
curl https://raw.github.com/gitlabhq/gitlab-recipes/master/init/sysvinit/centos/gitlab-unicorn > /etc/init.d/gitlab
chmod +x /etc/init.d/gitlab
## Nginx
yum install -y nginx
service nginx start
mkdir /etc/nginx/sites-{available,enabled}
usermod -a -G git nginx
chmod g+rx /home/git/
cp /home/git/gitlab/lib/support/nginx/gitlab /etc/nginx/sites-available/gitlab
ln -s /etc/nginx/sites-available/gitlab /etc/nginx/sites-enabled/gitlab
sed -i "s|include /etc/nginx/conf.d/*.conf;|include /etc/nginx/sites-enabled/*;|" /etc/nginx/nginx.conf
sed -i "s|server_name YOUR_SERVER_FQDN;|server_name GL_HOSTNAME;|" /etc/nginx/sites-available/gitlab
# Unicorn failed " upstream client closed connection ..."
sed -i "s|timeout 30|timeout 60|" /home/git/gitlab/config/unicorn.rb
chkconfig --add redis
chkconfig --add mysqld
chkconfig --add gitlab
chkconfig --add nginx
chkconfig redis on
chkconfig mysqld on
chkconfig gitlab on
chkconfig nginx on
service redis restart
service mysqld restart
service gitlab start
service nginx restart
echo "### Done ###############################################"
echo "#"
echo "#"
echo "# Point your browser to:"
echo "# http://$GL_HOSTNAME (or: http://<host-ip>)"
echo "# Default admin username: admin@local.host"
echo "# Default admin password: 5iveL!fe"
echo "#"
echo "### TODO : ####"
echo "configure LDAP"
echo "configure EMAIL"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment