Installation from source

Installation from source

这是使用源文件设置生产 GitLab 服务器的官方安装指南. 要设置开发安装或许多其他安装选项,请参见 . 它是为Debian / Ubuntu操作系统创建并经过测试的. 有关硬件和操作系统要求 ,请阅读 requirements.md. 如果要在 RHEL / CentOS 上安装,我们建议使用 .

本指南之所以冗长,是因为它涵盖了许多情况,并且包括您需要的所有命令,这是实际上可以立即使用的少数安装脚本之一 . 已知以下步骤有效. 偏离本指南时请多加注意 . 确保您没有违反任何有关 GitLab 对其环境的假设. 例如,许多人遇到权限问题,因为他们更改了目录的位置或以错误的用户身份运行服务.

如果您在本指南中发现错误/错误, 按照 提交合并请求 .

由于从源头进行安装需要大量工作并且容易出错,因此我们强烈建议您快速,可靠地安装 Omnibus 软件包 (deb / rpm).

Omnibus 软件包更可靠的原因之一是它使用 runit 来重新启动任何 GitLab 进程,以防万一崩溃. 在频繁使用的 GitLab 实例上,Sidekiq 后台工作程序的内存使用量会随着时间增长.

Omnibus 软件包通过在使用过多内存的情况下正常终止来解决此问题. 在此终止后,runit 将检测到 Sidekiq 没有运行并启动它. 由于从源头进行的安装不使用 runit 进行过程监视,因此 Sidekiq 无法终止,并且其内存使用量会随着时间的推移而增长.

Select a version to install

确保从您要安装的 GitLab 的分支(版本)中查看此安装指南 (例如11-7-stable ). 您可以在 GitLab 左上角的版本下拉菜单中选择分支(位于菜单栏下方).

如果不清楚最高数目的稳定分支,请查看以获取版本信息.

GitLab directory structure

这是主要的目录结构,您将按照此页面的说明进行操作:

  • /home/git/.ssh包含 OpenSSH 设置. 具体来说,由 GitLab Shell 管理的authorized_keys文件.
  • /home/git/gitlab -GitLab 核心软件.
  • /home/git/gitlab-shell -GitLab 的核心附加组件. 维护 SSH 克隆和其他功能.
  • /home/git/repositories按名称空间组织的所有项目的裸存储库. 这是为所有项目维护推/拉的 Git 存储库的地方. 该区域包含项目的关键数据. .

注意:可以在 GitLab 的config/gitlab.yml和 GitLab Shell 的config.ymlconfig/gitlab.yml存储库的默认位置.

有关更深入的概述,请参阅GitLab 体系结构文档 .

Overview

GitLab 安装包括设置以下组件:

  1. Packages and dependencies.
  2. .
  3. Go.
  4. .
  5. System users.
  6. .
  7. Redis.
  8. .
  9. NGINX.

1. Packages and dependencies

默认情况下,Debian 上未安装sudo . 确保您的系统是最新的并安装.

  1. # run as root!
  2. apt-get update -y
  3. apt-get upgrade -y
  4. apt-get install sudo -y

注意:在此安装过程中,将需要手动编辑某些文件. 如果您熟悉 vim,请使用以下命令将其设置为默认编辑器. 如果您不熟悉 vim,请跳过此步骤并继续使用默认编辑器.

  1. # Install vim and set as default editor
  2. sudo apt-get install -y vim
  3. sudo update-alternatives --set editor /usr/bin/vim.basic

安装所需的软件包(需要编译 Ruby 和 Ruby gem 的本机扩展):

  1. sudo apt-get install -y build-essential zlib1g-dev libyaml-dev libssl-dev libgdbm-dev libre2-dev \
  2. libreadline-dev libncurses5-dev libffi-dev curl openssh-server checkinstall libxml2-dev \
  3. libxslt-dev libcurl4-openssl-dev libicu-dev logrotate rsync python-docutils pkg-config cmake \
  4. runit

Ubuntu 14.04(Trusty libre2-dev )没有可用的libre2-dev软件包,但您可以手动安装 re2 .

如果要使用 Kerberos 进行用户身份验证,请安装libkrb5-dev

  1. sudo apt-get install libkrb5-dev

注意:如果您不知道 Kerberos 是什么,则可以假定您不需要它.

