GitLab

出自 ArchWiki

来自 GitLab 的主页

GitLab 提供 git 仓库管理、代码审查、问题跟踪、活动馈送和 wikis。企业在本地安装 GitLab,并将其与 LDAP 和 Active Directory 服务器连接,以实现安全身份验证和授权。单个 GitLab 服务器可以处理超过 25,000 名用户,但也可以创建具有多个活动服务器的高可用性设置。

可以在 GitLab.com 找到一个在线版本示例。

安装

GitLab 需要 Redis 和数据库后端。如果您计划在同一台机器上运行它,请先安装 PostgreSQL

安装 gitlab 软件包。

最后,必须安装和配置 web 服务器。GitLab 的配置将在 #Web 服务器配置 章节中讨论。

配置

初步说明

GitLab 由多个组件组成,请参阅 架构概览页面

gitlab 软件包以更符合标准 Linux 约定的方式安装 GitLab 的文件

描述 GitLab 官方 gitlab
应用程序代码 /home/git /usr/share/webapps/gitlab
应用程序数据 /home/git /var/lib/gitlab
用户(主目录) git (/home/git) gitlab (/var/lib/gitlab)
配置文件 GitShell /home/git/gitlab-shell/config.yml /etc/webapps/gitlab-shell/config.yml
配置文件 GitLab /home/git/gitlab/config/gitlab.yml /etc/webapps/gitlab/gitlab.yml
日志 /home/git/log /var/log/gitlab
Unix 套接字文件 / PID 文件 /home/git/sockets /run/gitlab
提示: 如果您熟悉 Arch 构建系统,您可以编辑 PKGBUILD 和相关文件,将 gitlab 的主目录更改为您喜欢的位置。

GitLab

编辑 /etc/webapps/gitlab/gitlab.yml 并至少设置以下参数

注意: hostnameport 用于 git clone http://hostname:port 示例。

