Omnibus GitLab

This project creates full-stack platform-specific downloadable packages for GitLab. For other installation options please see the GitLab installation page.

Canonical source

The source of omnibus-gitlab is hosted on GitLab.com and there are mirrors to make contributing as easy as possible.

Documentation version

Please make sure you are viewing the documentation for the version of omnibus-gitlab you are using. In most cases this should be the highest numbered stable branch (example shown below).

documentation version

Installation

Please follow the steps on the downloads page.

After installation

Run sudo gitlab-ctl status; the output should look like this:

run: nginx: (pid 972) 7s; run: log: (pid 971) 7s
run: postgresql: (pid 962) 7s; run: log: (pid 959) 7s
run: redis: (pid 964) 7s; run: log: (pid 963) 7s
run: sidekiq: (pid 967) 7s; run: log: (pid 966) 7s
run: unicorn: (pid 961) 7s; run: log: (pid 960) 7s

If any of the processes is not behaving like expected, try tailing their logs to see what is wrong.

sudo gitlab-ctl tail postgresql

Your GitLab instance should reachable over HTTP at the IP or hostname of your server. You can login as an admin user with username root and password 5iveL!fe.

Common installation problems

GitLab is unreachable in my browser

Try specifying an external_url in /etc/gitlab/gitlab.rb. Also check your firewall settings; port 80 (HTTP) or 443 (HTTPS) might be closed on your GitLab server.

Emails are not being delivered

To test email delivery you can create a new GitLab account for an email that is not used in your GitLab instance yet.

If necessary, you can modify the 'From' field of the emails sent by GitLab with the following setting in /etc/gitlab/gitlab.rb:

gitlab_rails['gitlab_email_from'] = 'gitlab@example.com'

Run sudo gitlab-ctl reconfigure for the change to take effect.

Reconfigure freezes at ruby_block[supervise_redis_sleep] action run

During the first gitlab-ctl reconfigure run, omnibus-gitlab needs to figure out if your Linux server is using SysV Init, Upstart or Systemd so that it can install and activate the gitlab-runsvdir service. If gitlab-ctl reconfigure makes the wrong decision, it will later hang atruby_block[supervise_redis_sleep] action run.

The choice of init system is currently made in the embedded Runit cookbook by essentially looking at the output of uname -a, /etc/issue and others. This mechanism can make the wrong decision in situations such as:

  • your OS release looks like 'Debian 7' but it is really some variant which uses Upstart instead of SysV Init;
  • your OS release is unknown to the Runit cookbook (e.g. ClearOS 6.5).

Solving problems like this would require changes to the embedded Runit cookbook; Merge Requests are welcome. Until this problem is fixed, you can work around it by manually performing the appropriate installation steps for your particular init system. For instance, to manually set up gitlab-runsvdir with Upstart, you can do the following:

sudo cp /opt/gitlab/embedded/cookbooks/runit/files/default/gitlab-runsvdir.conf /etc/init/
sudo initctl start gitlab-runsvdir
sudo gitlab-ctl reconfigure # Resume gitlab-ctl reconfigure

TCP ports for GitLab services are already taken

By default, Unicorn listens at TCP address 127.0.0.1:8080. Nginx listens on port 80 (HTTP) and/or 443 (HTTPS) on all interfaces.

The ports for Redis, PostgreSQL and Unicorn can be overriden in /etc/gitlab/gitlab.rb as follows:

redis['port'] = 1234
postgresql['port'] = 2345
unicorn['port'] = 3456

For Nginx port changes please see the section on enabling HTTPS below.

Git SSH access stops working on SELinux-enabled systems

On SELinux-enabled systems the git user's .ssh directory or its contents can get their security context messed up. You can fix this by runningsudo gitlab-ctl reconfigure, which will run a chcon --recursive command on /var/opt/gitlab/.ssh.

Postgres error 'FATAL: could not create shared memory segment: Cannot allocate memory'