确保您安装了正确的 Git 版本:

  1. # Install Git
  2. sudo apt-get install -y git-core
  3. # Make sure Git is version 2.27.0 or higher (minimal supported version is 2.25.0)
  4. git --version

从 GitLab 12.0 开始,需要使用libpcre2编译 Git. 找出是否是这种情况:

  1. ldd $(command -v git) | grep pcre2

输出应包含libpcre2-8.so.0 .

系统打包的 Git 是否过旧,或者未使用 pcre2 编译? 去掉它:

  1. sudo apt-get remove git-core

在 Ubuntu 上, 安装 Git:

  1. # run as root!
  2. add-apt-repository ppa:git-core/ppa
  3. apt update
  4. apt install git
  5. # repeat libpcre2 check as above

在 Debian 上,使用以下编译说明:

  1. # Install dependencies
  2. sudo apt-get install -y libcurl4-openssl-dev libexpat1-dev gettext libz-dev libssl-dev build-essential
  3. # Download and compile pcre2 from source
  4. curl --silent --show-error --location https://ftp.pcre.org/pub/pcre/pcre2-10.33.tar.gz --output pcre2.tar.gz
  5. tar -xzf pcre2.tar.gz
  6. cd pcre2-10.33
  7. chmod +x configure
  8. ./configure --prefix=/usr --enable-jit
  9. make
  10. # Download and compile from source
  11. cd /tmp
  12. curl --remote-name --location --progress https://www.kernel.org/pub/software/scm/git/git-2.27.0.tar.gz
  13. echo '77ded85cbe42b1ffdc2578b460a1ef5d23bcbc6683eabcafbb0d394dffe2e787 git-2.27.0.tar.gz' | shasum -a256 -c - && tar -xzf git-2.27.0.tar.gz
  14. cd git-2.27.0/
  15. ./configure --with-libpcre
  16. make prefix=/usr/local all
  17. # Install into /usr/local/bin
  18. sudo make prefix=/usr/local install
  19. # When editing config/gitlab.yml later, change the git -> bin_path to /usr/local/bin/git

为了使自定义图标能够正常工作,需要安装 GraphicsMagick.

  1. sudo apt-get install -y graphicsmagick

注意:为了接收邮件通知,请确保安装邮件服务器. 默认情况下,Debian 随 exim4 一起提供,但这而 Ubuntu 则没有. 推荐的邮件服务器是 postfix,您可以使用以下命令进行安装:

  1. sudo apt-get install -y postfix

然后选择” Internet Site”,然后按 Enter 确认主机名.

GitLab Workhorse需要使用exiftool才能从上传的图像中删除 EXIF 数据.

  1. sudo apt-get install -y libimage-exiftool-perl

运行 GitLab 需要使用 Ruby 解释器.

注意:当前支持的 Ruby(MRI)版本是 2.6.x. GitLab 12.2 放弃了对 Ruby 2.5.x 的支持.

在生产环境 Ruby 版本管理器(如RVM , 或chruby)与 GitLab 使用通常会导致难以诊断问题. 不支持版本管理器,我们强烈建议所有人按照以下说明使用系统 Ruby.

Linux 发行版通常提供较旧版本的 Ruby,因此这些说明旨在从官方源代码安装 Ruby.

删除旧的 Ruby 1.8(如果存在):

  1. sudo apt-get remove ruby1.8

下载 Ruby 并进行编译:

  1. mkdir /tmp/ruby && cd /tmp/ruby
  2. curl --remote-name --progress https://cache.ruby-lang.org/pub/ruby/2.6/ruby-2.6.6.tar.gz
  3. echo '2d78048e293817f38d4ede4ebc7873013e97bb0b ruby-2.6.6.tar.gz' | shasum -c - && tar xzf ruby-2.6.6.tar.gz
  4. cd ruby-2.6.6
  5. ./configure --disable-install-rdoc
  6. make
  7. sudo make install

然后安装 Bundler gem(低于 2.x 的版本):

  1. sudo gem install bundler --no-document --version '< 2'

3. Go