主机名:gitlab: 部分中设置 host: - 将 localhost 替换为 yourdomain.com (没有 http:// 或尾部斜杠)- 为您的完全限定域名。

端口: port: 可能会令人困惑。这不是 GitLab 服务器 (Puma) 运行的端口;它是用户最初通过浏览器访问的端口。基本上,如果您希望用户在浏览器中访问 yourdomain.com,而不在域名后附加端口号,请将 port: 保留为 80。如果您希望用户在浏览器中键入类似 yourdomain.com:3425 的内容,那么您应该将 port: 设置为 3425。您还需要配置您的 Web 服务器以监听该端口。

时区(可选): time_zone: 参数是可选的,但可能有助于强制 GitLab 应用程序的时区。

根据上面 #初步说明 中的表格,以下路径必须在 gitlab.yml 中配置

  • repository_downloads_path: "/var/lib/gitlab/shared/cache/archive/"
  • gitlab_ci 部分:builds_path: "/var/lib/gitlab/builds/"
  • incoming_email 部分(如果启用):log_path: "/var/log/gitlab/mail_room_json.log"
  • artifacts 部分(如果启用):path: "/var/lib/gitlab/shared/artifacts"
  • external_diffs 部分(如果启用):storage_path: "/var/lib/gitlab/shared/external-diffs"
  • lfs 部分(如果启用):storage_path: "/var/lib/gitlab/shared/lfs-objects"
  • packages 部分(如果启用):storage_path: "/var/lib/gitlab/shared/packages"
  • dependency_proxy 部分(如果启用):storage_path: "/var/lib/gitlab/shared/dependency_proxy"
  • terraform_state 部分(如果启用):storage_path: "/var/lib/gitlab/shared/terraform_state"
  • pages 部分(如果启用):path: "/var/lib/gitlab/shared/pages"
  • registry 部分(如果启用):path: "/var/lib/gitlab/shared/registry"

Puma 的自定义端口

GitLab Puma 是主要组件,它处理大多数用户请求。默认情况下,它监听 /run/gitlab/gitlab.socket UNIX 套接字,这可以在 /etc/webapps/gitlab/puma.rb 文件中更改。

要配置 Puma 以监听 TCP 端口以及 UNIX 套接字

/etc/webapps/gitlab/puma.rb
bind 'unix:///run/gitlab/gitlab.socket'
bind 'tcp://127.0.0.1:8080'

如果 Puma 地址已更改,则还必须更新与 Puma 通信的其他组件的配置

  • 对于 GitLab Shell,更新 /etc/webapps/gitlab-shell/config.yml 中的 gitlab_url 变量和 /etc/gitlab-gitaly/config.toml[gitlab] 部分中的 url
提示: UNIX 套接字路径可以使用 URL 转义的斜杠指定(例如,默认 /run/gitlab/gitlab.sockethttp+unix://%2Frun%2Fgitlab%2Fgitlab.socket)。
  • 对于 GitLab Workhorse,编辑 gitlab-workhorse.service 并更新 -authBackend 选项。有关详细信息,请参阅 [1]

密钥字符串

确保文件 /etc/webapps/gitlab/secret/etc/webapps/gitlab-shell/secret 文件包含内容。它们的内容应保密,因为它们用于生成身份验证令牌等。

例如,可以使用以下命令生成随机字符串

# hexdump -v -n 64 -e '1/1 "%02x"' /dev/urandom > /etc/webapps/gitlab/secret
# chmod 640 /etc/webapps/gitlab/secret
# hexdump -v -n 64 -e '1/1 "%02x"' /dev/urandom > /etc/webapps/gitlab-shell/secret
# chmod 640 /etc/webapps/gitlab-shell/secret

还要为 secrets.yml 填写(新的)密钥字符串

/etc/webapps/gitlab/secrets.yml
production:
  secret_key_base: secret
  db_key_base: secret
  otp_key_base: secret
  openid_connect_signing_key: secret
  active_record_encryption_primary_key: ["32-alphanumeric-chars"]
  active_record_encryption_deterministic_key: ["32-alphanumeric-chars"]
  active_record_encryption_key_derivation_salt: "32-alphanumeric-chars"

Redis

为了提供足够的性能,您将需要一个缓存数据库。安装配置 Redis 实例,注意专门用于通过套接字监听的部分。

gitlab 用户添加到 redis 用户组 并更新此配置文件

/etc/webapps/gitlab/resque.yml
development:
  url: unix:/run/redis/redis.sock
test:
  url: unix:/run/redis/redis.sock
production:
  url: unix:/run/redis/redis.sock

PostgreSQL 数据库

在运行 Gitlab 之前,需要 PostgreSQL 数据库。

登录到 PostgreSQL 并创建 gitlabhq_production 数据库及其用户。请记住将 your_username_hereyour_password_here 更改为真实值

# psql -d template1
template1=# CREATE USER your_username_here WITH PASSWORD 'your_password_here';
template1=# ALTER USER your_username_here SUPERUSER;
template1=# CREATE DATABASE gitlabhq_production OWNER your_username_here;
template1=# \q
注意: 将用户创建为超级用户的原因是 GitLab 试图“智能地”安装扩展(而不仅仅是在其自己的用户空间中创建它们)。这只有 Postgresql 中的超级用户才允许。

尝试使用新用户连接到新数据库以验证它是否工作

$ psql -d gitlabhq_production -U your_username_here -W

打开新的 /etc/webapps/gitlab/database.yml 并设置 username:password: 的值。例如

/etc/webapps/gitlab/database.yml
#
# PRODUCTION
#
production:
  main:
    adapter: postgresql
    encoding: unicode
    database: gitlabhq_production
    username: your_username_here
    password: "your_password_here"
    # host: localhost
    # port: 5432
    socket: /run/postgresql/.s.PGSQL.5432
  ci:
    adapter: postgresql
    encoding: unicode
    database: gitlabhq_production
    database_tasks: false
    username: your_username_here
    password: "your_password_here"
    # host: localhost
    # port: 5432
    socket: /run/postgresql/.s.PGSQL.5432
...

对于我们的目的(除非您知道自己在做什么),您无需担心配置 /etc/webapps/gitlab/database.yml 中列出的其他数据库。我们只需要设置生产数据库即可使 GitLab 工作。

注意:GitLab 15.9 以来,仅包含 main: 部分的 database.yml 已被弃用。在 GitLab 17.0 及更高版本中,您的 database.yml 中必须有两个部分:main:ci:ci: 连接必须与 main: 连接到相同的数据库

初始化 Gitlab 数据库

在初始化数据库之前,启动 Redis 服务器和 gitlab-gitaly.service

初始化数据库并激活高级功能

$ cd /usr/share/webapps/gitlab
$ sudo -u gitlab $(cat environment | xargs) bundle exec rake gitlab:setup 

您可以通过在 GITLAB_ROOT_PASSWORDGITLAB_ROOT_EMAIL 环境变量中分别提供管理员/root 密码和电子邮件来设置它们,如下所示。如果您未设置密码(并且密码设置为默认密码),请在安装完成并且您首次登录服务器之前,不要将 GitLab 暴露于公共互联网。在首次登录期间,您将被强制更改默认密码。也可以通过在 GITLAB_LICENSE_FILE 环境变量中提供完整路径来安装企业版许可证。

本文或本节的实际准确性存在争议。

原因: 这会将 yourpassword 记录在 shell 历史记录中。(在 Talk:GitLab 中讨论)
$ cd /usr/share/webapps/gitlab
$ sudo -u gitlab $(cat environment | xargs) bundle exec rake gitlab:setup GITLAB_ROOT_PASSWORD=yourpassword GITLAB_ROOT_EMAIL=youremail GITLAB_LICENSE_FILE=/path/to/license

最后运行以下命令来检查您的安装

$ sudo -u gitlab $(cat environment | xargs) bundle exec rake gitlab:env:info
$ sudo -u gitlab $(cat environment | xargs) bundle exec rake gitlab:check
注意
  • gitlab:env:infogitlab:check 命令可能会显示与 git 相关的致命错误。 这是正常的。
  • gitlab:check 将会抱怨缺少 initscripts。 这没什么可担心的,因为使用 systemd 服务文件代替(GitLab 无法识别)。

调整修改位

(如果用户和组所有权未正确配置,gitlab 检查将不会通过)

# chmod -R ug+rwX,o-rwx /var/lib/gitlab/repositories/
# chmod -R ug-s /var/lib/gitlab/repositories
# find /var/lib/gitlab/repositories/ -type d -print0 | xargs -0 chmod g+s

Web 服务器配置

要从外部网络访问 GitLab,上游文档建议使用已建立的 Web 服务器作为代理。 从 Web 服务器到 GitLab 的所有查询都由 GitLab Workhorse 处理,Workhorse 决定它们应如何处理。 有关详细信息,请参阅 [2]

Nginx

有关基本的 nginx 配置,请参阅 Nginx#配置,有关启用 HTTPS,请参阅 Nginx#TLS。 本节中的示例还假设服务器块使用 Nginx#管理服务器条目 进行管理。

基于以下代码片段创建并编辑配置。 有关更多示例,请参阅 上游 GitLab 仓库

/etc/nginx/sites-available/gitlab
upstream gitlab-workhorse {
  server unix:/run/gitlab/gitlab-workhorse.socket fail_timeout=0;
}

server {
  listen 80;                  # IPv4 HTTP
  #listen 443 ssl http2;      # uncomment to enable IPv4 HTTPS + HTTP/2
  #listen [::]:80;            # uncomment to enable IPv6 HTTP
  #listen [::]:443 ssl http2; # uncomment to enable IPv6 HTTPS + HTTP/2
  server_name example.com;

  access_log  /var/log/gitlab/nginx_access.log;
  error_log   /var/log/gitlab/nginx_error.log;

  #ssl_certificate ssl/example.com.crt;
  #ssl_certificate_key ssl/example.com.key;

  location ~ ^/(assets)/ {
    root /usr/share/webapps/gitlab/public;
    gzip_static on; # to serve pre-gzipped version
    expires max;
    add_header Cache-Control public;
  }

  location / {
      # unlimited upload size in nginx (so the setting in GitLab applies)
      client_max_body_size 0;

      # proxy timeout should match the timeout value set in /etc/webapps/gitlab/puma.rb
      proxy_read_timeout 60;
      proxy_connect_timeout 60;
      proxy_redirect off;

      proxy_set_header Host $http_host;
      proxy_set_header X-Real-IP $remote_addr;
      proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
      proxy_set_header X-Forwarded-Proto $scheme;

      #proxy_set_header X-Forwarded-Ssl on;

      proxy_pass http://gitlab-workhorse;
  }

  error_page 404 /404.html;
  error_page 422 /422.html;
  error_page 500 /500.html;
  error_page 502 /502.html;
  error_page 503 /503.html;
  location ~ ^/(404|422|500|502|503)\.html$ {
    root /usr/share/webapps/gitlab/public;
    internal;
  }
}

Apache

安装和配置 Apache HTTP 服务器Apache HTTP 服务器#TLS 以启用 HTTPS。 您可以使用这些 上游配方 来开始配置 GitLab 虚拟主机的配置文件。

请注意,SSL 虚拟主机需要特定的 IP 而不是通用的。 此外,如果您为 Puma 设置了自定义端口,请不要忘记在 BalanceMember 行中设置它。

以下 Apache 模块也必须在配置文件 /etc/httpd/conf/httpd.conf 中加载

/etc/httpd/conf/httpd.conf
LoadModule proxy_module modules/mod_proxy.so
LoadModule proxy_http_module modules/mod_proxy_http.so
LoadModule proxy_wstunnel_module modules/mod_proxy_wstunnel.so

如果需要通过 unix 套接字gitlab-workhorse.service 进行 Apache 配置,则以下配置是可行的

/etc/httpd/conf/extra/gitlab.conf
<VirtualHost *:443>
    ServerName SERVERNAME
    ServerAlias SERVERNAME
    DocumentRoot /usr/share/webapps/gitlab/public
    <Directory /usr/share/webapps/gitlab/public>
        Options FollowSymlinks
        AllowOverride all
        Require all granted
    </Directory>
    <IfModule mod_alias.c>
        Alias / /usr/share/webapps/gitlab/public/
    </IfModule>

    <IfModule mod_headers.c>
        Header always set Strict-Transport-Security "max-age=15552000; includeSubDomains; preload"
    </IfModule>

    ProxyPreserveHost On
    SSLProxyEngine on
    AllowEncodedSlashes NoDecode
    
    <Location />
        ProxyPass unix:/run/gitlab/gitlab-workhorse.socket|http://127.0.0.1/
        ProxyPassReverse unix:/run/gitlab/gitlab-workhorse.socket|http://127.0.0.1/
    </Location>
 
    <Location /-/cable>
        ProxyPass unix:/run/gitlab/gitlab-workhorse.socket|ws://127.0.0.1/-/cable
        ProxyPassReverse unix:/run/gitlab/gitlab-workhorse.socket|ws://127.0.0.1/-/cable
    </Location> 
    #
    RewriteEngine on
    RewriteCond %{DOCUMENT_ROOT}/%{REQUEST_FILENAME} !-f [OR]
    RewriteCond %{REQUEST_URI} ^/uploads/.*
    RewriteRule .* unix:/run/gitlab/gitlab-workhorse.socket|http://127.0.0.1%{REQUEST_URI} [P,QSA,NE]
    RequestHeader set X_FORWARDED_PROTO 'https'
    RequestHeader set X-Forwarded-Ssl on
    #
    ErrorDocument 404 /404.html
    ErrorDocument 422 /422.html
    ErrorDocument 500 /500.html
    ErrorDocument 503 /deploy.html
    ErrorLog /var/log/httpd/gitlab.lan.info-error_log
    CustomLog /var/log/httpd/gitlab.lan.info-access_log common
Include /etc/letsencrypt/options-ssl-apache.conf
SSLCertificateFile /etc/letsencrypt/live/SERVERNAME/fullchain.pem
SSLCertificateKeyFile /etc/letsencrypt/live/SERVERNAME/privkey.pem
</VirtualHost>

<VirtualHost *:80>
    ServerName SERVERNAME
    Redirect / https://SERVERNAME
RewriteEngine on
RewriteCond %{SERVER_NAME} =SERVERNAME
RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]
</VirtualHost>

使用 tcp 网络连接 的工作示例(certbot 风格),假设 gitlab-workhorse.serviceExecStart 行上包含 -listenNetwork tcp -listenAddr 127.0.0.1:8181

/etc/httpd/conf/extra/gitlab.conf
<VirtualHost *:443>
    ServerName SERVERNAME
    ServerAlias SERVERNAME
    DocumentRoot /usr/share/webapps/gitlab/public
    <Directory /usr/share/webapps/gitlab/public>
        Options FollowSymlinks
        AllowOverride all
        Require all granted
    </Directory>
    <IfModule mod_alias.c>
        Alias / /usr/share/webapps/gitlab/public/
    </IfModule>

    <IfModule mod_headers.c>
        Header always set Strict-Transport-Security "max-age=15552000; includeSubDomains; preload"
    </IfModule>

    ProxyPreserveHost On
    SSLProxyEngine on
    AllowEncodedSlashes NoDecode
    <Location />
        ProxyPassReverse http://127.0.0.1:8181
        ProxyPassReverse http://SERVERNAME
    </Location>
    <Location /-/cable>
        ProxyPassReverse http://127.0.0.1:8181
        ProxyPassReverse http://SERVERNAME
    </Location>
    #
    RewriteEngine on
    RewriteCond %{DOCUMENT_ROOT}/%{REQUEST_FILENAME} !-f [OR]
    RewriteCond %{REQUEST_URI} ^/uploads/.*
    RewriteRule .* http://127.0.0.1:8181%{REQUEST_URI} [P,QSA,NE]
    RequestHeader set X_FORWARDED_PROTO 'https'
    RequestHeader set X-Forwarded-Ssl on
    #
    ErrorDocument 404 /404.html
    ErrorDocument 422 /422.html
    ErrorDocument 500 /500.html
    ErrorDocument 503 /deploy.html
    ErrorLog /var/log/httpd/gitlab.lan.info-error_log
    CustomLog /var/log/httpd/gitlab.lan.info-access_log common
Include /etc/letsencrypt/options-ssl-apache.conf
SSLCertificateFile /etc/letsencrypt/live/SERVERNAME/fullchain.pem
SSLCertificateKeyFile /etc/letsencrypt/live/SERVERNAME/privkey.pem
</VirtualHost>

<VirtualHost *:80>
    ServerName SERVERNAME
    Redirect / https://SERVERNAME
RewriteEngine on
RewriteCond %{SERVER_NAME} =SERVERNAME
RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]
</VirtualHost>