The bundled Postgres instance will try to allocate 25% of total memory as shared memory. On some Linux (virtual) servers, there is less shared memory available, which will prevent Postgres from starting. In /var/log/gitlab/postgresql/current:

  1885  2014-08-08_16:28:43.71000 FATAL:  could not create shared memory segment: Cannot allocate memory
  1886  2014-08-08_16:28:43.71002 DETAIL:  Failed system call was shmget(key=5432001, size=1126563840, 03600).
  1887  2014-08-08_16:28:43.71003 HINT:  This error usually means that PostgreSQL's request for a shared memory segment exceeded available memory or swap space, or exceeded your kernel's SHMALL parameter.  You can either reduce the request size or reconfigure the kernel with larger SHMALL.  To reduce the request size (currently 1126563840 bytes), reduce PostgreSQL's shared memory usage, perhaps by reducing shared_buffers or max_connections.
  1888  2014-08-08_16:28:43.71004       The PostgreSQL documentation contains more information about shared memory configuration.

You can manually lower the amount of shared memory Postgres tries to allocate in /etc/gitlab/gitlab.rb:

postgresql['shared_buffers'] = "100MB"

Run sudo gitlab-ctl reconfigure for the change to take effect.

Reconfigure complains about the GLIBC version

$ gitlab-ctl reconfigure
/opt/gitlab/embedded/bin/ruby: /lib64/libc.so.6: version `GLIBC_2.14' not found (required by /opt/gitlab/embedded/lib/libruby.so.2.1)
/opt/gitlab/embedded/bin/ruby: /lib64/libc.so.6: version `GLIBC_2.17' not found (required by /opt/gitlab/embedded/lib/libruby.so.2.1)

This can happen if the omnibus package you installed was built for a different OS release than the one on your server. Double-check that you downloaded and installed the correct omnibus-gitlab package for your operating system.

Reconfigure fails to create the git user

This can happen if you run sudo gitlab-ctl reconfigure as the git user. Switch to another user.

More importantly: do not give sudo rights to the git user or to any of the other users used by omnibus-gitlab. Bestowing unnecessary privileges on a system user weakens the security of your system.

Uninstalling omnibus-gitlab

To uninstall omnibus-gitlab, preserving your data (repositories, database, configuration), run the following commands.

# Stop gitlab and remove its supervision process
sudo gitlab-ctl uninstall

# Debian/Ubuntu
sudo dpkg -r gitlab

# Redhat/Centos
sudo rpm -e gitlab

Updating

Instructions for updating your Omnibus installation and upgrading from a manual installation are in the update doc.

Starting and stopping

After omnibus-gitlab is installed and configured, your server will have a Runit service directory (runsvdir) process running that gets started at boot via /etc/inittab or the /etc/init/gitlab-runsvdir.conf Upstart resource. You should not have to deal with the runsvdir process directly; you can use the gitlab-ctl front-end instead.

You can start, stop or restart GitLab and all of its components with the following commands.

# Start all GitLab components
sudo gitlab-ctl start

# Stop all GitLab components
sudo gitlab-ctl stop

# Restart all GitLab components
sudo gitlab-ctl restart

Note that on a single-core server it may take up to a minute to restart Unicorn and Sidekiq. Your GitLab instance will give a 502 error until Unicorn is up again.

It is also possible to start, stop or restart individual components.

sudo gitlab-ctl restart sidekiq

Unicorn supports zero-downtime reloads. These can be triggered as follows:

sudo gitlab-ctl hup unicorn

Note that you cannot use a Unicorn reload to update the Ruby runtime.

Configuration

Backup and restore omnibus-gitlab configuration

All configuration for omnibus-gitlab is stored in /etc/gitlab. To backup your configuration, just backup this directory.

# Example backup command for /etc/gitlab:
# Create a time-stamped .tar file in the current directory.
# The .tar file will be readable only to root.
sudo sh -c 'umask 0077; tar -cf $(date "+etc-gitlab-%s.tar") -C / etc/gitlab'

You can extract the .tar file as follows.

# Rename the existing /etc/gitlab, if any
sudo mv /etc/gitlab /etc/gitlab.$(date +%s)
# Change the example timestamp below for your configuration backup
sudo tar -xf etc-gitlab-1399948539.tar -C /

