Wednesday, July 30, 2014

Gitlab Server Installation on Centos 6.4 x88_64

Gitlab Installation

This blog is to document the steps install Gitlab on a Centos 6.4 x88_64 Server. It will discuss some of the issues we encountered and provide some puppet code to automated the build. We used this wiki as a reference for the installation https://gitlab.com/gitlab-org/omnibus-gitlab/blob/master/README.md.

Overview
Gitlab using several subsystems
  • Postgres database
  • nginx
  • unicorn
  • ruby / rails
  • redis
  • sidekiq
We opted to install postgres 9.3 instead of the default provided in the rpm. Postgres will be running as a local database account gitlab.
Gitlab will run as local user Centos account git.

Setup

Install and Configure Postgres

Reference for this postgres installation : http://tecadmin.net/install-postgresql-on-centos-rhel-and-fedora/

Install postgres yum repo

rpm -Uhv http://yum.postgresql.org/9.3/redhat/rhel-6-x86_64/pgdg-redhat93-9.3-1.noarch.rpm
 
There was an issue with postgres requiring a new version of openss 10 so we installed a 6.5 package instead. Note this openssl is from updates repo which includes the fix for heartbleed vulnerability.

rpm -Uhv http://mirror.centos.org/centos/6/updates/x86_64/Packages/openssl-1.0.1e-16.el6_5.14.x86_64.rpm 
yum -y install postgresql93-server-9.3.4-1PGDG.rhel6.x86_64 postgresql93-9.3.4-1PGDG.rhel6.x86_64 postgresql93-libs-9.3.4-1PGDG.rhel6.x86_64
 
Edit pg_hba.conf
vi /var/lib/pgsql/9.3/data/pg_hba.conf
#local   all        all                                         peer
local   all         postgres                                    trust
local   all         all                                         trust
 
Initial database and start postgres daemon
service postgresql-9.3 initdb 
service postgresql-9.3 start
 
For some reason the gitlab configuration script is missing some instructions so we pre-config the db. Note postgres has no password to log in locally.

sudo -u postgres psql
CREATE DATABASE gitlab_production;
\c gitlab_production
CREATE USER gitlab WITH PASSWORD 'my_git_passwd1';
GRANT ALL PRIVILEGES ON DATABASE gitlab_production to gitlab;
\list
\q
 
Check gitlab database login
psql -U gitlab -W -d gitlab_production 

Install and Configure Gitlab

The download instruction for Centos can be found here : https://about.gitlab.com/downloads/
Select Centos 6.

Download Gitlab
wget https://downloads-packages.s3.amazonaws.com/centos-6.5/gitlab-7.1.1_omnibus-1.el6.x86_64.rpm
yum install openssh-server
yum install postfix
rpm -i gitlab-7.1.1_omnibus-1.el6.x86_64.rpm
 
Configure gitlab


vi /etc/gitlab/gitlab.rb 
 
# Change the external_url to the address your users will type in their browser
git_data_dir "/home/git"

external_url 'http://[your_hostname]'

#custom postgres install
postgresql['enable'] = false

# Fill in the values for database.yml
gitlab_rails['db_adapter'] = 'postgresql'
gitlab_rails['db_encoding'] = 'utf8'
gitlab_rails['db_database'] = 'gitlab_production'
gitlab_rails['db_username'] = 'gitlab'
gitlab_rails['db_password'] = 'dsu-8cq-c5r-poz'
gitlab_rails['db_socket'] = '/tmp/.s.PGSQL.5432'
 
 
Since we where using our own postgres install we need to add addition entries by adding
postgresql['enable'] = false
 


Run gitlab reconfiguration
gitlab-ctl reconfigure 
gitlab-rake gitlab:setup  RAILS_ENV=production 
 
Login to gitlab
In a browser, type http://[your_hostname]
username : admin@local.host
passwd   : 5iveL!fe 
 
 

Debugging

Couldn't create database for {"adapter"=>"postgresql", "encoding"=>"UTF-8", "database"=>"gitlab_production", "pool"=>10, "username"=>"gitlab", "password"=>"dsu-8cq-c5r-poz", "host"=>"127.0.0.1", "port"=>5432, "socket"=>"/tmp/.s.PGSQL.5432"}
-- enable_extension("plpgsql")
rake aborted!
PG::Error: FATAL:  Ident authentication failed for user "gitlab" 

 We had to run numerous time to figure out what was going on.

  • vi /etc/gitlab/gitlab.rb
  • gitlab-ctl reconfigure
  • gitlab-rake gitlab:setup  RAILS_ENV=production

 