Node.js

您可以使用 http-master for Node.js 轻松地在端口 443 上设置 HTTPS 代理,以将流量代理到 GitLab Workhorse。 http-master 构建于 node-http-proxy 之上。

HTTPS/SSL

更改 GitLab 配置

修改 /etc/webapps/gitlab/shell.yml,使您的 GitLab 站点的 URL 以 https:// 开头。 修改 /etc/webapps/gitlab/gitlab.yml,使 https: 设置为 true

Let's Encrypt

为了验证您的 URL,Let's Encrypt 进程将尝试通过类似 your.domain.name/.well-known/acme-challenge/a_long_id 的 URL 访问您的 GitLab 服务器。 因此,您需要确保对 .well-known 子目录的请求不会代理到 GitLab Workhorse。 这可以使用 Certbot 的 “webroot” 方法轻松完成,有关详细信息,请参阅 Certbot#Webroot

防火墙

如果您想通过 iptables 防火墙直接访问您的 Gitlab 安装,您可能需要调整端口和网络地址

# iptables -A tcp_inbound -p TCP -s 192.168.1.0/24 --destination-port 80 -j ACCEPT

如果您在路由器后面,请不要忘记将此端口转发到正在运行的 GitLab 服务器主机,如果您想允许 WAN 访问。

注意: 在完成安装并设置 root 密码之前,不建议允许从 localhost 以外的主机访问 GitLab。 请参阅 #启动并测试 GitLab