Remember to run sudo gitlab-ctl reconfigure after restoring a configuration backup.

Configuring the external URL for GitLab

In order for GitLab to display correct repository clone links to your users it needs to know the URL under which it is reached by your users, e.g.http://gitlab.example.com. Add or edit the following line in /etc/gitlab/gitlab.rb:

external_url "http://gitlab.example.com"

Run sudo gitlab-ctl reconfigure for the change to take effect.

Storing Git data in an alternative directory

By default, omnibus-gitlab stores Git repository data under /var/opt/gitlab/git-data: repositories are stored in /var/opt/gitlab/git-data/repositories, and satellites in /var/opt/gitlab/git-data/gitlab-satellites. You can change the location of the git-data parent directory by adding the following line to/etc/gitlab/gitlab.rb.

git_data_dir "/mnt/nas/git-data"

Run sudo gitlab-ctl reconfigure for the change to take effect.

If you already have existing Git repositories in /var/opt/gitlab/git-data you can move them to the new location as follows:

# Prevent users from writing to the repositories while you move them.
sudo gitlab-ctl stop

# Only move 'repositories'; 'gitlab-satellites' will be recreated
# automatically. Note there is _no_ slash behind 'repositories', but there _is_ a
# slash behind 'git-data'.
sudo rsync -av /var/opt/gitlab/git-data/repositories /mnt/nas/git-data/

# Fix permissions if necessary
sudo gitlab-ctl reconfigure

# Double-check directory layout in /mnt/nas/git-data. Expected output:
# gitlab-satellites  repositories
sudo ls /mnt/nas/git-data/

# Done! Start GitLab and verify that you can browse through the repositories in
# the web interface.
sudo gitlab-ctl start

Changing the name of the Git user / group

By default, omnibus-gitlab uses the user name git for Git gitlab-shell login, ownership of the Git data itself, and SSH URL generation on the web interface. Similarly, gitgroup is used for group ownership of the Git data. You can change the user and group by adding the following lines to /etc/gitlab/gitlab.rb.

user['username'] = "gitlab"
user['group'] = "gitlab"

Run sudo gitlab-ctl reconfigure for the change to take effect.

Setting up LDAP sign-in

If you have an LDAP directory service such as Active Directory, you can configure GitLab so that your users can sign in with their LDAP credentials. Add the following to/etc/gitlab/gitlab.rb, edited for your server.

For GitLab Community Edition:

# These settings are documented in more detail at
# https://gitlab.com/gitlab-org/gitlab-ce/blob/a0a826ebdcb783c660dd40d8cb217db28a9d4998/config/gitlab.yml.example#L136
gitlab_rails['ldap_enabled'] = true
gitlab_rails['ldap_servers'] = [
  {
    "main" => {
      "label" => "LDAP",
      "host" => "hostname of LDAP server",
      "port" => 389,
      "uid" => "sAMAccountName",
      "method" => "plain", # 'ssl' or 'plain'
      "bind_dn" => "CN=query user,CN=Users,DC=mycorp,DC=com",
      "password" => "query user password",
      "active_directory" => true,
      "allow_username_or_email_login" => true,
      "base" => "DC=mycorp,DC=com",
      "user_filter" => ""
    }
  }
]

If you are installing GitLab Enterprise edition package you can use multiple LDAP servers:

