Saturday, 9 January 2016

How to install and configure the GitLab in Ubuntu 14.04

Step 1:- Check the Hardware requirements.
Here I going to use Ubuntu 14.04 LTS version.

Step 2:- Choose an installation method [ Installation from source or Omnibus package installer ].
But they recommend installing the Omnibus package instead of installing GitLab from source. Omnibus GitLab takes just 2 minutes to install and is packaged in the popular deb and rpm formats. Compared to an installation from source, the Omnibus package is faster to install and upgrade, more reliable to upgrade and maintain, and it shortens the response time for our subscribers' issues. A package contains GitLab and all its dependcies (Ruby, PostgreSQL, Redis, Nginx, Unicorn, etc.), it can be installed without an internet connection.

But I am going to try both methods now.

Step 3:- Install GitLab from Omnibus package.
Enterprise Edition is license-based, so I going to install Community Edition which is free.

1. Install and configure the necessary dependencies.
#apt-get install curl openssh-server ca-certificates postfix
If you install Postfix to send email please select 'Internet Site' during setup.

2. Add the GitLab package server and install the package
#curl | sudo bash
It will create the repo file named "/etc/apt/sources.list.d/gitlab_gitlab-ce.list".
#apt-get install gitlab-ce

It will install latest version[8.3.2-ce.0] Or you can choose your own version,
#apt-get install gitlab-ce=8.3.1-ce.1

3. Configure and start GitLab
#gitlab-ctl reconfigure
Note: Git repository data path=/var/opt/gitlab/git-data, But we can change it as per our need.

4. Browse to the hostname/IP and login
Username: root
Password: 5iveL!fe --> Default Password

Upon signing in, you'll immediately be prompted for a new password.
After updating your password, you'll be presented with your user dashboard. From here you can create a new project or group. If you want to make a new project, simply click on the New Project button, enter the project name, choose the project visibility, and hit the Create Project button. If you want to add more users to your Gitlab instance, you can do so by clicking the Admin Area icon (a large gear and two smaller gears) in the upper-right corner of your screen, and clicking on "New User".

I have installed gitlab by both methods Omnibus package as well as manual installation. I can't see any major difference after installation.
So I also prefer to install Gitlab through Omnibus package installer. Please skip the step 4 if you want to install it from Omnibus package.

Step 4:- Install GitLab from source

1. Packages / Dependencies
#apt-get update && apt-get upgrade -y
Then reboot the server if it requires.
#apt-get install -y build-essential zlib1g-dev libyaml-dev libssl-dev libgdbm-dev libreadline-dev libncurses5-dev libffi-dev curl openssh-server checkinstall libxml2-dev libxslt-dev libcurl4-openssl-dev libicu-dev logrotate python-docutils pkg-config cmake nodejs

Install Git,
#apt-get install -y git-core
Note: It requires Git version 1.7.10 or higher, for example 1.7.12 or 2.0.0.

In order to receive mail notifications, make sure to install a mail server.
#apt-get install -y postfix
Then select 'Internet Site' and press enter to confirm the hostname.

2. Ruby
GitLab requires Ruby 2.0 or higher while the default version on Ubuntu 14.04 is 1.9.3.
Remove the old Ruby if present
#sudo apt-get remove ruby

Download Ruby and compile it:
mkdir /tmp/ruby && cd /tmp/ruby
curl -O --progress
echo 'e2e195a4a58133e3ad33b955c829bb536fa3c075  ruby-2.1.7.tar.gz' | shasum -c - && tar xzf ruby-2.1.7.tar.gz
cd ruby-2.1.7
./configure --disable-install-rdoc
sudo make install

Install the Bundler Gem:
#sudo gem install bundler --no-ri --no-rdoc

3. Go
Since GitLab 8.0, Git HTTP requests are handled by gitlab-workhorse (formerly gitlab-git-http-server). This is a small daemon written in Go. To install gitlab-workhorse we need a Go compiler.

#curl -O --progress
echo '46eecd290d8803887dec718c691cc243f2175fe0  go1.5.1.linux-amd64.tar.gz' | shasum -c - && \
  sudo tar -C /usr/local -xzf go1.5.1.linux-amd64.tar.gz
sudo ln -sf /usr/local/go/bin/{go,godoc,gofmt} /usr/local/bin/
rm go1.5.1.linux-amd64.tar.gz

4. System Users

Create a git user for GitLab:
#sudo adduser --disabled-login --gecos 'GitLab' git

5. Database
We recommend using a PostgreSQL database.

# Install the database packages
sudo apt-get install -y postgresql postgresql-client libpq-dev

# Login to PostgreSQL
sudo -u postgres psql -d template1

# Create a user for GitLab
# Do not type the 'template1=#', this is part of the prompt
template1=# CREATE USER git CREATEDB;

# Create the GitLab production database & grant all privileges on database
template1=# CREATE DATABASE gitlabhq_production OWNER git;

# Quit the database session
template1=# \q

# Try connecting to the new database with the new user
sudo -u git -H psql -d gitlabhq_production

# Quit the database session
gitlabhq_production> \q

6. Redis
GitLab requires at least Redis 2.8.

$ sudo apt-get install -y python-software-properties
$ sudo add-apt-repository -y ppa:rwky/redis
$ sudo apt-get update
$ sudo apt-get install -y redis-server

Enable the redis socket & set 777 permission in /etc/redis/redis.conf

# Add git to the redis group
sudo usermod -aG redis git

7. GitLab

# We'll install GitLab into home directory of the user "git"
cd /home/git

Clone the Source