从 GitLab 8.0 开始,GitLab 有几个用 Go 编写的守护程序. 要安装 GitLab,我们需要一个 Go 编译器. 以下说明假定您使用 64 位 Linux. 您可以在找到其他平台的下载 .

  1. # Remove former Go installation folder
  2. sudo rm -rf /usr/local/go
  3. curl --remote-name --progress https://dl.google.com/go/go1.13.5.linux-amd64.tar.gz
  4. echo '512103d7ad296467814a6e3f635631bd35574cab3369a97a323c9a585ccaa569 go1.13.5.linux-amd64.tar.gz' | shasum -a256 -c - && \
  5. sudo tar -C /usr/local -xzf go1.13.5.linux-amd64.tar.gz
  6. sudo ln -sf /usr/local/go/bin/{go,godoc,gofmt} /usr/local/bin/
  7. rm go1.13.5.linux-amd64.tar.gz

4. Node

从 GitLab 8.17 开始,GitLab 需要使用 Node 来编译 JavaScript 资产,并使用 Yarn 来管理 JavaScript 依赖项. 当前的最低要求是:

  • node > = v10.13.0. (我们建议使用节点 12.x,因为它速度更快)
  • yarn > = v1.10.0.

在许多发行版中,官方软件包存储库提供的版本已经过时,因此我们需要通过以下命令进行安装:

  1. # install node v12.x
  2. curl --location https://deb.nodesource.com/setup_12.x | sudo bash -
  3. sudo apt-get install -y nodejs
  4. curl --silent --show-error https://dl.yarnpkg.com/debian/pubkey.gpg | sudo apt-key add -
  5. echo "deb https://dl.yarnpkg.com/debian/ stable main" | sudo tee /etc/apt/sources.list.d/yarn.list
  6. sudo apt-get update
  7. sudo apt-get install yarn

如果您对这些步骤有任何疑问,请访问node和的官方网站.

5. System users

为 GitLab 创建一个git用户:

  1. sudo adduser --disabled-login --gecos 'GitLab' git

6. Database

注意:从 GitLab 12.1 开始,仅支持 PostgreSQL. 从 GitLab 13.0 开始,我们需要 PostgreSQL 11+.

    1. sudo apt-get install -y postgresql postgresql-client libpq-dev postgresql-contrib
  1. 启动 PostgreSQL 服务并确认该服务正在运行:

    1. sudo service postgresql start
    2. sudo service postgresql status
  2. 为 GitLab 创建数据库用户:

    1. sudo -u postgres psql -d template1 -c "CREATE USER git CREATEDB;"
  3. 创建pg_trgm扩展(GitLab 8.6+必需):

    1. sudo -u postgres psql -d template1 -c "CREATE EXTENSION IF NOT EXISTS pg_trgm;"
  4. 创建 GitLab 生产数据库并授予该数据库的所有特权:

    1. sudo -u postgres psql -d template1 -c "CREATE DATABASE gitlabhq_production OWNER git;"
  5. 尝试使用新用户连接到新数据库:

  6. 检查是否启用了pg_trgm扩展名:

    1. SELECT true AS enabled
    2. FROM pg_available_extensions
    3. WHERE name = 'pg_trgm'
    4. AND installed_version IS NOT NULL;

    如果启用了扩展名,将产生以下输出:

    1. enabled
    2. ---------
    3. t
    4. (1 row)
  7. 退出数据库会话:

    1. gitlabhq_production> \q

GitLab 至少需要 Redis 5.0.

如果您使用的是 Debian 10 或 Ubuntu 20.04 及更高版本,则可以使用以下命令安装 Redis 5.0:

  1. sudo apt-get install redis-server

完成后,您可以配置 Redis:

  1. # Configure redis to use sockets
  2. sudo cp /etc/redis/redis.conf /etc/redis/redis.conf.orig
  3. # Disable Redis listening on TCP by setting 'port' to 0
  4. sudo sed 's/^port .*/port 0/' /etc/redis/redis.conf.orig | sudo tee /etc/redis/redis.conf
  5. # Enable Redis socket for default Debian / Ubuntu path
  6. echo 'unixsocket /var/run/redis/redis.sock' | sudo tee -a /etc/redis/redis.conf
  7. # Grant permission to the socket to all members of the redis group
  8. echo 'unixsocketperm 770' | sudo tee -a /etc/redis/redis.conf
  9. # Create the directory which contains the socket
  10. sudo mkdir -p /var/run/redis
  11. sudo chown redis:redis /var/run/redis
  12. sudo chmod 755 /var/run/redis
  13. # Persist the directory which contains the socket, if applicable
  14. if [ -d /etc/tmpfiles.d ]; then echo 'd /var/run/redis 0755 redis redis 10d -' | sudo tee -a /etc/tmpfiles.d/redis.conf
  15. fi
  16. # Activate the changes to redis.conf
  17. sudo service redis-server restart
  18. # Add git to the redis group
  19. sudo usermod -aG redis git