gitlab_rails['ldap_enabled'] = true
gitlab_rails['ldap_servers'] = [
  {
    "main" => {
      "label" => "LDAP",
      "host" => "hostname of LDAP server",
      "port" => 389,
      "uid" => "sAMAccountName",
      "method" => "plain", # 'ssl' or 'plain'
      "bind_dn" => "CN=query user,CN=Users,DC=mycorp,DC=com",
      "password" => "query user password",
      "active_directory" => true,
      "allow_username_or_email_login" => true,
      "base" => "DC=mycorp,DC=com",
      "group_base" => "OU=groups,DC=mycorp,DC=com",
      "admin_group" => "",
      "sync_ssh_keys" => false,
      "sync_time" => 3600
    }
  },
  {
    "secondary" => {
      "label" => "LDAP 2",
      "host" => "hostname of LDAP server 2",
      "port" => 389,
      "uid" => "sAMAccountName",
      "method" => "plain", # 'ssl' or 'plain'
      "bind_dn" => "CN=query user,CN=Users,DC=mycorp,DC=com",
      "password" => "query user password",
      "active_directory" => true,
      "allow_username_or_email_login" => true,
      "base" => "DC=mycorp,DC=com",
      "group_base" => "OU=groups,DC=mycorp,DC=com",
      "sync_ssh_keys" => false
    }
  }
]

Run sudo gitlab-ctl reconfigure for the LDAP settings to take effect.

Note: If you are using pre GitLab 7.4 configuration syntax like described in the old version README LDAP section be advised that it is deprecated.

Enable HTTPS

By default, omnibus-gitlab does not use HTTPS. If you want to enable HTTPS for gitlab.example.com, add the following statement to /etc/gitlab/gitlab.rb:

external_url "https://gitlab.example.com"

Because the hostname in our example is 'gitlab.example.com', omnibus-gitlab will look for key and certificate files called /etc/gitlab/ssl/gitlab.example.com.keyand /etc/gitlab/ssl/gitlab.example.com.crt, respectively. Create the /etc/gitlab/ssl directory and copy your key and certificate there.

sudo mkdir -p /etc/gitlab/ssl
sudo chmod 700 /etc/gitlab/ssl
sudo cp gitlab.example.com.key gitlab.example.com.crt /etc/gitlab/ssl/

Now run sudo gitlab-ctl reconfigure. When the reconfigure finishes your GitLab instance should be reachable at http://gitlab.example.com.

If you are using a firewall you may have to open port 443 to allow inbound HTTPS traffic.

# UFW example (Debian, Ubuntu)
sudo ufw allow https

# lokkit example (RedHat, CentOS 6)
sudo lokkit -s https

# firewall-cmd (RedHat, Centos 7)
sudo firewall-cmd --permanent --add-service=https
sudo systemctl reload firewalld

Redirect HTTP requests to HTTPS.

By default, when you specify an external_url starting with 'https', Nginx will no longer listen for unencrypted HTTP traffic on port 80. If you want to redirect all HTTP traffic to HTTPS you can use the redirect_http_to_https setting.

external_url "https://gitlab.example.com"
nginx['redirect_http_to_https'] = true

Change the default port and the ssl certificate locations.

If you need to use an HTTPS port other than the default (443), just specify it as part of the external_url.

external_url "https://gitlab.example.com:2443"

Run sudo gitlab-ctl reconfigure for the change to take effect.

Use non-bundled web-server

By default, omnibus-gitlab installs GitLab with bundled Nginx. Omnibus-gitlab allows webserver access through user gitlab-www which resides in the group with the same name. To allow an external webserver access to GitLab, external webserver user needs to be added gitlab-www group.

To use another web server like Apache or an existing Nginx installation you will have to do the following steps:

  • Disable bundled Nginx by specifying in /etc/gitlab/gitlab.rb:
nginx['enable'] = false
  • Check the username of the non-bundled web-server user. By default, omnibus-gitlab has no default setting for external webserver user. You have to specify the external webserver user username in the configuration! Let's say for example that webserver user is www-data. In /etc/gitlab/gitlab.rb set:
web_server['external_users'] = ['www-data']

This setting is an array so you can specify more than one user to be added to gitlab-www group.

Run sudo gitlab-ctl reconfigure for the change to take effect.

Note: if you are using SELinux and your web server runs under a restricted SELinux profile you may have to loosen the restrictions on your web server.

Adding ENV Vars to the Gitlab Runtime Environment

If you need Gitlab to have access to certain environment variables, you can configure them in /etc/gitlab/gitlab.rb. This is useful in situations where you need to use a proxy to access the internet and you will be wanting to clone externally hosted repositories directly into gitlab. In /etc/gitlab/gitlab.rb supply agitlab_rails['env'] with a hash value. For example:

