Installing GitLab 6.6 (6.x) on CentOS 6.5 with Percona Server 5.6
GitLab CE (Community Edition) is essentially a self-hosted opensource clone of the online Git code repository service GitHub.
The main installation guide for GitLab was written for installation on Ubuntu/Debian operating systems.
This guide covers the steps required for a fresh install of GitLab production server on CentOS 6.5 with Percona Server 5.6 (drop-in replacement for MySQL®).
1. Install the EPEL and RPMForge packages,and update CentOS 6.5.
# rpm -Uvh http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm
# rpm -Uvh http://pkgs.repoforge.org/rpmforge-release/rpmforge-release-0.5.3-1.el6.rf.x86_64.rpm
# yum -y update
2. Enable the RPMForge Extras. Open the RPMForge repo.
nano /etc/yum.repos.d/rpmforge.repo
and change enabled = 0
under [rpmforge-extras]
to enabled = 1
3. Add the EPEL SCL (Software Collections) repo to your CentOS installation.
# wget -P /etc/yum.repos.d http://people.redhat.com/bkabrda/scl_ruby193.repo
4. Then install the Development tools.
# yum -y groupinstall 'Development Tools'
5. Install the Percona repo and Percona Server 5.6
# rpm -Uhv http://www.percona.com/downloads/percona-release/percona-release-0.0-1.x86_64.rpm
# yum -y install Percona-Server-client-56 Percona-Server-server-56 Percona-Server-devel-56
6. Ok. Now install ruby193, git, redis and nginx (as well as a few other required packages). And start all the services.
(* The install command below should cover all the packages required to enable a smooth install of GitLab. However, depending on your base install of CentOS 6.5, you may require some extra packages not listed below. The installation process is pretty good at making clear what you're missing if anything.)
# service mysql start
# service redis start
# service nginx start
# chkconfig mysql on
# chkconfig redis on
# chkconfig nginx on
7. Add the user git and set the git globals.
# adduser -r -s /bin/bash -c 'Gitlab user' -m -d /home/git git
# chmod o+x /home/git
# su - git
[git@gitlab ~]$ git config --global user.name "GitLab"
[git@gitlab ~]$ git config --global user.email "gitlab@localhost"
[git@gitlab ~]$ git config --global core.autocrlf input
8. Still as the git user, clone the git repos.
[git@gitlab ~]$ git clone https://github.com/gitlabhq/gitlab-shell.git
[git@gitlab ~]$ git clone https://github.com/gitlabhq/gitlabhq.git gitlab
9. Extend your .bashrc ( [git@gitlab ~]$ nano .bashrc
) to have the following content which will load our scl environment for us when we login.
# .bashrc
# Source global definitions
if [ -f /etc/bashrc ]; then
. /etc/bashrc
fi
source /opt/rh/ruby193/enable
# User specific aliases and functions
10. Make sure the paths are right. You can test this by executing env
.
11. Logout and login again as user gitlab ( su - git
). If everything went fine you should be able to do this.
[git@gitlab ~]$ which ruby
/opt/rh/ruby193/root/usr/bin/ruby
[git@gitlab ~]$ ruby --version
ruby 1.9.3p327 (2012-11-10 revision 37606) [x86_64-linux]
12. As git, cd into the git-shell dir and checkout version 1.7.1
[git@gitlab ~]$ cd gitlab-shell/
[git@gitlab gitlab-shell]$ git checkout v1.8.0
13. Copy the file config.yml.example
to config.yml
in the git-shell directory
cp config.yml.example config.yml
14. Install gitshell.
[git@gitlab gitlab-shell]$ ./bin/install
15. IMPORTANT. Do this still as the git user! Checkout gitlab 6.
[git@gitlab ~]$ cd gitlab
[git@gitlab gitlab]$ git checkout 6-6-stable
16. Now configure Gitlab and install the gems.
[git@gitlab gitlab]$ gem install json
[git@gitlab gitlab]$ gem install charlock_holmes --version '0.6.9.4'
17. Time to configure GitLab. Copy the example GitLab config and set the necessary file permissions, ownership, and create the required directories using the following commands.
[git@gitlab gitlab]$ cp /home/git/gitlab/config/gitlab.yml{.example,}
[git@gitlab gitlab]$ sed -i 's/localhost/gitlab.local.domb.com/g' /home/git/gitlab/config/gitlab.yml
[git@gitlab gitlab]$ chown -R git /home/git/gitlab/log/
[git@gitlab gitlab]$ chown -R git /home/git/gitlab/tmp/
[git@gitlab gitlab]$ chmod -R u+rwX /home/git/gitlab/log/
[git@gitlab gitlab]$ chmod -R u+rwX /home/git/gitlab/tmp/
[git@gitlab gitlab]$ mkdir /home/git/gitlab-satellites
[git@gitlab gitlab]$ mkdir /home/git/gitlab/tmp/pids/
[git@gitlab gitlab]$ mkdir /home/git/gitlab/tmp/sockets/
[git@gitlab gitlab]$ chmod -R u+rwX /home/git/gitlab/tmp/pids/
[git@gitlab gitlab]$ chmod -R u+rwX /home/git/gitlab/tmp/sockets/
[git@gitlab gitlab]$ mkdir /home/git/gitlab/public/uploads
[git@gitlab gitlab]$ chmod -R u+rwX /home/git/gitlab/public/uploads
18. Update your /home/git/gitlab/config/gitlab.yml
file with your host
(e.g. mygitlab.example.com), and email address ( email_from
).
19. Copy the /home/git/gitlab/config/unicorn.rb.example
to /home/git/gitlab/config/unicorn.rb
and configure it by uncommenting the follow section.
72 old_pid = "#{server.config[:pid]}.oldbin"
73 if old_pid != server.pid
74 begin
75 sig = (worker.nr + 1) >= server.worker_processes ? :QUIT : :TTOU
76 Process.kill(sig, File.read(old_pid).to_i)
77 rescue Errno::ENOENT, Errno::ESRCH
78 end
79 end
20. Change the user and password in the /home/git/gitlab/config/database.yml
file (create this file or rename the existing database.yml.mysql
file).
production:
adapter: mysql2
encoding: utf8
reconnect: false
database: gitlabhq_production
pool: 5
username: gitlab
password: "mysql_password_here"
# host: localhost
# socket: /tmp/mysql.sock
21. Create a MySQL User in Percona
[git@gitlab gitlab]$ mysql -u root
# Create a user for GitLab. (change 'mysql_password_here' to a real password)
CREATE USER 'gitlab'@'localhost' IDENTIFIED BY 'mysql_password_here';
# Create the GitLab production database
CREATE DATABASE IF NOT EXISTS `gitlabhq_production` DEFAULT CHARACTER SET `utf8` COLLATE `utf8_unicode_ci`;
# Grant the GitLab user necessary permissions on the table.
GRANT SELECT, LOCK TABLES, INSERT, UPDATE, DELETE, CREATE, DROP, INDEX, ALTER ON `gitlabhq_production`.* TO 'gitlab'@'localhost';
22. Check you can login as the gitlab user.
[git@gitlab gitlab]$ mysql -u gitlab -p -D gitlabhq_production
23. As root, create a gitlab.conf
nginx config file # nano /etc/nginx/conf.d/gitlab.conf
, and add the following to it.
upstream gitlab {
server unix:/home/git/gitlab/tmp/sockets/gitlab.socket;
}
server {
listen *:80 default_server; # e.g., listen 192.168.1.1:80; In most cases *:80 is a better
server_name gitlab.local.domb.com; # e.g., server_name mygitlab.example.com;
server_tokens off; # don't show the version number, a security best practice
root /home/git/gitlab/public;
# individual nginx logs for this gitlab vhost
access_log /var/log/nginx/gitlab_access.log;
error_log /var/log/nginx/gitlab_error.log;
location / {
# serve static files from defined root folder;.
# @gitlab is a named location for the upstream fallback, see below
try_files $uri $uri/index.html $uri.html @gitlab;
}
# if a file, which is not found in the root folder is requested,
# then the proxy pass the request to the upsteam (gitlab unicorn)
location @gitlab {
proxy_read_timeout 300; # https://github.com/gitlabhq/gitlabhq/issues/694
proxy_connect_timeout 300; # https://github.com/gitlabhq/gitlabhq/issues/694
proxy_redirect off;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_pass http://gitlab;
}
}
24. (You may need to) Disable the nginx default.conf
config file, and restart nginx.
# mv /etc/nginx/conf.d/default.conf /etc/nginx/conf.d/defualt.conf.off
# service nginx restart
25. From the gitlab dir execute the below to enable support with MySQL/Percona.
[git@gitlab gitlab]$ bundle install --deployment --without development test postgres
[git@gitlab gitlab]$ bundle exec rake gitlab:setup RAILS_ENV=production
# Type 'yes' to create the database tables.
26. If everything installed without any errors you'll see:
Administrator account created:
login.........admin@local.host
password......5iveL!fe
27. As root get the init script.
# cp /home/git/gitlab/lib/support/init.d/gitlab /etc/init.d/gitlab
# chmod +x /etc/init.d/gitlab
28. If you want you can now configure the mail server. Open /etc/mail/sendmail.mc
and add or modify the following lines.
Add:
define(`SMART_HOST', `smtp.example.com')dnl
Comment
dnl EXPOSED_USER(`root')dnl
29. Restart sendmail # service sendmail restart
30. Forward all email to a central mail address.
# echo adminlogs@example.com > /root/.forward
# chown root /root/.forward
# chmod 600 /root/.forward
# echo adminlogs@example.com > /home/git/.forward
# chown git /home/git/.forward
# chmod 600 /home/git/.forward
31. Your done. Start up your server
# service gitlab start
# service nginx restart
32. You can now browse to your GitLab URL http://yourgitlabserver.com
and login using the username and password presented during the installation.
Sources:
GitLab 6.0 (6.x) installation instructions with SCL for RHEL 6.4 and CentOS 6.4
GitLab.org - installation.md
If you spot any errors above, please do drop me a comment below.