8. GitLab

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

克隆社区版:

  1. sudo -u git -H git clone https://gitlab.com/gitlab-org/gitlab-foss.git -b X-Y-stable gitlab

克隆企业版:

  1. # Clone GitLab repository
  2. sudo -u git -H git clone https://gitlab.com/gitlab-org/gitlab-ee.git -b X-Y-stable gitlab

确保用与要安装的版本匹配的稳定分支替换XY-stable . 例如,如果要安装 11.8,则可以使用分支名称11-8-stable .

注意:您可以更改XY-stable ,以master ,如果你想最前沿的版本,但从来没有安装master在生产服务器上!

Configure It

  1. # Go to GitLab installation folder
  2. cd /home/git/gitlab
  3. # Copy the example GitLab config
  4. sudo -u git -H cp config/gitlab.yml.example config/gitlab.yml
  5. # Update GitLab config file, follow the directions at top of the file
  6. sudo -u git -H editor config/gitlab.yml
  7. # Copy the example secrets file
  8. sudo -u git -H cp config/secrets.yml.example config/secrets.yml
  9. sudo -u git -H chmod 0600 config/secrets.yml
  10. # Make sure GitLab can write to the log/ and tmp/ directories
  11. sudo chown -R git log/
  12. sudo chown -R git tmp/
  13. sudo chmod -R u+rwX,go-w log/
  14. sudo chmod -R u+rwX tmp/
  15. # Make sure GitLab can write to the tmp/pids/ and tmp/sockets/ directories
  16. sudo chmod -R u+rwX tmp/pids/
  17. sudo chmod -R u+rwX tmp/sockets/
  18. # Create the public/uploads/ directory
  19. sudo -u git -H mkdir -p public/uploads/
  20. # Make sure only the GitLab user has access to the public/uploads/ directory
  21. # now that files in public/uploads are served by gitlab-workhorse
  22. sudo chmod 0700 public/uploads
  23. # Change the permissions of the directory where CI job logs are stored
  24. sudo chmod -R u+rwX builds/
  25. # Change the permissions of the directory where CI artifacts are stored
  26. sudo chmod -R u+rwX shared/artifacts/
  27. # Change the permissions of the directory where GitLab Pages are stored
  28. sudo chmod -R ug+rwX shared/pages/
  29. # Copy the example Puma config
  30. sudo -u git -H cp config/puma.rb.example config/puma.rb
  31. # Refer to https://github.com/puma/puma#configuration for more information.
  32. # You should scale Puma workers and threads based on the number of CPU
  33. # cores you have available. You can get that number via the `nproc` command.
  34. sudo -u git -H editor config/puma.rb
  35. # Copy the example Rack attack config
  36. sudo -u git -H cp config/initializers/rack_attack.rb.example config/initializers/rack_attack.rb
  37. # Configure Git global settings for git user
  38. # 'autocrlf' is needed for the web editor
  39. sudo -u git -H git config --global core.autocrlf input
  40. # Disable 'git gc --auto' because GitLab already runs 'git gc' when needed
  41. # Enable packfile bitmaps
  42. sudo -u git -H git config --global repack.writeBitmaps true
  43. # Enable push options
  44. sudo -u git -H git config --global receive.advertisePushOptions true
  45. # Enable fsyncObjectFiles to reduce risk of repository corruption if the server crashes
  46. sudo -u git -H git config --global core.fsyncObjectFiles true
  47. # Configure Redis connection settings
  48. sudo -u git -H cp config/resque.yml.example config/resque.yml
  49. # Change the Redis socket path if you are not using the default Debian / Ubuntu configuration
  50. sudo -u git -H editor config/resque.yml

注意:请确保同时编辑gitlab.ymlpuma.rb以匹配您的设置. 如果要使用 Unicorn Web 服务器,请参阅” 使用 Unicorn”以了解其他步骤.注意:如果要使用 HTTPS,请参阅” 以了解其他步骤.

