💎一站式轻松地调用各大LLM模型接口,支持GPT4、智谱、星火、月之暗面及文生图 广告
# Installation from source > 原文:[https://docs.gitlab.com/ee/install/installation.html](https://docs.gitlab.com/ee/install/installation.html) * [Consider the Omnibus package installation](#consider-the-omnibus-package-installation) * [Select a version to install](#select-a-version-to-install) * [GitLab directory structure](#gitlab-directory-structure) * [Overview](#overview) * [1\. Packages and dependencies](#1-packages-and-dependencies) * [2\. Ruby](#2-ruby) * [3\. Go](#3-go) * [4\. Node](#4-node) * [5\. System users](#5-system-users) * [6\. Database](#6-database) * [7\. Redis](#7-redis) * [8\. GitLab](#8-gitlab) * [Clone the Source](#clone-the-source) * [Configure It](#configure-it) * [Configure GitLab DB Settings](#configure-gitlab-db-settings) * [Install Gems](#install-gems) * [Install GitLab Shell](#install-gitlab-shell) * [Install GitLab Workhorse](#install-gitlab-workhorse) * [Install GitLab-Elasticsearch-indexer on Enterprise Edition](#install-gitlab-elasticsearch-indexer-on-enterprise-edition) * [Install GitLab Pages](#install-gitlab-pages) * [Install Gitaly](#install-gitaly) * [Start Gitaly](#start-gitaly) * [Initialize Database and Activate Advanced Features](#initialize-database-and-activate-advanced-features) * [Secure secrets.yml](#secure-secretsyml) * [Install Init Script](#install-init-script) * [Set up Logrotate](#set-up-logrotate) * [Check Application Status](#check-application-status) * [Compile GetText PO files](#compile-gettext-po-files) * [Compile Assets](#compile-assets) * [Start Your GitLab Instance](#start-your-gitlab-instance) * [9\. NGINX](#9-nginx) * [Installation](#installation) * [Site Configuration](#site-configuration) * [Test Configuration](#test-configuration) * [Restart](#restart) * [Post-install](#post-install) * [Double-check Application Status](#double-check-application-status) * [Initial Login](#initial-login) * [Advanced Setup Tips](#advanced-setup-tips) * [Relative URL support](#relative-url-support) * [Using HTTPS](#using-https) * [Enable Reply by email](#enable-reply-by-email) * [LDAP Authentication](#ldap-authentication) * [Using Custom OmniAuth Providers](#using-custom-omniauth-providers) * [Build your projects](#build-your-projects) * [Adding your Trusted Proxies](#adding-your-trusted-proxies) * [Custom Redis Connection](#custom-redis-connection) * [Custom SSH Connection](#custom-ssh-connection) * [Additional Markup Styles](#additional-markup-styles) * [Using Unicorn](#using-unicorn) * [Using Sidekiq instead of Sidekiq Cluster](#using-sidekiq-instead-of-sidekiq-cluster) * [Troubleshooting](#troubleshooting) * [“You appear to have cloned an empty repository.”](#you-appear-to-have-cloned-an-empty-repository) * [`google-protobuf` “LoadError: /lib/x86_64-linux-gnu/libc.so.6: version `GLIBC_2.14’ not found”](#google-protobuf-loaderror-libx86_64-linux-gnulibcso6-version-glibc_214-not-found) # Installation from source[](#installation-from-source "Permalink") 这是使用源文件设置生产 GitLab 服务器的官方安装指南. 要设置**开发安装**或许多其他安装选项,请参见[主要安装页面](README.html) . 它是为**Debian / Ubuntu**操作系统创建并经过测试的. 有关硬件和操作系统[要求](requirements.html) ,请阅读 requirements.md. 如果要在 RHEL / CentOS 上安装,我们建议使用[Omnibus 软件包](https://about.gitlab.com/install/) . 本指南之所以冗长,是因为它涵盖了许多情况,并且包括您需要的所有命令,这是[实际上可以立即使用的少数安装脚本之一](https://twitter.com/robinvdvleuten/status/424163226532986880) . 已知以下步骤有效. **偏离**本指南**时请多加注意** . 确保您没有违反任何有关 GitLab 对其环境的假设. 例如,许多人遇到权限问题,因为他们更改了目录的位置或以错误的用户身份运行服务. 如果您在本指南中发现错误/错误, **请**按照[提供帮助的指南](https://gitlab.com/gitlab-org/gitlab/blob/master/CONTRIBUTING.md) **提交合并请求** . ## Consider the Omnibus package installation[](#consider-the-omnibus-package-installation "Permalink") 由于从源头进行安装需要大量工作并且容易出错,因此我们强烈建议您快速,可靠地[安装 Omnibus 软件包](https://about.gitlab.com/install/) (deb / rpm). Omnibus 软件包更可靠的原因之一是它使用 runit 来重新启动任何 GitLab 进程,以防万一崩溃. 在频繁使用的 GitLab 实例上,Sidekiq 后台工作程序的内存使用量会随着时间增长. Omnibus 软件包通过[使 Sidekiq](../administration/operations/sidekiq_memory_killer.html)在使用过多内存的情况下[正常终止来](../administration/operations/sidekiq_memory_killer.html)解决此问题. 在此终止后,runit 将检测到 Sidekiq 没有运行并启动它. 由于从源头进行的安装不使用 runit 进行过程监视,因此 Sidekiq 无法终止,并且其内存使用量会随着时间的推移而增长. ## Select a version to install[](#select-a-version-to-install "Permalink") 确保从您要安装的 GitLab 的分支(版本)中查看[此安装指南](https://gitlab.com/gitlab-org/gitlab/blob/master/doc/install/installation.md) (例如`11-7-stable` ). 您可以在 GitLab 左上角的版本下拉菜单中选择分支(位于菜单栏下方). 如果不清楚最高数目的稳定分支,请查看[GitLab 博客](https://about.gitlab.com/blog/)以获取版本信息. ## GitLab directory structure[](#gitlab-directory-structure "Permalink") 这是主要的目录结构,您将按照此页面的说明进行操作: ``` |-- 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 存储库的地方. **该区域包含项目的关键数据.** **[保持备份](../raketasks/backup_restore.html) .** **注意:**可以在 GitLab 的`config/gitlab.yml`和 GitLab Shell 的`config.yml`中`config/gitlab.yml`存储库的默认位置. 有关更深入的概述,请参阅[GitLab 体系结构文档](../development/architecture.html) . ## Overview[](#overview "Permalink") GitLab 安装包括设置以下组件: 1. [Packages and dependencies](#1-packages-and-dependencies). 2. [Ruby](#2-ruby). 3. [Go](#3-go). 4. [Node](#4-node). 5. [System users](#5-system-users). 6. [Database](#6-database). 7. [Redis](#7-redis). 8. [GitLab](#8-gitlab). 9. [NGINX](#9-nginx). ## 1\. Packages and dependencies[](#1-packages-and-dependencies "Permalink") 默认情况下,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](https://github.com/google/re2/wiki/Install) . 如果要使用 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](https://git-scm.com/download/linux)安装 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 ``` 为了使[自定义图标](../user/admin_area/appearance.html#favicon)能够正常工作,需要安装 GraphicsMagick. ``` sudo apt-get install -y graphicsmagick ``` **注意:**为了接收邮件通知,请确保安装邮件服务器. 默认情况下,Debian 随 exim4 一起提供,但这[会带来问题,](https://gitlab.com/gitlab-org/gitlab-foss/-/issues/12754)而 Ubuntu 则没有. 推荐的邮件服务器是 postfix,您可以使用以下命令进行安装: ``` sudo apt-get install -y postfix ``` 然后选择" Internet Site",然后按 Enter 确认主机名. [GitLab Workhorse](https://gitlab.com/gitlab-org/gitlab-workhorse#dependencies)需要使用`exiftool`才能从上传的图像中删除 EXIF 数据. ``` sudo apt-get install -y libimage-exiftool-perl ``` ## 2\. Ruby[](#2-ruby "Permalink") 运行 GitLab 需要使用 Ruby 解释器. **注意:**当前支持的 Ruby(MRI)版本是 2.6.x. GitLab 12.2 放弃了对 Ruby 2.5.x 的支持. 在生产环境[中将](https://github.com/rbenv/rbenv) Ruby 版本管理器(如[RVM](https://rvm.io/) , [rbenv](https://github.com/rbenv/rbenv)或[chruby)](https://github.com/postmodern/chruby)与 GitLab [一起](https://github.com/postmodern/chruby)使用通常会导致难以诊断问题. 不支持版本管理器,我们强烈建议所有人按照以下说明使用系统 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' ``` ## 3\. Go[](#3-go "Permalink") 从 GitLab 8.0 开始,GitLab 有几个用 Go 编写的守护程序. 要安装 GitLab,我们需要一个 Go 编译器. 以下说明假定您使用 64 位 Linux. 您可以在[Go 下载页面上](https://s0golang0org.icopy.site/dl)找到其他平台的[下载](https://s0golang0org.icopy.site/dl) . ``` # 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 ``` ## 4\. Node[](#4-node "Permalink") 从 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 ``` 如果您对这些步骤有任何疑问,请访问[node](https://s0nodejs0org.icopy.site/en/download/package-manager/)和[yarn](https://classic.yarnpkg.com/en/docs/install/)的官方网站. ## 5\. System users[](#5-system-users "Permalink") 为 GitLab 创建一个`git`用户: ``` sudo adduser --disabled-login --gecos 'GitLab' git ``` ## 6\. Database[](#6-database "Permalink") **注意:**从 GitLab 12.1 开始,仅支持 PostgreSQL. 从 GitLab 13.0 开始,我们需要 PostgreSQL 11+. 1. 安装数据库软件包: ``` sudo apt-get install -y postgresql postgresql-client libpq-dev postgresql-contrib ``` 2. 启动 PostgreSQL 服务并确认该服务正在运行: ``` sudo service postgresql start sudo service postgresql status ``` 3. 为 GitLab 创建数据库用户: ``` sudo -u postgres psql -d template1 -c "CREATE USER git CREATEDB;" ``` 4. 创建`pg_trgm`扩展(GitLab 8.6+必需): ``` sudo -u postgres psql -d template1 -c "CREATE EXTENSION IF NOT EXISTS pg_trgm;" ``` 5. 创建 GitLab 生产数据库并授予该数据库的所有特权: ``` sudo -u postgres psql -d template1 -c "CREATE DATABASE gitlabhq_production OWNER git;" ``` 6. 尝试使用新用户连接到新数据库: ``` sudo -u git -H psql -d gitlabhq_production ``` 7. 检查是否启用了`pg_trgm`扩展名: ``` SELECT true AS enabled FROM pg_available_extensions WHERE name = 'pg_trgm' AND installed_version IS NOT NULL; ``` 如果启用了扩展名,将产生以下输出: ``` enabled --------- t (1 row) ``` 8. 退出数据库会话: ``` gitlabhq_production> \q ``` ## 7\. Redis[](#7-redis "Permalink") 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 ``` ## 8\. GitLab[](#8-gitlab "Permalink") ``` # We'll install GitLab into the home directory of the user "git" cd /home/git ``` ### Clone the Source[](#clone-the-source "Permalink") 克隆社区版: ``` # 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`在生产服务器上! ### Configure It[](#configure-it "Permalink") ``` # 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.yml`和`puma.rb`以匹配您的设置. 如果要使用 Unicorn Web 服务器,请参阅" [使用 Unicorn"](#using-unicorn)以了解其他步骤.**注意:**如果要使用 HTTPS,请参阅" [使用 HTTPS"](#using-https)以了解其他步骤. ### Configure GitLab DB Settings[](#configure-gitlab-db-settings "Permalink") ``` 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 ``` ### Install Gems[](#install-gems "Permalink") **注意:**从 Bundler 1.5.2 开始,您可以调用`bundle install -jN` (其中`N`是您的处理器内核数)并享受并行 gem 的安装,其完成时间有可衡量的差异(快 60%). 使用`nproc`检查您的内核数. 有关更多信息,请参见这篇[文章](https://thoughtbot.com/blog/parallel-gem-installing-using-bundler) . 确保您有`bundle` (运行`bundle -v` ): * `>= 1.5.2` ,因为某些[问题](https://devcenter.heroku.com/changelog-items/411)已在 1.5.2 中[修复](https://github.com/rubygems/bundler/pull/2817) . * `< 2.x`. ``` sudo -u git -H bundle install --deployment --without development test mysql aws kerberos ``` **注意:**如果要使用 Kerberos 进行用户身份验证,请在上面的`--without`选项中省略`kerberos` . ### Install GitLab Shell[](#install-gitlab-shell "Permalink") 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"](#using-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[](#install-gitlab-workhorse "Permalink") GitLab-Workhorse 使用[GNU Make](https://www.gnu.org/software/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 ``` ### Install GitLab-Elasticsearch-indexer on Enterprise Edition[](#install-gitlab-elasticsearch-indexer-on-enterprise-edition "Permalink") GitLab-Elasticsearch-Indexer 使用[GNU Make](https://www.gnu.org/software/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.yml`的`production -> elasticsearch -> indexer_path`设置以指向该二进制文件. **注意:** Elasticsearch 是 GitLab 企业版的一项功能,不包含在 GitLab 社区版中. ### Install GitLab Pages[](#install-gitlab-pages "Permalink") GitLab Pages 使用[GNU Make](https://www.gnu.org/software/make/) . 此步骤是可选的,仅当您希望在 GitLab 中托管静态站点时才需要. 以下命令将在`/home/git/gitlab-pages`安装 GitLab `/home/git/gitlab-pages` . 有关其他设置步骤,请查阅适用于您的 GitLab 版本的[管理指南](https://gitlab.com/gitlab-org/gitlab/blob/master/doc/administration/pages/source.md) ,因为 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 ``` ### Install Gitaly[](#install-gitaly "Permalink") ``` # 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](../administration/gitaly/index.html). ### Start Gitaly[](#start-gitaly "Permalink") 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 &" ``` ### Initialize Database and Activate Advanced Features[](#initialize-database-and-activate-advanced-features "Permalink") ``` 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_PASSWORD`和`GITLAB_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" ``` ### Secure secrets.yml[](#secure-secretsyml "Permalink") `secrets.yml`文件存储会话和安全变量的加密密钥. 备份`secrets.yml`安全保存,但是请不要将其与数据库备份存储在同一位置. 否则,如果其中一个备份遭到破坏,您的秘密就会暴露出来. ### Install Init Script[](#install-init-script "Permalink") 下载初始化脚本(将为`/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 ``` ### Set up Logrotate[](#set-up-logrotate "Permalink") ``` sudo cp lib/support/logrotate/gitlab /etc/logrotate.d/gitlab ``` ### Check Application Status[](#check-application-status "Permalink") 检查 GitLab 及其环境是否配置正确: ``` sudo -u git -H bundle exec rake gitlab:env:info RAILS_ENV=production ``` ### Compile GetText PO files[](#compile-gettext-po-files "Permalink") ``` sudo -u git -H bundle exec rake gettext:compile RAILS_ENV=production ``` ### Compile Assets[](#compile-assets "Permalink") ``` 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 ``` 如果`rake`因`JavaScript 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" ``` ### Start Your GitLab Instance[](#start-your-gitlab-instance "Permalink") ``` sudo service gitlab start # or sudo /etc/init.d/gitlab restart ``` ## 9\. NGINX[](#9-nginx "Permalink") **注意:** NGINX 是 GitLab 官方支持的 Web 服务器. 如果您不能或不想将 NGINX 用作 Web 服务器,请参阅[GitLab 配方](https://gitlab.com/gitlab-org/gitlab-recipes/) . ### Installation[](#installation "Permalink") ``` sudo apt-get install -y nginx ``` ### Site Configuration[](#site-configuration "Permalink") 复制示例站点配置: ``` 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 页面管理指南中](../administration/pages/index.html)阅读有关所需配置的所有信息. **注意:**如果要使用 HTTPS,请将`gitlab` NGINX 配置替换为`gitlab-ssl` . 有关 HTTPS 配置的详细信息,请参见[使用 HTTPS](#using-https) . ### Test Configuration[](#test-configuration "Permalink") 使用以下命令验证`gitlab`或`gitlab-ssl` NGINX 配置文件: ``` sudo nginx -t ``` 您应该会收到`syntax is okay`并且`test is successful`消息. 如果收到错误,请按照给出的错误消息中的说明检查`gitlab`或`gitlab-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[](#restart "Permalink") ``` sudo service nginx restart ``` ## Post-install[](#post-install "Permalink") ### Double-check Application Status[](#double-check-application-status "Permalink") 为了确保您不会错过任何东西,请使用以下命令进行更彻底的检查: ``` sudo -u git -H bundle exec rake gitlab:check RAILS_ENV=production ``` 如果所有项目均为绿色,则恭喜您成功安装了 GitLab! 向`gitlab:check`提供`SANITIZE=true`环境变量,以从 check 命令的输出中省略项目名称. ### Initial Login[](#initial-login "Permalink") 在您的 Web 浏览器中访问 YOUR_SERVER 进行首次 GitLab 登录. 如果[在设置过程中](#initialize-database-and-activate-advanced-features)未[提供 root 密码,](#initialize-database-and-activate-advanced-features)则将重定向到密码重置屏幕,以提供初始管理员帐户的密码. 输入所需的密码,您将被重定向回登录屏幕. 默认帐户的用户名是**root** . 提供您先前创建的密码并登录. 登录后,您可以根据需要更改用户名. **Enjoy!** You can use `sudo service gitlab start` and `sudo service gitlab stop` to start and stop GitLab. ## Advanced Setup Tips[](#advanced-setup-tips "Permalink") ### Relative URL support[](#relative-url-support "Permalink") 有关如何使用相对 URL 配置 GitLab 的更多信息,请参见[相对 URL 文档](relative_url.html) . ### Using HTTPS[](#using-https "Permalink") 要将 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_file`或`ca_path`选项设置证书. 3. 使用`gitlab-ssl` NGINX 示例配置,而不是`gitlab`配置. 1. 更新`YOUR_SERVER_FQDN` . 2. 更新`ssl_certificate`和`ssl_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 ``` 2. 在 GitLab Shell 的`config.yml` ,将`self_signed_cert`设置为`true` . ### Enable Reply by email[](#enable-reply-by-email "Permalink") 有关如何进行此设置的更多信息,请参见["通过电子邮件答复"文档](../administration/reply_by_email.html) . ### LDAP Authentication[](#ldap-authentication "Permalink") 您可以在`config/gitlab.yml`配置 LDAP 身份验证. 编辑此文件后,重新启动 GitLab. ### Using Custom OmniAuth Providers[](#using-custom-omniauth-providers "Permalink") 请参阅[OmniAuth 集成文档](../integration/omniauth.html) . ### Build your projects[](#build-your-projects "Permalink") GitLab 可以构建您的项目. 要启用该功能,您需要 GitLab Runners 为您执行此操作. 请参阅[GitLab Runner 部分](https://about.gitlab.com/stages-devops-lifecycle/continuous-integration/#gitlab-runner)进行安装. ### Adding your Trusted Proxies[](#adding-your-trusted-proxies "Permalink") 如果要在单独的计算机上使用反向代理,则可能要将代理添加到"受信任的代理"列表中. 否则,用户将显示为从代理的 IP 地址登录. 您可以通过自定义第 1 节中的`trusted_proxies`选项在`config/gitlab.yml`添加受信任的代理.保存文件并[重新配置 GitLab,](../administration/restart_gitlab.html)以使更改生效. ### Custom Redis Connection[](#custom-redis-connection "Permalink") 如果您想通过非标准端口或其他主机连接到 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') %> ``` ### Custom SSH Connection[](#custom-ssh-connection "Permalink") 如果您在非标准端口上运行 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_user` , `ssh_host` , `admin_uri` ). ### Additional Markup Styles[](#additional-markup-styles "Permalink") 除了始终支持的 Markdown 样式外,GitLab 还可以显示其他富文本文件. 但是您可能必须安装依赖项才能这样做. 有关更多信息,请参见[`github-markup` gem 自述文件](https://github.com/gitlabhq/markup#markups) . ### Using Unicorn[](#using-unicorn "Permalink") 从 GitLab 12.9 开始, [Puma](https://github.com/puma/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 ``` 3. 编辑系统`init.d`脚本并设置`USE_WEB_SERVER="unicorn"` . 如果您有`/etc/default/gitlab` ,那么您应该对其进行编辑. 4. Restart GitLab. ### Using Sidekiq instead of Sidekiq Cluster[](#using-sidekiq-instead-of-sidekiq-cluster "Permalink") 从 GitLab 12.10 开始,Source 安装使用`bin/sidekiq-cluster`来管理 Sidekiq 进程. 在 14.0 之前,仍支持直接使用 Sidekiq. 因此,如果您遇到问题,请: 1. 编辑系统`init.d`脚本以删除`SIDEKIQ_WORKERS`标志. 如果您有`/etc/default/gitlab` ,那么您应该对其进行编辑. 2. 重新启动 GitLab. 3. [创建一个](https://gitlab.com/gitlab-org/gitlab/-/issues/-/new)描述问题的问题. ## Troubleshooting[](#troubleshooting "Permalink") ### “You appear to have cloned an empty repository.”[](#you-appear-to-have-cloned-an-empty-repository "Permalink") 如果在尝试克隆由 GitLab 托管的存储库时看到此消息,则可能是由于 NGINX 或 Apache 配置过时,或者缺少或配置了错误的 GitLab Workhorse 实例. 仔细检查您是否已[安装 Go](#3-go) , [已安装 GitLab Workhorse](#install-gitlab-workhorse)并已正确[配置 NGINX](#site-configuration) . ### `google-protobuf` “LoadError: /lib/x86_64-linux-gnu/libc.so.6: version `GLIBC_2.14’ not found”[](#google-protobuf-loaderror-libx86_64-linux-gnulibcso6-version-glibc_214-not-found "Permalink") 对于某些版本的`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' ```