1. Installation from source

原文:https://docs.gitlab.com/ee/install/installation.html

2. Installation from source

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

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

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

2.1. Consider the Omnibus package installation

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

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

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

2.2. Select a version to install

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

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

2.3. GitLab directory structure

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

|-- home
|   |-- git
|       |-- .ssh
|       |-- gitlab
|       |-- gitlab-shell
|       |-- repositories 
  • /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 体系结构文档 .

2.4. Overview

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

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

2.5. 1. Packages and dependencies

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

# run as root!
apt-get update -y
apt-get upgrade -y
apt-get install sudo -y 

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

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

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

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

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

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

sudo apt-get install libkrb5-dev 

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

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

# Install Git
sudo apt-get install -y git-core

# Make sure Git is version 2.27.0 or higher (minimal supported version is 2.25.0)
git --version 

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

ldd $(command -v git) | grep pcre2 

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

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

sudo apt-get remove git-core 

在 Ubuntu 上, 从其官方 PPA安装 Git:

# run as root!
add-apt-repository ppa:git-core/ppa
apt update
apt install git
# repeat libpcre2 check as above 

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

# Install dependencies
sudo apt-get install -y libcurl4-openssl-dev libexpat1-dev gettext libz-dev libssl-dev build-essential

# Download and compile pcre2 from source
curl --silent --show-error --location https://ftp.pcre.org/pub/pcre/pcre2-10.33.tar.gz --output pcre2.tar.gz
tar -xzf pcre2.tar.gz
cd pcre2-10.33
chmod +x configure
./configure --prefix=/usr --enable-jit
make
sudo make install

# Download and compile from source
cd /tmp
curl --remote-name --location --progress https://www.kernel.org/pub/software/scm/git/git-2.27.0.tar.gz
echo '77ded85cbe42b1ffdc2578b460a1ef5d23bcbc6683eabcafbb0d394dffe2e787  git-2.27.0.tar.gz' | shasum -a256 -c - && tar -xzf git-2.27.0.tar.gz
cd git-2.27.0/
./configure --with-libpcre
make prefix=/usr/local all

# Install into /usr/local/bin
sudo make prefix=/usr/local install

# When editing config/gitlab.yml later, change the git -> bin_path to /usr/local/bin/git 

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

sudo apt-get install -y graphicsmagick 

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

sudo apt-get install -y postfix 

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

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

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

2.6. 2. Ruby

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

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

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

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

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

sudo apt-get remove ruby1.8 

下载 Ruby 并进行编译:

mkdir /tmp/ruby && cd /tmp/ruby
curl --remote-name --progress https://cache.ruby-lang.org/pub/ruby/2.6/ruby-2.6.6.tar.gz
echo '2d78048e293817f38d4ede4ebc7873013e97bb0b  ruby-2.6.6.tar.gz' | shasum -c - && tar xzf ruby-2.6.6.tar.gz
cd ruby-2.6.6

./configure --disable-install-rdoc
make
sudo make install 

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

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

2.7. 3. Go

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

# Remove former Go installation folder
sudo rm -rf /usr/local/go

curl --remote-name --progress https://dl.google.com/go/go1.13.5.linux-amd64.tar.gz
echo '512103d7ad296467814a6e3f635631bd35574cab3369a97a323c9a585ccaa569  go1.13.5.linux-amd64.tar.gz' | shasum -a256 -c - && \
  sudo tar -C /usr/local -xzf go1.13.5.linux-amd64.tar.gz
sudo ln -sf /usr/local/go/bin/{go,godoc,gofmt} /usr/local/bin/
rm go1.13.5.linux-amd64.tar.gz 

2.8. 4. Node

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

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

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

# install node v12.x
curl --location https://deb.nodesource.com/setup_12.x | sudo bash -
sudo apt-get install -y nodejs

curl --silent --show-error https://dl.yarnpkg.com/debian/pubkey.gpg | sudo apt-key add -
echo "deb https://dl.yarnpkg.com/debian/ stable main" | sudo tee /etc/apt/sources.list.d/yarn.list
sudo apt-get update
sudo apt-get install yarn 

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

2.9. 5. System users

为 GitLab 创建一个git用户:

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