启动并测试 GitLab

确保 PostgreSQLRedis 正在运行并且设置正确。

然后 启动/启用 gitlab.target

现在通过访问 https://127.0.0.1https://127.0.0.1:port 测试您的 GitLab 实例,其中 port 是您的 Web 服务器监听的端口号。 您应该会看到创建密码的提示

username: root
password: You will be prompted to create one on your first visit.

有关故障排除,请参阅 #故障排除/var/log/gitlab/ 目录中的日志文件。

更新时升级数据库

手动方法

更新 gitlab 软件包后,需要升级数据库

$ cd /usr/share/webapps/gitlab
$ sudo -u gitlab $(cat environment | xargs) bundle exec rake db:migrate

之后,重新加载重启 gitlab-sidekiq.servicegitlab-puma.servicegitlab-workhorse.servicegitlab-gitaly.service

自动方法

您可以创建 pacman hooks 以在 GitLab 软件包更新时自动执行数据库升级。 创建以下三个文件,不要忘记使 shell 脚本 可执行

/etc/pacman.d/hooks/05-gitlab-pre.hook
[Trigger]
Operation = Upgrade
Type = Package
Target = gitlab

[Action]
Description = Stopping gitlab services
When = PreTransaction
Exec = /usr/bin/systemctl stop gitlab-gitaly.service gitlab-mailroom.service gitlab-puma.service gitlab-sidekiq.service gitlab-workhorse.service
/etc/pacman.d/hooks/99-gitlab-post.hook
[Trigger]
Operation = Upgrade
Type = Package
Target = gitlab

