Skip to content

Instantly share code, notes, and snippets.

@wake
Last active November 30, 2016 16:43
Show Gist options
  • Save wake/5304650 to your computer and use it in GitHub Desktop.
Save wake/5304650 to your computer and use it in GitHub Desktop.
Build GitLab 5.1 on DigitalOcen CentOS 6.3 x64

GitLab 4.2 Installation (DigitalOcen CentOS 6.3 x64)


  1. Packages / Dependencies ==========================
yum groupinstall "Development Tools" -y
yum install kernel-devel \
  kernel-headers \
  zlib-devel \
  libyaml-devel \
  openssl-devel \
  gdbm-devel \
  readline-devel \
  ncurses-devel \
  libffi-devel \
  git \
  curl \
  openssh-server \
  redis \
  postfix \
  libxml2-devel \
  libxslt-devel \
  perl-Time-HiRes \
  curl-devel \
  libicu-devel \
  mysql-devel -y
  1. Ruby (1.9.3-p327) ====================
mkdir /tmp/ruby && cd /tmp/ruby
curl --progress http://ftp.ruby-lang.org/pub/ruby/1.9/ruby-1.9.3-p392.tar.gz | tar xz
cd ruby-1.9.3-p392
./configure
make
sudo make install

Install the Bundler Gem

sudo gem install bundler

If you get

  1. System Users ===============
sudo useradd -r -m git
sudo useradd -g git gitlab
sudo chmod g+x /home/git
sudo -u gitlab -H ssh-keygen -q -N '' -t rsa -f /home/gitlab/.ssh/id_rsa
  1. Gitolite ===========
cd /home/git
sudo -u git -H git clone -b gl-v320 git://github.com/gitlabhq/gitolite.git /home/git/gitolite

Add Gitolite scripts to $PATH

sudo -u git -H mkdir /home/git/bin
sudo -u git -H sh -c 'printf "%b\n%b\n" "PATH=\$PATH:/home/git/bin" "export PATH" >> /home/git/.profile'
sudo -u git -H sh -c 'gitolite/install -ln /home/git/bin'

If you get

Set Gitolite users

Copy the gitlab user's (public) SSH key...

sudo cp /home/gitlab/.ssh/id_rsa.pub /home/git/gitlab.pub
sudo chmod 0444 /home/git/gitlab.pub

... and use it as the admin key for the Gitolite setup

sudo -u git -H sh -c "PATH=/home/git/bin:$PATH; gitolite setup -pk /home/git/gitlab.pub"

Make sure the Gitolite config dir is owned by git

sudo chmod 750 /home/git/.gitolite/
sudo chown -R git:git /home/git/.gitolite/

Make sure the repositories dir is owned by git and it stays that way

sudo chmod -R ug+rwXs,o-rwx /home/git/repositories/
sudo chown -R git:git /home/git/repositories/
sudo chmod -R ug-s /home/git/repositories/
find /home/git/repositories/ -type d -print0 | sudo xargs -0 chmod g+s

Add domain to know_hosts

sudo -u gitlab -H ssh git@localhost
sudo -u gitlab -H ssh git@YOUR_DOMAIN_NAME
sudo -u gitlab -H ssh git@YOUR_GITOLITE_DOMAIN_NAME

Clone the admin repo so SSH adds localhost to known_hosts and to be sure your users have access to Gitolite

sudo -u gitlab -H git clone git@localhost:gitolite-admin.git /tmp/gitolite-admin

If it succeeded without errors you can remove the cloned repo

sudo rm -rf /tmp/gitolite-admin
  1. Database (MySQL) ===================
yum install mysql mysql-devel mysql-server -y

Start mysql and set a password for root@localhost

service mysqld start
mysqladmin -u root password 'YOUR_PASSWORD'

Connect to MySQL and...

  • Create a user for GitLab
  • Create the production database
  • Grant the necessary permissopns