2.10. 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 服务并确认该服务正在运行:
    sudo service postgresql start
    sudo service postgresql status 
    1. 为 GitLab 创建数据库用户:
    sudo -u postgres psql -d template1 -c "CREATE USER git CREATEDB;" 
    1. 创建pg_trgm扩展(GitLab 8.6+必需):
    sudo -u postgres psql -d template1 -c "CREATE EXTENSION IF NOT EXISTS pg_trgm;" 
    1. 创建 GitLab 生产数据库并授予该数据库的所有特权:
    sudo -u postgres psql -d template1 -c "CREATE DATABASE gitlabhq_production OWNER git;" 
    1. 尝试使用新用户连接到新数据库:
    sudo -u git -H psql -d gitlabhq_production 
    1. 检查是否启用了pg_trgm扩展名:
    SELECT true AS enabled
    FROM pg_available_extensions
    WHERE name = 'pg_trgm'
    AND installed_version IS NOT NULL; 

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

    enabled
    ---------
     t
    (1 row) 
    1. 退出数据库会话:
    gitlabhq_production> \q 

2.11. 7. Redis

GitLab 至少需要 Redis 5.0.

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

sudo apt-get install redis-server 

完成后,您可以配置 Redis:

# Configure redis to use sockets
sudo cp /etc/redis/redis.conf /etc/redis/redis.conf.orig

# Disable Redis listening on TCP by setting 'port' to 0
sudo sed 's/^port .*/port 0/' /etc/redis/redis.conf.orig | sudo tee /etc/redis/redis.conf

# Enable Redis socket for default Debian / Ubuntu path
echo 'unixsocket /var/run/redis/redis.sock' | sudo tee -a /etc/redis/redis.conf

# Grant permission to the socket to all members of the redis group
echo 'unixsocketperm 770' | sudo tee -a /etc/redis/redis.conf

# Create the directory which contains the socket
sudo mkdir -p /var/run/redis
sudo chown redis:redis /var/run/redis
sudo chmod 755 /var/run/redis

# Persist the directory which contains the socket, if applicable
if [ -d /etc/tmpfiles.d ]; then echo 'd  /var/run/redis  0755  redis  redis  10d  -' | sudo tee -a /etc/tmpfiles.d/redis.conf
fi

# Activate the changes to redis.conf
sudo service redis-server restart

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

2.12. 8. GitLab

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

2.12.1. Clone the Source

克隆社区版:

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

克隆企业版:

# Clone GitLab repository
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在生产服务器上!

2.12.2. 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 the 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/

# Create the public/uploads/ directory
sudo -u git -H mkdir -p public/uploads/

# Make sure only the GitLab user has access to the public/uploads/ directory
# now that files in public/uploads are served by gitlab-workhorse
sudo chmod 0700 public/uploads

# Change the permissions of the directory where CI job logs 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/

# Change the permissions of the directory where GitLab Pages are stored
sudo chmod -R ug+rwX shared/pages/

# Copy the example Puma config
sudo -u git -H cp config/puma.rb.example config/puma.rb

# Refer to https://github.com/puma/puma#configuration for more information.
# You should scale Puma workers and threads based on the number of CPU
# cores you have available. You can get that number via the `nproc` command.
sudo -u git -H editor config/puma.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
# 'autocrlf' is needed for the web editor
sudo -u git -H git config --global core.autocrlf input

# Disable 'git gc --auto' because GitLab already runs 'git gc' when needed
sudo -u git -H git config --global gc.auto 0

# Enable packfile bitmaps
sudo -u git -H git config --global repack.writeBitmaps true

# Enable push options
sudo -u git -H git config --global receive.advertisePushOptions true

# Enable fsyncObjectFiles to reduce risk of repository corruption if the server crashes
sudo -u git -H git config --global core.fsyncObjectFiles true

# 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 

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

2.12.3. Configure GitLab DB Settings

sudo -u git cp config/database.yml.postgresql config/database.yml

# Remove host, username, and password lines from config/database.yml.
# Once modified, the `production` settings will be as follows:
#
#   production:
#     adapter: postgresql
#     encoding: unicode
#     database: gitlabhq_production
#     pool: 10
#
sudo -u git -H editor config/database.yml

# Remote PostgreSQL only:
# Update username/password in config/database.yml.
# You only need to adapt the production settings (first part).
# If you followed the database guide then please do as follows:
# Change 'secure password' with the value you have given to $password
# You can keep the double quotes around the password
sudo -u git -H editor config/database.yml

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