[Action]
Description = Migrating GitLab database and starting services
When = PostTransaction
Exec = /etc/pacman.d/scripts/gitlab-migrate-database.sh
/etc/pacman.d/scripts/gitlab-migrate-database.sh
#!/bin/sh

cd "/usr/share/webapps/gitlab"
sudo -u gitlab $(cat environment | xargs) bundle exec rake db:migrate

# The hook runs after 30-systemd-daemon-reload.hook so another systemctl daemon-reload is not necessary.
systemctl start gitlab.target

高级配置

基本 SSH

完成基本安装后,为用户设置 SSH 访问。 下面描述了 OpenSSH 的配置。 其他 SSH 客户端和服务器 将需要不同的修改。

有关添加用户 SSH 密钥的技巧,GitLab 网站上对此过程进行了详细记录。 您可以查看 /var/lib/gitlab/log/gitlab-shell.log 中的管理员日志,以确认用户 SSH 密钥是否已正确提交。 在幕后,GitLab 将这些密钥添加到其 /var/lib/gitlab/.ssh/authorized_keys 中的 authorized_keys 文件中。

测试密钥的常用方法(例如 ssh -T git@your_server)需要一些额外的配置才能正常工作。 除了其他一些更改之外,还必须将 /etc/webapps/gitlab/gitlab.yml 中配置的用户(默认情况下为 gitlab)添加到服务器的 sshd 配置文件中

