Last modified: [last-modified]
I’ve been eagerly waiting for Gitlab 5.0 to be released so that Gitolite dependency would go away. Well a few days ago I got my wish. I followed the documentation provided by the Gitlab guys at https://github.com/gitlabhq/gitlabhq/blob/5-0-stable/doc/install/installation.md and as expected it didn’t quite match up with what needs to be done to deploy on CentOS 6. It is after all written for Ubuntu. These instructions should also work for Redhat Enterprise 6 and are meant for a fresh installation. Not an upgrade.
Using the official document as a guide I managed to get things deployed on my system and now I’m going to share it with you.
I installed Gitlab 5.0 on CentOS 6.4 64-bit and used MySQL as my database back end and configured my existing Apache deployment to proxy connections to Gitlab. I also installed it under a custom user account and not the default ‘git’ account that the Gitlab documentation tells you to use.
I’m going to assume you already have a CentOS server up and running, SELinux is disabled, you aren’t using a firewall (iptables), the default CentOS Python 2.6 packages installed and Sendmail or Postfix up and running.
If you are running a Minimal Install of CentOS 6 see Olav’s comment below.
Unfortunately the version of Ruby that comes with CentOS 6 is to old for Gitlab so we need to compile that from source. The method I use will install the latest version of Ruby. If you have the CentOS Ruby packages installed it shouldn’t matter. These instructions should allow you to run both versions.
- Install the development tools necessary to compile applications from source
[[email protected] ~] yum -y groupinstall "Development Tools"
[[email protected] ~] yum install perl-ExtUtils-MakeMaker postgresql-devel
- Install missing dependencies I believe this is all of them. If anything is missing drop me a comment and I’ll update this guide.
[[email protected] ~] yum install libxslt-devel libyaml-devel libxml2-devel gdbm-devel libffi-devel zlib zlib-devel openssl-devel libyaml-devel readline readline-devel curl-devel openssl-devel pcre-devel git memcached-devel valgrind-devel mysql-devel ImageMagick-devel ImageMagick libicu libicu-devel libffi-devel make bzip2 autoconf automake libtool bison iconv-devel redis
- Start redis and enable it on boot
[[email protected]~] service redis start
[[email protected]~] chkconfig --levels 35 redis on
- Create a new user account that we’ll run Gitlab under. I’m going to use ‘sa_gitlab’. Gitlab will be deployed in it’s home directory. On my server I want that to be in ‘/data/apps’ instead of ‘/home’
[[email protected]~] adduser sa_gitlab --home-dir=/data/apps/sa_gitlab
# If you want users to be able to use public/private key pairs you need to set a password for the sa_gitlab account. Make sure you use a strong password. This is neccessary to allow SSH access with public/private keys.
[[email protected]~] passwd sa_gitlab
- Become the ‘sa_gitlab’ user and setup the ‘authorized_keys’ list and generate Gitlabs private key
[[email protected]~] su - sa_gitlab
[[email protected]~] mkdir -p /data/apps/sa_gitlab/.ssh
[[email protected]~] chmod -R 700 /data/apps/sa_gitlab/.ssh
[[email protected]~] echo "" > /data/apps/sa_gitlab/.ssh/authorized_keys
[[email protected]~] chmod -R 600 /data/apps/sa_gitlab/.ssh/authorized_keys
# This generates a 2048 bit key pair see below if you're paranoid :)
[[email protected]~] ssh-keygen -q -N '' -t rsa -f /data/apps/sa_gitlab/.ssh/id_rsa
# This generates a 4096 bit key pair
[[email protected]~] ssh-keygen -q -b 4096 -N '' -t rsa -f /data/apps/sa_gitlab/.ssh/id_rsa
[[email protected]~] cat /data/apps/sa_gitlab/.ssh/id_rsa.pub >> /data/apps/sa_gitlab/.ssh/authorized_keys
- Create a ‘temp’ dir for us to work with and a ‘ruby’ dir for Ruby to be installed into. Then download, configured and install Ruby 1.9.3
[[email protected]~] mkdir temp
[[email protected]~] mkdir ruby
[[email protected]~] cd temp
[[email protected]~] wget -c "http://ftp.ruby-lang.org/pub/ruby/1.9/ruby-1.9.3-p392.tar.gz"
[[email protected]~] tar -xf ruby-1.9.3-p392.tar.gz
[[email protected]~] cd ruby-1.9.3-p392
[[email protected]~] ./configure --prefix=/data/apps/sa_gitlab/ruby
[[email protected]~] make
[[email protected]~] make install
- Download, compile and install the latest version of git
[[email protected]~] cd ~/temp
[[email protected]~] wget -c https://git-core.googlecode.com/files/git-1.8.2.3.tar.gz
[[email protected]~] tar -xf git-1.8.2.3.tar.gz
[[email protected]~] cd git-1.8.2.3
[[email protected]~] ./configure --prefix=/data/apps/sa_gitlab/git
[[email protected]~] make
[[email protected]~] make install
- Add the new installation of Ruby to the ‘sa_gitlab’ users PATH so you can use our complied version of Ruby. Also my CentOS came with an old version of bundle installed by default which is to old. We’ll create an alias in the sa_gitlab users bash profile to reference our compiled version of ‘bundle’
[[email protected]~] vim ~/.bash_profile
# -------- Make the following edits --------
# Change the PATH line to look like this:
PATH=$HOME/git/bin:$HOME/ruby/bin:$PATH:$HOME/bin;
# -------- Save and close the file --------
[[email protected]~] vim ~/.bashrc
# -------- Make the following edits --------
# Add this to the bottom. I know it's redundant but it solves a problem when gitlab calls /usr/bin/env
PATH=$HOME/git/bin:$HOME/ruby/bin:$PATH:$HOME/bin;
# -------- Save and close the file --------
# Re-export your PATH
[[email protected]~] PATH=$HOME/git/bin:$HOME/ruby/bin:$PATH:$HOME/bin;
# Verify your using the right version of Ruby now
[[email protected]~] which ruby
~/ruby/bin/ruby
[[email protected]~] ruby --version
ruby 1.9.3p392 (2013-02-22) [x86_64-linux]
[[email protected]~] which git
~/git/bin/git
[[email protected] ~] git --version
git version 1.8.2.3
- Install bundler
[[email protected]~] gem install bundler
- Download gitlab-shell
[[email protected]~] cd ~/
[[email protected]~] mkdir gitlab-shell
[[email protected]~] git clone https://github.com/gitlabhq/gitlab-shell.git gitlab-shell/
- Configure gitlab-shell and install it
[[email protected]~] cd gitlab-shell/
[[email protected]~] cp config.yml.example config.yml
[[email protected]~] vim config.yml
# -------- Make the following edits --------
user: sa_gitlab
gitlab_url: "http://git.yourdomain.com/"
repos_path: "/data/apps/sa_gitlab/repositories"
auth_file: "/data/apps/sa_gitlab/.ssh/authorized_keys"
# -------- Save and close the file --------
[[email protected]~] ./bin/install
- Create yourself a MySQL database on your server and a dedicated user account with full access to it.
- Download Gitlab 5.0
[[email protected]~] cd ~/
[[email protected]~] mkdir gitlab
[[email protected]~] git clone https://github.com/gitlabhq/gitlabhq.git gitlab
[[email protected]~] cd gitlab
[[email protected]~] git checkout 5-0-stable
- Edit the Gitlab configuration file
[[email protected]~] cp config/gitlab.yml.example config/gitlab.yml
[[email protected]~] vim config/gitlab.yml
# -------- Make the following edits --------
host: git.yourdomain.com
port: 80
https: false
user: sa_gitlab
email_from: [email protected]
support_email: [email protected]
satellites:
# Relative paths are relative to Rails.root (default: tmp/repo_satellites/)
path: /data/apps/sa_gitlab/gitlab-satellites/
gitlab_shell:
# REPOS_PATH MUST NOT BE A SYMLINK!!!
repos_path: /data/apps/sa_gitlab/repositories/
hooks_path: /data/apps/sa_gitlab/gitlab-shell/hooks/
git:
bin_path: /data/apps/sa_gitlab/git/bin/git
# -------- Save and close the file --------
- Fix up some permissions
[[email protected]~] chown -R sa_gitlab log/
[[email protected]~] chown -R sa_gitlab tmp/
[[email protected]~] chmod -R u+rwX log/
[[email protected]~] chmod -R u+rwX tmp/
- Create the satellites directory and configure the database
[[email protected]~] mkdir /data/apps/sa_gitlab/gitlab-satellites/
[[email protected]~] mkdir tmp/pids/
[[email protected]~] chmod -R u+rwX tmp/pids/
[[email protected]~] cp config/unicorn.rb.example config/unicorn.rb
[[email protected]~] vim config/unicorn.rb
# -------- Make the following edits --------
# You can change the port that Gitlab will run on to anything. If you don't want to proxy connections to Gitlab via Apache and don't have a web-server running you can set this to 80 or 443. I also commented out the gitlab.socket line because I think it overrides listening on a port
#listen "#{app_dir}/tmp/sockets/gitlab.socket"
listen "127.0.0.1:65527" # listen to port 8080 on the loopback interface
# -------- Save and close the file --------
[[email protected]~] cp config/database.yml.mysql config/database.yml
# -------- Make the following edits --------
vim config/database.yml
database: [DATABASE NAME]
username: [DATABASE USER]
password: "[DATABASE USER PASSWORD]"
host: localhost
# -------- Save and close the file --------
- Install charlocks_holmes
[[email protected]~] cd ~/gitlab
[[email protected]~] gem install charlock_holmes --version '0.6.9'
- Setup the database structure, setup Gitlab and populate the database with default data. Yes one of the commands below says ‘postgres’ instead of ‘mysql’. Note the ‘–without’ in front of it
[[email protected]~] /data/apps/sa_gitlab/ruby/bin/bundle install --deployment --without development test postgres
[[email protected]~] /data/apps/sa_gitlab/ruby/bin/bundle exec rake gitlab:setup RAILS_ENV=production
[[email protected]~] /data/apps/sa_gitlab/ruby/bin/bundle exec rake db:seed_fu RAILS_ENV=production
- Setup the Gitlab Init script. THis file requires a little bit of tweaking because I chose not to use the ‘git’ user. We also have to tell the script where to find our new version of bundle otherwise it will try to use the old version that comes with CentOS. The following is done as root
[[email protected]~] curl --output /etc/init.d/gitlab https://raw.github.com/gitlabhq/gitlab-recipes/5-0-stable/init.d/gitlab
[[email protected]~] chmod +x /etc/init.d/gitlab
[[email protected]~] vim /etc/init.d/gitlab
# -------- Make the following edits --------
# The lines with a + are lines you need to add to the script
APP_ROOT="/data/apps/sa_gitlab/gitlab"
+ APP_USER="sa_gitlab"
# Search and replace "sudo -u git -H bash" with "sudo -u $APP_USER -H bash
# -------- Save and close the file --------
[[email protected]~] /etc/init.d/gitlab start
[[email protected]~] /etc/init.d/gitlab status
Gitlab service / Unicorn with PID 19988 is running.
Gitlab service / Sidekiq with PID 20031 is running.
[[email protected]~] chkconfig --add gitlab
[[email protected]~] chkconfig --levels 35 gitlab on
- Switch back to the Gitlab user and check if anything has gone wrong
[[email protected]~] su - sa_gitlab
[[email protected]~] cd gitlab
[[email protected]~] git config --global user.name "GitLab"
[[email protected]~] git config --global user.email "[email protected]"
[[email protected]~] bundle exec rake gitlab:env:info RAILS_ENV=production
# Check for errors
[[email protected]~] bundle exec rake gitlab:check RAILS_ENV=production
# Check for errors
- Finally if everything above worked out for you then Gitlab should be waiting for you at http://git.yourdomain.com:<PORT> where <PORT> is what we set back in step 14. If you’re happy with this then you’re done. Login with the default username and password ([email protected] / 5iveL!fe) for Gitlab and start using it. If you’re already running a web server and couldn’t run Gitlab on standard web ports add the following to your Apache config to proxy connections from Apache to Gitlab
[[email protected]~] vim /etc/httpd/conf/httpd.conf
# -------- Make the following edits --------
<VirtualHost *:80>
ServerName git.yourdomain.com
DocumentRoot /data/apps/sa_gitlab/gitlab/public
CustomLog logs/git.yourdomain.com combined
ErrorLog logs/git.yourdomain.com-error.log
ProxyPass / http://127.0.0.1:65527/
ProxyPassReverse / http://127.0.0.1:65527/
ProxyPreserveHost On
</VirtualHost>
# -------- Save and close the file --------
[[email protected]~] service httpd graceful
Once you’ve confirmed everything is working for you follow these instructions to run the whole thing over SSL. I’m going to assume you already have SSL certificates and mod_rewrite installed in Apache.
- Change the git-shell configuration to use https:// as the sa_gitlab user
[[email protected]~] vim ~/gitlab-shell/config.yml
# -------- Make the following edits --------
# Add a 's' to the URL
gitlab_url: "https://git.yourdomain.com/"
# -------- Save and close the file --------
[[email protected]~] vim ~/gitlab/config/gitlab.yml
# -------- Make the following edits --------
port: 443
https: true
# -------- Save and close the file --------
- Alter your Apache config with these virtual hosts
[[email protected]~] vim /etc/httpd/conf/httpd.conf
# -------- Make the following edits --------
<VirtualHost *:80>
ServerName git.yourdomain.com
DocumentRoot /data/apps/sa_gitlab/gitlab/public
CustomLog logs/git.yourdomain.com.log combined
ErrorLog logs/git.yourdomain.com-error.log
ProxyPass / http://127.0.0.1:65527/
ProxyPassReverse / http://127.0.0.1:65527/
ProxyPreserveHost On
RewriteEngine On
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://git.yourdomain.com$1 [R,L]
</VirtualHost>
<VirtualHost *:443>
ServerName git.yourdomain.com
DocumentRoot /data/apps/sa_gitlab/gitlab/public
CustomLog logs/git.yourdomain.com.log combined
ErrorLog logs/git.yourdomain.com-error.log
ProxyPass / http://127.0.0.1:65527/
ProxyPassReverse / http://127.0.0.1:65527/
ProxyPreserveHost On
SSLEngine on
SSLProtocol all -SSLv2
SSLCipherSuite ECDHE-RSA-AES128-SHA256:AES128-GCM-SHA256:RC4:HIGH:!MD5:!aNULL:!EDH
SSLCertificateFile /etc/httpd/conf/certs/yourdomain.com.crt
SSLCertificateKeyFile /etc/httpd/conf/certs/yourdomain.com.key
SSLCertificateChainFile /etc/httpd/conf/certs/ca-bundle.pem
</VirtualHost>
# -------- Save and close the file --------
[[email protected]~] service gitlab restart
[[email protected]~] service httpd restart
That’s it! I hope I haven’t missed anything but if I have drop me a comment and I’ll update this post.
Update March 31st, 2013 – I’ve written an article on how to update Gitlab once you’ve gotten it installed. You can find it here.
Update April 23rd, 2013 – Gitlab 5.1 is out! If you’ve followed the above instructions you should have a functioning Gitlab 5.0 instance. To upgrade to Gitlab 5.1 head over to this article: How to upgrade Gitlab 5.0 to 5.1 on CentOS 6 or RHEL6
Update April 26th, 2013 – Fixed an error in step 16. I said to run ‘cd ~/’ and it should be ‘cd ~/gitlab’. Thank you Ronald for pointing that out.
Update April 28th, 2013 – There was an error with my curl command to grab the gitlab init script. I was getting it from the master branch instead of the 5.0 branch. In the latest master Gitlab has changed their init script in a way that it will not work with 5.0 deployments because they moved from unicorn to puma. I updated the URL so it grabs the 5.0 init script.
Update May 21st, 2013 – Added steps for downloading, compiling and installing the latest version of git for use with Gitlab. Resolves a bug I came across when using my original deployment instructions and the default version of git that comes with CentOS 6.
Update May 22nd, 2013 – Added step to modify gitlab/config/gitlab.yml to use the new version of git. I had assumed Gitlab got the location of the git binary from the PATH environmental variable.
References