2.12.4. Install Gems

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

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

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

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

2.12.5. Install GitLab Shell

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

# Run the installation task for gitlab-shell:
sudo -u git -H bundle exec rake gitlab:shell:install 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 

注意:如果要使用 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) .

2.12.6. Install GitLab Workhorse

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

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

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

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

2.12.7. Install GitLab-Elasticsearch-indexer on Enterprise Edition

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

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

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

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 社区版中.

2.12.8. Install GitLab Pages

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

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

2.12.9. Install Gitaly

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

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

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:

# Restrict Gitaly socket access
sudo chmod 0700 /home/git/gitlab/tmp/sockets/private
sudo chown git /home/git/gitlab/tmp/sockets/private

# If you are using non-default settings you need to update config.toml
cd /home/git/gitaly
sudo -u git -H editor config.toml 

For more information about configuring Gitaly see the Gitaly documentation.

2.12.10. Start Gitaly

Gitaly 必须在下一节中运行.

gitlab_path=/home/git/gitlab
gitaly_path=/home/git/gitaly

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 &" 

2.12.11. Initialize Database and Activate Advanced Features

cd /home/git/gitlab
sudo -u git -H bundle exec rake gitlab:setup RAILS_ENV=production
# Type 'yes' to create the database tables.

# or you can skip the question by adding force=yes
sudo -u git -H bundle exec rake gitlab:setup RAILS_ENV=production force=yes

# When done, you see 'Administrator account created:' 

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

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" 

2.12.12. Secure secrets.yml

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

2.12.13. Install Init Script

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

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

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

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

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

使 GitLab 在启动时启动:

sudo update-rc.d gitlab defaults 21 

2.12.14. Set up Logrotate

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

2.12.15. Check Application Status

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

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

2.12.16. Compile GetText PO files

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

2.12.17. Compile Assets

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

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

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

2.12.18. Start Your GitLab Instance

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

2.13. 9. NGINX

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

2.13.1. Installation

sudo apt-get install -y nginx 

2.13.2. Site Configuration

复制示例站点配置:

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

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

# Change YOUR_SERVER_FQDN to the fully-qualified
# domain name of your host serving GitLab.
#
# Remember to match your paths to GitLab, especially
# if installing for a user other than 'git'.
#
# 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 

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

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

2.13.3. Test Configuration

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

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

2.13.4. Restart

sudo service nginx restart 

2.14. Post-install

2.14.1. Double-check Application Status

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

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

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

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

2.14.2. 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.

2.15. Advanced Setup Tips

2.15.1. Relative URL support

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

2.15.2. 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 证书:

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

2.15.3. Enable Reply by email

有关如何进行此设置的更多信息,请参见"通过电子邮件答复"文档 .

2.15.4. LDAP Authentication

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

2.15.5. Using Custom OmniAuth Providers

请参阅OmniAuth 集成文档 .

2.15.6. Build your projects

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

2.15.7. Adding your Trusted Proxies

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

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

2.15.8. Custom Redis Connection

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

# example
production:
  url: redis://redis.example.tld:6379 

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

# example
production:
  url: unix:/path/to/redis/socket 

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

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

2.15.9. Custom SSH Connection

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

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

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

2.15.10. Additional Markup Styles

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

2.15.11. Using Unicorn

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

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

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

2.15.12. 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. 创建一个描述问题的问题.

2.16. Troubleshooting

2.16.1. “You appear to have cloned an empty repository.”

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

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

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

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

cd /home/git/gitlab

# Only one of the following two commands will print something. It
# will look like: * google-protobuf (3.2.0)
bundle list | grep google-protobuf
bundle check | grep google-protobuf 

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

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

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

sudo -u git -H bundle exec ruby -rgoogle/protobuf -e 'puts :OK' 

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

在 Debian / Ubuntu 上:

sudo apt-get install build-essential libgmp-dev 

在 RedHat / CentOS 上:

sudo yum groupinstall 'Development Tools' 
Copyright © 温玉 2021 | 浙ICP备2020032454号 all right reserved,powered by Gitbook该文件修订时间: 2023-08-17 12:04:10

results matching ""

    No results matching ""