/etc/ssh/sshd_config
PubkeyAuthentication   yes
AuthorizedKeysFile     %h/.ssh/authorized_keys

如果您的 /etc/ssh/sshd_config 包含 AllowUsers 选项,则应将 gitlab 用户添加到列表中

/etc/ssh/sshd_config
AllowUsers gitlab other users...

更新配置文件后,重启 sshd.service

测试用户 SSH 密钥(可选添加 -v 以查看额外信息)

$ ssh -T gitlab@your_server

自定义 SSH 连接

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

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

您还需要更改 /etc/webapps/gitlab/gitlab.yml 文件中相应的选项(例如 ssh_user、ssh_host、admin_uri)。

从 GitLab 发送电子邮件

GitLab 可以使用本地 邮件传输代理(通过 sendmail)或使用 SMTP 发送电子邮件。

要使用 sendmail,请编辑 /etc/webapps/gitlab/smtp_settings.rb 并注释掉所有行。 假设本地邮件传输代理已正确配置,则邮件传递应该无需在 GitLab 中进行任何进一步配置即可工作。

要使用 SMTP,请根据您的邮件服务器在 smtp_settings.rb 中配置选项。 例如,要通过 Gmail 发送

/etc/webapps/gitlab/smtp_settings.rb
if Rails.env.production?
  Gitlab::Application.config.action_mailer.delivery_method = :smtp

  ActionMailer::Base.delivery_method = :smtp
  ActionMailer::Base.smtp_settings = {
    address:              'smtp.gmail.com',
    port:                 587,
    domain:               'gmail.com',
    user_name:            'username@gmail.com',
    password:             'application password',
    authentication:       'plain',
    enable_starttls_auto: true
  }