Configure GitLab DB Settings

  1. sudo -u git cp config/database.yml.postgresql config/database.yml
  2. # Remove host, username, and password lines from config/database.yml.
  3. # Once modified, the `production` settings will be as follows:
  4. #
  5. # production:
  6. # adapter: postgresql
  7. # encoding: unicode
  8. # database: gitlabhq_production
  9. # pool: 10
  10. #
  11. sudo -u git -H editor config/database.yml
  12. # Remote PostgreSQL only:
  13. # Update username/password in config/database.yml.
  14. # You only need to adapt the production settings (first part).
  15. # If you followed the database guide then please do as follows:
  16. # Change 'secure password' with the value you have given to $password
  17. # You can keep the double quotes around the password
  18. sudo -u git -H editor config/database.yml
  19. # Make config/database.yml readable to git only
  20. sudo -u git -H chmod o-rwx config/database.yml

Install Gems

注意:从 Bundler 1.5.2 开始,您可以调用bundle install -jN (其中N是您的处理器内核数)并享受并行 gem 的安装,其完成时间有可衡量的差异(快 60%). 使用nproc检查您的内核数. 有关更多信息,请参见这篇文章 .

确保您有bundle (运行bundle -v ):

  • >= 1.5.2 ,因为某些已在 1.5.2 中修复 .
  • < 2.x.
  1. sudo -u git -H bundle install --deployment --without development test mysql aws kerberos

注意:如果要使用 Kerberos 进行用户身份验证,请在上面的--without选项中省略kerberos .

Install GitLab Shell

GitLab Shell 是专门为 GitLab 开发的 SSH 访问和存储库管理软件.

  1. # Run the installation task for gitlab-shell:
  2. sudo -u git -H bundle exec rake gitlab:shell:install RAILS_ENV=production
  3. # By default, the gitlab-shell config is generated from your main GitLab config.
  4. # You can review (and modify) the gitlab-shell config as follows:
  5. sudo -u git -H editor /home/git/gitlab-shell/config.yml

注意:如果要使用 HTTPS,请参阅” 使用 HTTPS”以了解其他步骤.注意:确保您的主机名可以通过正确的 DNS 记录或/etc/hosts的其他行(” 127.0.0.1 主机名”)在计算机上解析. 例如,如果您在反向代理后面设置了 GitLab,则可能有必要. 如果无法解析主机名,则最终安装检查将失败,并具有Check GitLab API access: FAILED. code: 401 Check GitLab API access: FAILED. code: 401和推送提交将通过[remote rejected] master -> master (hook declined) .

Install GitLab Workhorse

GitLab-Workhorse 使用GNU Make . 以下命令行将在建议的位置/home/git/gitlab-workhorse安装 GitLab-Workhorse.

  1. sudo -u git -H bundle exec rake "gitlab:workhorse:install[/home/git/gitlab-workhorse]" RAILS_ENV=production

您可以通过提供其他参数来指定其他 Git 存储库:

  1. sudo -u git -H bundle exec rake "gitlab:workhorse:install[/home/git/gitlab-workhorse,https://example.com/gitlab-workhorse.git]" RAILS_ENV=production

Install GitLab-Elasticsearch-indexer on Enterprise Edition

GitLab-Elasticsearch-Indexer 使用GNU Make . 以下命令行将在推荐位置/home/git/gitlab-elasticsearch-indexer中安装 GitLab-Elasticsearch-Indexer.

  1. sudo -u git -H bundle exec rake "gitlab:indexer:install[/home/git/gitlab-elasticsearch-indexer]" RAILS_ENV=production

您可以通过提供其他参数来指定其他 Git 存储库:

  1. sudo -u git -H bundle exec rake "gitlab:indexer:install[/home/git/gitlab-elasticsearch-indexer,https://example.com/gitlab-elasticsearch-indexer.git]" RAILS_ENV=production

首先将源代码提取到第一个参数指定的路径. 然后,将在其bin目录下构建一个二进制文件. 然后,您将需要更新gitlab.ymlproduction -> elasticsearch -> indexer_path设置以指向该二进制文件.

注意: Elasticsearch 是 GitLab 企业版的一项功能,不包含在 GitLab 社区版中.

Install GitLab Pages