gitlab_rails['env'] = {"http_proxy" => "my_proxy", "https_proxy" => "my_proxy"}

Run sudo gitlab-ctl reconfigure for the change to take effect.

Changing gitlab.yml settings

Some of GitLab's features can be customized through gitlab.yml. If you want to change a gitlab.yml setting with omnibus-gitlab, you need to do so via/etc/gitlab/gitlab.rb. The translation works as follows.

In gitlab.yml, you will find structure like this:

production: &base
  gitlab:
    default_projects_limit: 10

In gitlab.rb, this translates to:

gitlab_rails['gitlab_default_projects_limit'] = 10

What happens here is that we forget about production: &base, and join gitlab: with default_projects_limit: into gitlab_default_projects_limit. Note that not all gitlab.yml settings can be changed via gitlab.rb yet; see the gitlab.yml ERB template. If you think an attribute is missing please create a merge request on the omnibus-gitlab repository.

Run sudo gitlab-ctl reconfigure for changes in gitlab.rb to take effect.

Do not edit the generated file in /var/opt/gitlab/gitlab-rails/etc/gitlab.yml since it will be overwritten on the next gitlab-ctl reconfigure run.

Specify numeric user and group identifiers

Omnibus-gitlab creates users for GitLab, PostgreSQL, Redis and NGINX. You can specify the numeric identifiers for these users in /etc/gitlab/gitlab.rb as follows.

user['uid'] = 1234
user['gid'] = 1234
postgresql['uid'] = 1235
postgresql['gid'] = 1235
redis['uid'] = 1236
redis['gid'] = 1236
web_server['uid'] = 1237
web_server['gid'] = 1237

Storing user attachments on Amazon S3

By default, attachments are stored in /var/opt/gitlab/gitlab-rails/uploads. Instead of using local storage you can also store the user attachments for your GitLab instance on Amazon S3.

This currently only works if you are packaging a forked version of GitLab.

# /etc/gitlab/gitlab.rb
gitlab_rails['aws_enable'] = true
gitlab_rails['aws_access_key_id'] = 'AKIA1111111111111UA'
gitlab_rails['aws_secret_access_key'] = 'secret'
gitlab_rails['aws_bucket'] = 'my_gitlab_bucket'
gitlab_rails['aws_region'] = 'us-east-1'

Sending application email via SMTP

If you would rather send email via an SMTP server instead of via Sendmail, add the following configuration information to /etc/gitlab/gitlab.rb and rungitlab-ctl reconfigure.

gitlab_rails['smtp_enable'] = true
gitlab_rails['smtp_address'] = "smtp.server"
gitlab_rails['smtp_port'] = 456
gitlab_rails['smtp_user_name'] = "smtp user"
gitlab_rails['smtp_password'] = "smtp password"
gitlab_rails['smtp_domain'] = "example.com"
gitlab_rails['smtp_authentication'] = "login"
gitlab_rails['smtp_enable_starttls_auto'] = true

# If your SMTP server does not like the default 'From: gitlab@localhost' you
# can change the 'From' with this setting.
gitlab_rails['gitlab_email_from'] = 'gitlab@example.com'

Omniauth (Google, Twitter, GitHub login)

Omniauth configuration is documented on doc.gitlab.com. To effect the necessary changes in gitlab.yml, use the following syntax in /etc/gitlab/gitlab.rb. Note that the providers are specified as an array of Ruby hashes.

gitlab_rails['omniauth_enabled'] = true
gitlab_rails['omniauth_providers'] = [
  {
    "name" => "google_oauth2",
    "app_id" => "YOUR APP ID",
    "app_secret" => "YOUR APP SECRET",
    "args" => { "access_type" => "offline", "approval_prompt" => "" }
  }
]

Adjusting Unicorn settings

If you need to adjust the Unicorn timeout or the number of workers you can use the following settings in

喜欢这篇文章?

点击后弹出微信二维码,可自选金额或输入其他金额