# Clone GitLab repository
sudo -u git -H git clone -b 8-3-stable gitlab

Note: You can change 8-3-stable to master if you want the bleeding edge version, but never install master on a production server!
Configure It

# Go to GitLab installation folder
cd /home/git/gitlab

# Copy the example GitLab config
sudo -u git -H cp config/gitlab.yml.example config/gitlab.yml

# Update GitLab config file, follow the directions at top of file
sudo -u git -H editor config/gitlab.yml

# Copy the example secrets file
sudo -u git -H cp config/secrets.yml.example config/secrets.yml
sudo -u git -H chmod 0600 config/secrets.yml

# Make sure GitLab can write to the log/ and tmp/ directories
sudo chown -R git log/
sudo chown -R git tmp/
sudo chmod -R u+rwX,go-w log/
sudo chmod -R u+rwX tmp/

# Make sure GitLab can write to the tmp/pids/ and tmp/sockets/ directories
sudo chmod -R u+rwX tmp/pids/
sudo chmod -R u+rwX tmp/sockets/

# Make sure GitLab can write to the public/uploads/ directory
sudo chmod -R u+rwX  public/uploads

# Change the permissions of the directory where CI build traces are stored
sudo chmod -R u+rwX builds/

# Change the permissions of the directory where CI artifacts are stored
sudo chmod -R u+rwX shared/artifacts/

# Copy the example Unicorn config
sudo -u git -H cp config/unicorn.rb.example config/unicorn.rb

# Find number of cores

# Enable cluster mode if you expect to have a high load instance
# Set the number of workers to at least the number of cores
# Ex. change amount of workers to 3 for 2GB RAM server
sudo -u git -H editor config/unicorn.rb

# Copy the example Rack attack config
sudo -u git -H cp config/initializers/rack_attack.rb.example config/initializers/rack_attack.rb

# Configure Git global settings for git user, used when editing via web editor
sudo -u git -H git config --global core.autocrlf input

# Configure Redis connection settings
sudo -u git -H cp config/resque.yml.example config/resque.yml

# Change the Redis socket path if you are not using the default Debian / Ubuntu configuration
sudo -u git -H editor config/resque.yml

Important Note: Make sure to edit both gitlab.yml and unicorn.rb to match your setup

Configure GitLab DB Settings

# PostgreSQL only:
sudo -u git cp config/database.yml.postgresql config/database.yml

# Make config/database.yml readable to git only
sudo -u git -H chmod o-rwx config/database.yml

Install Gems

#sudo -u git -H bundle install --deployment --without development test mysql aws kerberos

# Run the installation task for gitlab-shell (replace `REDIS_URL` if needed):
sudo -u git -H bundle exec rake gitlab:shell:install REDIS_URL=unix:/var/run/redis/redis.sock RAILS_ENV=production

# By default, the gitlab-shell config is generated from your main GitLab config.
# You can review (and modify) the gitlab-shell config as follows:
sudo -u git -H editor /home/git/gitlab-shell/config.yml

Install gitlab-workhorse

cd /home/git
sudo -u git -H git clone
cd gitlab-workhorse
sudo -u git -H git checkout 0.5.1
sudo -u git -H make

Initialize Database and Activate Advanced Features

# Go to GitLab installation folder
cd /home/git/gitlab
sudo -u git -H bundle exec rake gitlab:setup RAILS_ENV=production

# Type 'yes' to create the database tables.
# When done you see 'Administrator account created:'
sudo -u git -H bundle exec rake gitlab:setup RAILS_ENV=production GITLAB_ROOT_PASSWORD=yourpassword

Install Init Script

Download the init script (will be /etc/init.d/gitlab):

sudo cp lib/support/init.d/gitlab /etc/init.d/gitlab

And if you are installing with a non-default folder or user copy and edit the defaults file:

sudo cp lib/support/init.d/gitlab.default.example /etc/default/gitlab

If you installed GitLab in another directory or as a user other than the default you should change these settings in /etc/default/gitlab. Do not edit /etc/init.d/gitlab as it will be changed on upgrade.

Make GitLab start on boot:

sudo update-rc.d gitlab defaults 21

Setup Logrotate

sudo cp lib/support/logrotate/gitlab /etc/logrotate.d/gitlab

Check Application Status

Check if GitLab and its environment are configured correctly:

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

Compile Assets

sudo -u git -H bundle exec rake assets:precompile RAILS_ENV=production

Start Your GitLab Instance

sudo service gitlab start
# or
sudo /etc/init.d/gitlab restart

8. Nginx

Note: Nginx is the officially supported web server for GitLab.

sudo apt-get install -y nginx

Site Configuration

Copy the example site config:

sudo cp lib/support/nginx/gitlab /etc/nginx/sites-available/gitlab
sudo ln -s /etc/nginx/sites-available/gitlab /etc/nginx/sites-enabled/gitlab

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

# Change YOUR_SERVER_FQDN to the fully-qualified
# domain name of your host serving GitLab.
# If using Ubuntu default nginx install:
# either remove the default_server from the listen line
# or else sudo rm -f /etc/nginx/sites-enabled/default
sudo editor /etc/nginx/sites-available/gitlab

sudo nginx -t

You should receive syntax is okay and test is successful messages.
sudo service nginx restart

Double-check Application Status

To make sure you didn't miss anything run a more thorough check with:

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

If all items are green, then congratulations on successfully installing GitLab!

Initial Login

Visit YOUR_SERVER in your web browser for your first GitLab login. The setup has created a default admin account for you. You can use it to log in:


Important Note: On login you'll be prompted to change the password.

No comments:

Post a Comment