Instead we run the following before editing the final gitlab.rb
  • vi /var/opt/gitlab/gitlab-rails/etc/database.yml
  • gitlab:setup  RAILS_ENV=production
     
    
    
  

Bonus Puppet code


Git Node definition

/etc/puppet/manifest/git.pp
node /[your_git_server]/
{
    class
    {
        "postgres":
            version => "9.3",
    }

    class
    {
        "gitlab":
            version => "7.0.0",
            require => Class["postgres"],
    } 
 

Postgres module

/etc/puppet/modules/postgres/manifests/init.pp
class postgres ( $version = "9.3" )
{

    case $version {

        "9.3"     : { $package_version = "93" }

        default   : { $package_version = "93" }
    }

    package
    {
        [ "postgresql${package_version}-server", "postgresql${package_version}" , "postgresql${package_version}-libs" ]:
            ensure => latest,
            require => Package["pgdg-redhat93-9.3-1"];
         
        "pgdg-redhat93-9.3-1":
            ensure => latest, 
 
         #Add this to a local repo : http://yum.postgresql.org/9.3/redhat/rhel-6-x86_64/pgdg-redhat93-9.3-1.noarch.rpm 
         #TODO centos 6.4 requires openssl-1.0.1e-16.el6_5.14.x86_64.rpm for centos 6.5 
    }


    service
    {
         "postgresql-${version}":
             ensure  => "running",
             enable  => "true",
             require => [Package["postgresql${package_version}-server"], Exec["init_postgres"]],

    }

    exec
    {
        "init_postgres":
            command => "service postgresql-${version} initdb",
            path    => "/usr/local/bin/:/bin/:/usr/bin/:/usr/sbin/:/sbin",
            onlyif => "ls /var/lib/pgsql/${version}/data",
            require => Package["postgresql${package_version}-server"],

    }

}
 



Gitlab Module

 
/etc/puppet/modules/gitlab/manifests/init.pp
class gitlab( $version = '7.0.0' )
{


    class
    {
        "gitlab::user":
    }

    file
    {
        "/home/git":
            ensure => directory,
            require => Class["gitlab::user"];


        "/etc/gitlab/gitlab.rb":
            ensure => "present",
            owner  => $::git,
            group  => $::git,
            mode    => 0655,
            notify => Service["gitlab-ctl"],
            content => template("gitlab/gitlab.rb.erb"),
            require => Package["gitlab-${version}_omnibus"];

    }

    package
    {
         "git":
             ensure => latest,
             require => Class["gitlab::user"];

         "gitlab-7.0.0_omnibus":
             ensure => latest,
             require => Package["git"];

    }

    service
    {
        "gitlab-ctl":
            ensure  => "running",
            hasrestart => true,
            restart => "/usr/bin/gitlab-ctl reconfigure && chsh  -s /bin/bash ${::git_user}",
            hasstatus => true,
            status => "/usr/bin/gitlab-ctl status",
            start =>  "/usr/bin/gitlab-ctl start",
            stop =>  "/usr/bin/gitlab-ctl stop",
            require => File["/etc/gitlab/gitlab.rb"],
    }
}


class gitlab::user
{
    # base::generic_user is a custom "define" create user. There are many definitions to create users. We made it into a class so we can "require" it
    # git user account information was define on the top level scope e.g. = $::git
 
    base::generic_user 
    {
        "${git_user}":
            user => "$git_user",
            uid => "${git_user_uid}",
            base_home => "/var/opt",
            home_name => "gitlab",
            password => "${git_user_pass}",
            comment => "${git_user_comment}",
            bash_profile_path => "/opt/gitlab:/opt/gitlab/bin:/opt/gitlab/embedded/bin:/usr/sbin:/sbin:/apps/bin:\$PATH",
            bash_rubylib => "/opt/gitlab/embedded/lib"
    }
}
 


/etc/puppet/modules/gitlab/templates/gitlab.rb.erb
# Autconfigured by Puppet. Do not edit


# Change the external_url to the address your users will type in their browser
git_data_dir "/home/git"

external_url 'http://<%=fqdn%>'

#need to install postgres
postgresql['enable'] = false

# Fill in the values for database.yml
gitlab_rails['db_adapter'] = 'postgresql'
gitlab_rails['db_encoding'] = 'utf8'
gitlab_rails['db_database'] = 'gitlab_production'
gitlab_rails['db_username'] = 'gitlab'
gitlab_rails['db_password'] = 'your_git_user_dbpasswd'
gitlab_rails['db_socket'] = '/tmp/.s.PGSQL.5432'