end
注意: Gmail 将拒绝以此方式收到的邮件(并向您发送一封拒绝邮件)。 您将需要禁用安全身份验证(按照拒绝邮件中的链接)来解决此问题。 更安全的方法是为 username@gmail.com 启用两因素身份验证,并为此配置文件设置 应用程序专用密码

实用技巧

Rake 任务

许多设置/维护/等等任务可以通过 rake 获得。 要列出它们,请转到 Gitlab 的主目录

$ cd /usr/share/webapps/gitlab

并运行

$ sudo -u gitlab $(cat environment | xargs) bundle exec rake -T | grep gitlab
rake gitlab:app:check                         # GITLAB | Check the configuration of the GitLab Rails app
rake gitlab:backup:create                     # GITLAB | Create a backup of the GitLab system
rake gitlab:backup:restore                    # GITLAB | Restore a previously created backup
rake gitlab:check                             # GITLAB | Check the configuration of GitLab and its environment
rake gitlab:cleanup:block_removed_ldap_users  # GITLAB | Cleanup | Block users that have been removed in LDAP
rake gitlab:cleanup:dirs                      # GITLAB | Cleanup | Clean namespaces
rake gitlab:cleanup:repos                     # GITLAB | Cleanup | Clean repositories
rake gitlab:env:check                         # GITLAB | Check the configuration of the environment
rake gitlab:env:info                          # GITLAB | Show information about GitLab and its environment
rake gitlab:generate_docs                     # GITLAB | Generate sdocs for project
rake gitlab:gitlab_shell:check                # GITLAB | Check the configuration of GitLab Shell
rake gitlab:import:all_users_to_all_groups    # GITLAB | Add all users to all groups (admin users are added as owners)
rake gitlab:import:all_users_to_all_projects  # GITLAB | Add all users to all projects (admin users are added as masters)
rake gitlab:import:repos                      # GITLAB | Import bare repositories from gitlab_shell -> repos_path into GitLab project instance
rake gitlab:import:user_to_groups[email]      # GITLAB | Add a specific user to all groups (as a developer)
rake gitlab:import:user_to_projects[email]    # GITLAB | Add a specific user to all projects (as a developer)
rake gitlab:satellites:create                 # GITLAB | Create satellite repos
rake gitlab:setup                             # GITLAB | Setup production application
rake gitlab:shell:build_missing_projects      # GITLAB | Build missing projects
rake gitlab:shell:install[tag,repo]           # GITLAB | Install or upgrade gitlab-shell
rake gitlab:shell:setup                       # GITLAB | Setup gitlab-shell
rake gitlab:sidekiq:check                     # GITLAB | Check the configuration of Sidekiq
rake gitlab:test                              # GITLAB | Run all tests
rake gitlab:web_hook:add                      # GITLAB | Adds a web hook to the projects
rake gitlab:web_hook:list                     # GITLAB | List web hooks
rake gitlab:web_hook:rm                       # GITLAB | Remove a web hook from the projects
rake setup                                    # GITLAB | Setup gitlab db

备份和恢复

创建 gitlab 系统的备份

$ cd /usr/share/webapps/gitlab
$ sudo -u gitlab $(cat environment | xargs) bundle exec rake gitlab:backup:create

恢复先前创建的备份文件 /var/lib/gitlab/backups/1556571328_2019_04_29_11.10.2_gitlab_backup.tar

$ cd /usr/share/webapps/gitlab
$ sudo -u gitlab $(cat environment | xargs) bundle exec rake gitlab:backup:restore BACKUP=1556571328_2019_04_29_11.10.2
注意: 备份文件夹在 config/gitlab.yml 中设置。 GitLab 备份和恢复在此处记录:备份恢复[死链 2024-07-30 ⓘ]