GitLab Pages 使用GNU Make . 此步骤是可选的,仅当您希望在 GitLab 中托管静态站点时才需要. 以下命令将在/home/git/gitlab-pages安装 GitLab /home/git/gitlab-pages . 有关其他设置步骤,请查阅适用于您的 GitLab 版本的 ,因为 GitLab Pages 守护程序可以通过几种不同的方式运行.

  1. cd /home/git
  2. sudo -u git -H git clone https://gitlab.com/gitlab-org/gitlab-pages.git
  3. cd gitlab-pages
  4. sudo -u git -H git checkout v$(</home/git/gitlab/GITLAB_PAGES_VERSION)
  5. sudo -u git -H make

Install Gitaly

  1. # Fetch Gitaly source with Git and compile with Go
  2. cd /home/git/gitlab
  3. sudo -u git -H bundle exec rake "gitlab:gitaly:install[/home/git/gitaly,/home/git/repositories]" RAILS_ENV=production

您可以通过提供其他参数来指定其他 Git 存储库:

  1. sudo -u git -H bundle exec rake "gitlab:gitaly:install[/home/git/gitaly,/home/git/repositories,https://example.com/gitaly.git]" RAILS_ENV=production

接下来,确保已配置 Gitaly:

  1. sudo chmod 0700 /home/git/gitlab/tmp/sockets/private
  2. sudo chown git /home/git/gitlab/tmp/sockets/private
  3. # If you are using non-default settings you need to update config.toml
  4. cd /home/git/gitaly
  5. sudo -u git -H editor config.toml

For more information about configuring Gitaly see .

Start Gitaly

Gitaly 必须在下一节中运行.

  1. gitlab_path=/home/git/gitlab
  2. gitaly_path=/home/git/gitaly
  3. sudo -u git -H sh -c "$gitlab_path/bin/daemon_with_pidfile $gitlab_path/tmp/pids/gitaly.pid \ $gitaly_path/gitaly $gitaly_path/config.toml >> $gitlab_path/log/gitaly.log 2>&1 &"

Initialize Database and Activate Advanced Features

  1. cd /home/git/gitlab
  2. sudo -u git -H bundle exec rake gitlab:setup RAILS_ENV=production
  3. # Type 'yes' to create the database tables.
  4. # or you can skip the question by adding force=yes
  5. sudo -u git -H bundle exec rake gitlab:setup RAILS_ENV=production force=yes
  6. # When done, you see 'Administrator account created:'

注意:您可以通过分别在环境变量GITLAB_ROOT_PASSWORDGITLAB_ROOT_EMAIL提供管理员/ root 密码和电子邮件来设置它们,如下所示. 如果您未设置密码(并且密码已设置为默认密码),请等待 GitLab 暴露在公共互联网上,直到安装完成并且您已首次登录服务器. 首次登录时,将被迫更改默认密码. 通过在GITLAB_LICENSE_FILE环境变量中提供完整路径,此时也可以安装 Enterprise Edition 许可证.

  1. sudo -u git -H bundle exec rake gitlab:setup RAILS_ENV=production GITLAB_ROOT_PASSWORD=yourpassword GITLAB_ROOT_EMAIL=youremail GITLAB_LICENSE_FILE="/path/to/license"

Secure secrets.yml

secrets.yml文件存储会话和安全变量的加密密钥. 备份secrets.yml安全保存,但是请不要将其与数据库备份存储在同一位置. 否则,如果其中一个备份遭到破坏,您的秘密就会暴露出来.

下载初始化脚本(将为/etc/init.d/gitlab ):

而且,如果要使用非默认文件夹或用户安装,请复制并编辑默认文件:

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

如果将 GitLab 安装在其他目录中或以默认用户以外的用户身份安装,则应在/etc/default/gitlab更改这些设置. 不要编辑/etc/init.d/gitlab因为它将在升级时更改.

使 GitLab 在启动时启动:

  1. sudo update-rc.d gitlab defaults 21

Set up Logrotate

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

Check Application Status

检查 GitLab 及其环境是否配置正确:

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

Compile GetText PO files

  1. sudo -u git -H bundle exec rake gettext:compile RAILS_ENV=production

Compile Assets

  1. sudo -u git -H yarn install --production --pure-lockfile
  2. sudo -u git -H bundle exec rake gitlab:assets:compile RAILS_ENV=production NODE_ENV=production

如果rakeJavaScript heap out of memory不足错误而失败,请尝试按如下所示设置NODE_OPTIONS来运行它.

  1. sudo -u git -H bundle exec rake gitlab:assets:compile RAILS_ENV=production NODE_ENV=production NODE_OPTIONS="--max_old_space_size=4096"