mysql -u root -p
mysql> CREATE USER 'gitlab'@'localhost' IDENTIFIED BY 'GITLAB_PASSWORD';
mysql> CREATE DATABASE IF NOT EXISTS `gitlabhq_production` DEFAULT CHARACTER SET `utf8` COLLATE `utf8_unicode_ci`;
mysql> GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, DROP, INDEX, ALTER ON `gitlabhq_production`.* TO 'gitlab'@'localhost';
mysql> \q

Try connecting to the new database with the new user

sudo -u gitlab -H mysql -u gitlab -p -D gitlabhq_production
  1. GitLab =========
cd /home/gitlab
sudo -u gitlab -H git clone git://github.com/gitlabhq/gitlabhq.git gitlab
cd /home/gitlab/gitlab
sudo -u gitlab -H git checkout 4-2-stable

Configure it

cd /home/gitlab/gitlab
sudo -u gitlab -H cp config/gitlab.yml.example config/gitlab.yml

Make sure to change "localhost" to the fully-qualified domain name of your host serving GitLab where necessary

sudo -u gitlab -H vi config/gitlab.yml

Make sure GitLab can write to the log/ and tmp/ directories

sudo chown -R gitlab log/
sudo chown -R gitlab tmp/
sudo chmod -R u+rwX  log/
sudo chmod -R u+rwX  tmp/

Make directory for satellites

sudo -u gitlab -H mkdir /home/gitlab/gitlab-satellites

Copy the example Unicorn config

sudo -u gitlab -H cp config/unicorn.rb.example config/unicorn.rb

Database config

sudo -u gitlab cp config/database.yml.mysql config/database.yml
sudo -u gitlab -H vi config/database.yml

Install Gems

sudo gem install charlock_holmes --version '0.6.9'
sudo -u gitlab -H bundle install --deployment --without development test postgres

Configure git

sudo -u gitlab -H git config --global user.name "GitLab"
sudo -u gitlab -H git config --global user.email "gitlab@YOUR_DOMAIN_NAME"

Set hooks for GitLab

sudo cp ./lib/hooks/post-receive /home/git/.gitolite/hooks/common/post-receive
sudo chown git:git /home/git/.gitolite/hooks/common/post-receive

Initialize database

sudo -u gitlab -H bundle exec rake gitlab:setup RAILS_ENV=production

GitLab initializer

sudo curl --output /etc/init.d/gitlab https://raw.github.com/gitlabhq/gitlab-recipes/4-2-stable/init.d/gitlab
sudo chmod +x /etc/init.d/gitlab

Check if everything is ok

sudo -u gitlab -H bundle exec rake gitlab:env:info RAILS_ENV=production
sudo -u gitlab -H bundle exec rake gitlab:check RAILS_ENV=production

If you get

  1. Start all needed service ===========================
sudo service mysql start
sudo service redis start
sudo service gitlab start
  1. Nginx ========

Install

yum install nginx -y

Download an example site config

sudo curl --output /etc/nginx/conf.d/gitlab.conf https://raw.github.com/gitlabhq/gitlab-recipes/4-2-stable/nginx/gitlab

Make sure to edit the config file to match your setup:

Change YOUR_SERVER_IP and YOUR_SERVER_FQDN to the IP address and fully-qualified domain name of your host serving GitLab

sudo vi /etc/nginx/conf.d/gitlab.conf

Start

sudo service nginx start
  1. Enjoy ========

Default account

admin@local.host
5iveL!fe

If the GitLab can't start or always get 502 response from Nginx, you can check:

  • Unicorn is running?
  • Sidekiq is running?
  • Can Nginx access path /home/gitlab/gitlab?
@ohmerhe
Copy link

ohmerhe commented Jun 2, 2013

how to ensure if Nginx can access path /home/gitlab/gitlab?
and if it is ,what can i do ?
Thank you !

@tucq88
Copy link

tucq88 commented Jun 3, 2013

I checked my config folder and not see any Unicorn file. Instead of Unicorn, I see puma.rb :(

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment