Skip to main content

Amazon Web Services

Install GitLab on Amazon EC2 Cloud Server

There are plenty of web pages to guide you how to install GitLab on an Ubuntu server. The official document in GitHub is also using Ubuntu as example.  You may follow them to install GitLab on Amazon EC2 Cloud Server but you may meet various problems that stop you from moving forward. I feel it is very necessary to write a specific guide in steps how to install GitLab on Amazon EC2 Cloud Server (actually it is Redhat Linux).

Note: I assume you have root account or an account you can run sudo –s to play as a root on your .

1.  Download EPEL repo to yum

$    sudo -s

$    cd /installationfiles  # you can cd to where you save the download files

$    rpm -Uvh http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm 

2. Install all required packages

$    yum -y groupinstall ‘Development Tools’ ‘Additional Development’ 

$    yum -y install readline readline-devel ncurses-devel gdbm-devel glibc-devel tcl-devel openssl-devel curl-devel expat-devel db4-devel byacc gitolite 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 readline mysql-devel postgresql-devel

3.  Uninstall Ruby 1.8.7 and reinstall Ruby 1.9

Because only Ruby 1.9 is supported so we need to uninstall the original Ruby 1.8.7

$    yum remove ruby

$    curl -O http://ftp.ruby-lang.org/pub/ruby/1.9/ruby-1.9.3-p0.tar.gz

$    tar xzvf ruby-1.9.3-p0.tar.gz

$    cd ruby-1.9.3-p0

$    ./configure –enable-shared –disable-pthread 

$    make && make install 

4.  Install qt-devel qtwebkit-devel

$    yum install qt-devel qtwebkit-devel

$    export PATH=$PATH:/usr/lib64/qt4/bin

5.  Install all the gems GitLab needs to run

$    gem update –system

$    gem update

$    gem install rails

6.  System Users

$    adduser –shell /bin/bash –create-home –home-dir /home/gitlab gitlab

$    su gitlab 

$    ssh-keygen -t rsa   # as gitlab user

$    exit                #switch back to root

$    adduser –system –shell /bin/sh –comment ‘gitolite’ –create-home –home-dir /home/git git 

$    cp /home/gitlab/.ssh/id_rsa.pub /home/git/gitlab.pub  #make sure you do this as root

7.  Download gitolite 3.2 and install

$    cd /home/git

$    git clone -b gl-v320 https://github.com/gitlabhq/gitolite.git /home/git/gitolite

# Add Gitolite scripts to $PATH

$    mkdir /home/git/bin

$    sh -c ‘printf “%b\n%b\n” “PATH=\$PATH:/home/git/bin” “export PATH” >> /home/git/.profile’

$    sh -c ‘gitolite/install -ln /home/git/bin’

# … and use it as the admin key for the Gitolite setup

$    sh -c PATH=/home/git/bin:$PATH

$    su git

$    gl-setup ~/gitlab.pub # this passes the admin key to gitolite

When the prompt appears edit the provided file (it’s in a vi-Editor) and set $REPO_UMASK to 0007

$    exit                #switch back to root

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

$    usermod -a -G git gitlab

$    chmod -R g+rwX /home/git/repositories/

$    chmod 775 /home/git

$    passwd gitlab # please choose a good password

# Add domains to list to the list of known 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

# Test if everything works so far

# 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

8.  GitLab needs a few gems, we haven’t installed yet

$    curl http://python-distribute.org/distribute_setup.py | python

$    easy_install pip

$    pip install pigments

$    gem install bundler

9.  gitlab user will have to do a bit of administration stuff, so we need to give him sudo rights

$    visudo

# Add gitlab ALL=(ALL) ALL after root ALL=(ALL) ALL so it looks like this:

        1:  … 

        2:  root    ALL=(ALL)    ALL 

        3:  gitlab    ALL=(ALL)    ALL 

        4:  … 

Do not edit anything else!!!

10.  Finished with the gem stuff

$    su gitlab

# Get the GitLab software

$    cd && git clone git://github.com/gitlabhq/gitlabhq.git 

$    cd gitlabhq

$    bundle install

11.  Install MySQL

$    exit                #switch back to root

$    yum -y install mysql-server

$    /etc/init.d/mysqld start

$    mysql_secure_installation

# Remember the password you type in for root!

$    mysql -u root -p # when prompted enter the root password you’ve chosen in mysql_secure_installation

      1:  mysql> CREATE DATABASE gitlab CHARACTER SET UTF8; 

      2:  mysql> GRANT ALL PRIVILEGES ON gitlab.* TO ‘gitlabusr’@’localhost’ IDENTIFIED BY ‘supersecret’ WITH GRANT OPTION; 

      3:  mysql> quit 

Remember the password and username (here: gitlabusr and supersecret)!

12.  Needs an additional service to run

$    nohup redis-server > /dev/null

# Enter the password you created for the gitlab user and hit CTRL+Z. Then type

$    bg

13.  Configure Gitlab

$    cp /home/gitlab/gitlabhq/config/database.yml.mysql /home/gitlab/gitlabhq/config/database.yml

$    cp /home/gitlab/gitlabhq/config/gitlab.yml.example /home/gitlab/gitlabhq/config/gitlab.yml

# In database.yml you have to edit the production settings of your database (at the very top of the file). You have to change the database-name, username and password.

14.  Create database structure

$    RAILS_ENV=production rake db:setup 

$    RAILS_ENV=production rake db:seed_fu 

15.  Start the server

$    su gitlab

$    cd /home/gitlab/gitlabhq

$    sudo nohup redis-server > /dev/null

# Hit CTRL+Z. Then type

$    bg

$    bundle exec rails s -e production

# To start as backend service

$    nohup bundle exec rails s -e production & 1> /dev/null

# Open http://your-ip-or-domain:3000/ and log in with

user: admin@local.host

pass: 5iveL!fe

 

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Follow Us