Start Your GitLab Instance

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

9. NGINX

注意: NGINX 是 GitLab 官方支持的 Web 服务器. 如果您不能或不想将 NGINX 用作 Web 服务器,请参阅 .

Installation

  1. sudo apt-get install -y nginx

Site Configuration

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

确保编辑配置文件以匹配您的设置. 另外,请确保您与 GitLab 的路径匹配,尤其是在为git用户以外的用户安装时:

  1. # Change YOUR_SERVER_FQDN to the fully-qualified
  2. # domain name of your host serving GitLab.
  3. #
  4. # Remember to match your paths to GitLab, especially
  5. # if installing for a user other than 'git'.
  6. #
  7. # If using Ubuntu default nginx install:
  8. # either remove the default_server from the listen line
  9. # or else sudo rm -f /etc/nginx/sites-enabled/default
  10. sudo editor /etc/nginx/sites-available/gitlab

如果您打算启用 GitLab 页面,则需要使用一个单独的 NGINX 配置. 在GitLab 页面管理指南中阅读有关所需配置的所有信息.

注意:如果要使用 HTTPS,请将gitlab NGINX 配置替换为gitlab-ssl . 有关 HTTPS 配置的详细信息,请参见 .

Test Configuration

使用以下命令验证gitlabgitlab-ssl NGINX 配置文件:

  1. sudo nginx -t

您应该会收到syntax is okay并且test is successful消息. 如果收到错误,请按照给出的错误消息中的说明检查gitlabgitlab-ssl NGINX 配置文件是否有错别字等.

注意:通过运行nginx -v验证安装的版本是否大于 1.12.1. 如果它较低,您可能会收到以下错误: nginx: [emerg] unknown "start$temp=[filtered]$rest" variable nginx: configuration file /etc/nginx/nginx.conf test failed

Restart

  1. sudo service nginx restart

Post-install

Double-check Application Status

为了确保您不会错过任何东西,请使用以下命令进行更彻底的检查:

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

如果所有项目均为绿色,则恭喜您成功安装了 GitLab!

gitlab:check提供SANITIZE=true环境变量,以从 check 命令的输出中省略项目名称.

Initial Login

在您的 Web 浏览器中访问 YOUR_SERVER 进行首次 GitLab 登录.

如果未提供 root 密码,则将重定向到密码重置屏幕,以提供初始管理员帐户的密码. 输入所需的密码,您将被重定向回登录屏幕.

默认帐户的用户名是root . 提供您先前创建的密码并登录. 登录后,您可以根据需要更改用户名.

Enjoy!

You can use sudo service gitlab start and sudo service gitlab stop to start and stop GitLab.

Advanced Setup Tips

有关如何使用相对 URL 配置 GitLab 的更多信息,请参见相对 URL 文档 .

Using HTTPS