启用快速 SSH 密钥查找

按照此页面中的说明启用快速 SSH 密钥查找:https://docs.gitlab.com/ee/administration/operations/fast_ssh_key_lookup.html

简而言之,编辑 /etc/ssh/sshd_config

还原按照此 wiki 完成的所有更改(或从 openssh 软件包还原 sshd_config),并且仅添加

AuthorizedKeysCommand /var/lib/gitlab/gitlab-shell/bin/gitlab-shell-authorized-keys-check gitlab %u %k
AuthorizedKeysCommandUser gitlab

最后 重启 sshd.service

Rails 控制台

Rails 控制台可用于直接与 GitLab 交互。 有关详细信息,请参阅 [3]

要访问 Rails 控制台

$ cd /usr/share/webapps/gitlab
$ sudo -u gitlab $(cat environment | xargs) bundle exec rails console

从这里,您可以排除故障或执行管理任务,例如 重置用户密码

故障排除

HTTPS 不是绿色(gravatar 未使用 https)

Redis 缓存 gravatar 图像,因此如果您使用 http 访问过 GitLab,然后启用了 https,则 gravatar 将加载不安全的图像。 您可以通过执行以下操作来清除缓存

$ cd /usr/share/webapps/gitlab
$ sudo -u gitlab $(cat environment | xargs) bundle exec rake cache:clear

以 gitlab 用户身份。

更新后出错

从 AUR 更新软件包后,数据库迁移和资产更新有时会失败。 如果简单的重启不起作用,这些步骤可能会解决问题。

首先,移动到 gitlab 安装目录。

$ cd /usr/share/webapps/gitlab

如果每个 gitlab 页面都给出 500 错误,则数据库迁移和资产可能已过时。 如果不是,请跳过此步骤。

$ sudo -u gitlab $(cat environment | xargs) bundle exec rake db:migrate

如果 gitlab 一直在等待部署完成,则资产可能尚未重新编译。

$ sudo -u gitlab $(cat environment | xargs) bundle exec rake gitlab:assets:clean gitlab:assets:compile cache:clear

最后,重启 gitlab-puma.servicegitlab-sidekiq.servicegitlab-workhorse.service

GitLab Puma 无法访问非默认仓库目录

如果在 /home 中设置了自定义仓库存储目录,请禁用 gitlab-puma.service 中的 ProtectHome=true 参数(请参阅 systemd#Drop-in 文件gitlab.com 上的相关论坛帖子)。

无法连接到 Gitaly

有时,Gitaly 服务不会启动,导致 GitLab 无法连接到 Gitaly。 解决方案很简单:启动 gitlab-gitaly.service

无法通过 SSH 连接

本文或本节正在考虑删除。

原因: /usr/share/webapps/gitlab-shell/bin/gitlab-shell 是默认 shell。 本节仅与之前将 shell 更改为 /usr/share/webapps/gitlab-shell/bin/gitlab-shell-ruby 的人相关。(在 Talk:GitLab 中讨论)

如果使用 ssh 的 git 操作(-T、pull、clone 等)失败,请尝试更改 shell

# usermod -s /usr/share/webapps/gitlab-shell/bin/gitlab-shell gitlab

CSS 或样式问题

如果您在使用样式和 CSS 时遇到任何问题,您可以尝试编辑 /usr/share/webapps/gitlab/config/environments/production.rb 并更改

 # Disable Rails's static asset server (Apache or nginx will already do this)
 config.public_file_server.enabled = false

 # Disable Rails's static asset server (Apache or nginx will already do this)
 config.public_file_server.enabled = true

服务器不支持推送选项

如果您收到类似 fatal: the receiving end does not support push options 的错误,您可能需要在服务器上为 GitLab Git 用户 (gitlab) 启用它。 这可以在 gitconfig 中完成

/etc/webapps/gitlab-shell/.gitconfig
[receive]
         advertisePushOptions = true

或者,可以使用以下命令进行设置

$ sudo -u gitlab -H git config --global receive.advertisePushOptions true

参见