要将 GitLab 与 HTTPS 一起使用:

  1. In gitlab.yml:
    1. 将第 1 节中的port选项设置为443 .
    2. 将第 1 节中的https选项设置为true .
  2. 在 GitLab Shell 的config.yml中:
    1. gitlab_url选项设置为 GitLab 的 HTTPS 端点(例如https://git.example.com ).
    2. 使用ca_fileca_path选项设置证书.
  3. 使用gitlab-ssl NGINX 示例配置,而不是gitlab配置.
    1. 更新YOUR_SERVER_FQDN .
    2. 更新ssl_certificatessl_certificate_key .
    3. 查看配置文件,并考虑应用其他安全性和性能增强功能.

不鼓励使用自签名证书,但如果必须使用它,请遵循正常说明. 然后:

  1. 生成自签名 SSL 证书:

    1. mkdir -p /etc/nginx/ssl/
    2. cd /etc/nginx/ssl/
    3. sudo openssl req -newkey rsa:2048 -x509 -nodes -days 3560 -out gitlab.crt -keyout gitlab.key
    4. sudo chmod o-r gitlab.key
  2. 在 GitLab Shell 的config.yml ,将self_signed_cert设置为true .

Enable Reply by email

有关如何进行此设置的更多信息,请参见 .

LDAP Authentication

您可以在config/gitlab.yml配置 LDAP 身份验证. 编辑此文件后,重新启动 GitLab.

Using Custom OmniAuth Providers

请参阅OmniAuth 集成文档 .

Build your projects

GitLab 可以构建您的项目. 要启用该功能,您需要 GitLab Runners 为您执行此操作. 请参阅GitLab Runner 部分进行安装.

Adding your Trusted Proxies

如果要在单独的计算机上使用反向代理,则可能要将代理添加到”受信任的代理”列表中. 否则,用户将显示为从代理的 IP 地址登录.

您可以通过自定义第 1 节中的trusted_proxies选项在config/gitlab.yml添加受信任的代理.保存文件并重新配置 GitLab,以使更改生效.

Custom Redis Connection

如果您想通过非标准端口或其他主机连接到 Redis 服务器,则可以通过config/resque.yml文件配置其连接字符串.

  1. # example
  2. production:
  3. url: redis://redis.example.tld:6379

如果要通过套接字连接 Redis 服务器,请使用” unix:” URL 方案以及config/resque.yml文件中 Redis 套接字文件的路径.

  1. # example
  2. production:
  3. url: unix:/path/to/redis/socket

另外,您可以在config/resque.yml文件中使用环境变量:

  1. # example
  2. production:
  3. url: <%= ENV.fetch('GITLAB_REDIS_URL') %>

Custom SSH Connection

如果您在非标准端口上运行 SSH,则必须更改 GitLab 用户的 SSH 配置.

  1. # Add to /home/git/.ssh/config
  2. host localhost # Give your setup a name (here: override localhost)
  3. user git # Your remote git user
  4. port 2222 # Your port number
  5. hostname 127.0.0.1; # Your server name or IP

您还需要在config\gitlab.yml文件中更改相应的选项(例如ssh_userssh_hostadmin_uri ).

Additional Markup Styles

除了始终支持的 Markdown 样式外,GitLab 还可以显示其他富文本文件. 但是您可能必须安装依赖项才能这样做. 有关更多信息,请参见github-markup gem 自述文件 .

Using Unicorn

从 GitLab 12.9 开始, Puma已取代 Unicorn 成为默认源安装 Web 服务器. 如果要切换回独角兽,请按照下列步骤操作:

  1. 完成 GitLab 设置,以使其启动并运行.
  2. 将提供的示例 Unicorn 配置文件复制到位:

    1. cd /home/git/gitlab
    2. # Copy config file for the web server
    3. sudo -u git -H cp config/unicorn.rb.example config/unicorn.rb
  3. 编辑系统init.d脚本并设置USE_WEB_SERVER="unicorn" . 如果您有/etc/default/gitlab ,那么您应该对其进行编辑.

  4. Restart GitLab.

Using Sidekiq instead of Sidekiq Cluster

从 GitLab 12.10 开始,Source 安装使用bin/sidekiq-cluster来管理 Sidekiq 进程. 在 14.0 之前,仍支持直接使用 Sidekiq. 因此,如果您遇到问题,请:

  1. 编辑系统init.d脚本以删除SIDEKIQ_WORKERS标志. 如果您有/etc/default/gitlab ,那么您应该对其进行编辑.
  2. 重新启动 GitLab.
  3. 创建一个描述问题的问题.

如果在尝试克隆由 GitLab 托管的存储库时看到此消息,则可能是由于 NGINX 或 Apache 配置过时,或者缺少或配置了错误的 GitLab Workhorse 实例. 仔细检查您是否已 , 已安装 GitLab Workhorse并已正确 .

google-protobuf “LoadError: /lib/x86_64-linux-gnu/libc.so.6: version `GLIBC_2.14’ not found”

对于某些版本的google-protobuf gem,这可能会在某些平台上发生. 解决方法是安装此 gem 的仅源版本.

首先,您必须找到 GitLab 安装所需的google-protobuf确切版本:

  1. cd /home/git/gitlab
  2. # Only one of the following two commands will print something. It
  3. # will look like: * google-protobuf (3.2.0)
  4. bundle list | grep google-protobuf
  5. bundle check | grep google-protobuf

下面以3.2.0为例. 将其替换为您在上面找到的版本号:

  1. cd /home/git/gitlab
  2. sudo -u git -H gem install google-protobuf --version 3.2.0 --platform ruby

最后,您可以测试google-protobuf是否正确加载. 以下应打印”确定”.

    如果命令失败,则可能需要安装操作系统的开发人员工具.

    在 RedHat / CentOS 上:

    1. sudo yum groupinstall 'Development Tools'