535 字
3 分钟
GitLab(极狐)的部署和配置
2024-12-29

安装#

IMPORTANT

建议参考英文教程:https://about.gitlab.com/

Enable SSH and open firewall ports#

Terminal window
sudo systemctl enable --now ssh
sudo ufw allow 22/tcp
sudo ufw allow 80/tcp
sudo ufw allow 443/tcp
sudo ufw enable

Add the GitLab package repository#

Terminal window
sudo apt update
sudo apt install -y curl
curl "https://packages.gitlab.com/install/repositories/gitlab/gitlab-ce/script.deb.sh" | sudo bash

推荐镜像源:MirrorZ Help

Install the package#

Terminal window
sudo apt update
sudo EXTERNAL_URL="https://gitlab.example.com" apt install gitlab-ce
# or
sudo GITLAB_ROOT_EMAIL="admin@example.com" GITLAB_ROOT_PASSWORD="strongpassword" EXTERNAL_URL="https://gitlab.example.com" apt install gitlab-ce

升级#


常见问题#

从 jh 迁移到 ce 或 ee#

创建备份,备份结果在 /var/opt/gitlab/backups/

Terminal window
sudo gitlab-rake gitlab:backup:create

查询 gitlab-jh 版本,例如 17.6.0-jh

Terminal window
cat /opt/gitlab/embedded/service/gitlab-rails/VERSIO

安装指定版本的 gitlab-ce/ee:

  • 方法1:参考之前的安装过程增加软件源,并安装指定版本的 gitlab-ce:sudo apt install gitlab-ce=17.6.0
  • 方法2:从 https://packages.gitlab.com/gitlab/gitlab-ce 获取并安装指定版本的 deb 安装包

安装完成后,先修改 gitlab-ce 的版本标识符:

Terminal window
vim /opt/gitlab/embedded/service/gitlab-rails/VERSIO
# 将版本从 17.6.0 改为 17.6.0-jh,不然备份还原不了

修改完成后,使用以下指令还原:

Terminal window
sudo gitlab-rake gitlab:backup:restore BACKUP=1767071890_2025_12_30_17.6.0-jh

还原完成后,重启即可使用:

Terminal window
sudo gitlab-ctl reconfigure
sudo gitlab-ctl restart

内存占用过高#

服务器突然崩溃,参考 在内存受限的环境中运行,从6GB降低至4GB,降低了 2GB

Terminal window
sudo vim /etc/gitlab/gitlab.rb
sudo gitlab-ctl reconfigure
nginx['worker_processes'] = 2
puma['worker_processes'] = 0
sidekiq['concurrency'] = 5
postgresql['max_worker_processes'] = 2
prometheus_monitoring['enable'] = false
gitlab_rails['env'] = {
'MALLOC_CONF' => 'dirty_decay_ms:1000,muzzy_decay_ms:1000'
}
gitaly['configuration'] = {
concurrency: [
{
'rpc' => "/gitaly.SmartHTTPService/PostReceivePack",
'max_per_repo' => 3,
}, {
'rpc' => "/gitaly.SSHService/SSHUploadPack",
'max_per_repo' => 3,
},
],
cgroups: {
repositories: {
count: 2,
},
mountpoint: '/sys/fs/cgroup',
hierarchy_root: 'gitaly',
memory_bytes: 500000,
cpu_shares: 512,
},
}
gitaly['env'] = {
'MALLOC_CONF' => 'dirty_decay_ms:1000,muzzy_decay_ms:1000',
'GITALY_COMMAND_SPAWN_MAX_PARALLEL' => '2'
}

同时增加的定时重启:

Terminal window
crontab -e

每天0点重启服务器:

Terminal window
# m h dom mon dow command
00 00 * * * /sbin/shutdown -r now

添加密钥#

Terminal window
ssh-keygen
cat ~/.ssh/id_rsa.pub

手动配置 HTTPS#

官方方法#

官方方法

  1. 编辑 /etc/gitlab/gitlab.rb
external_url "https://gitlab.example.com" # 域名
letsencrypt['enable'] = false # 禁用 Let's Encrypt 集成
nginx['enable'] = true
nginx['redirect_http_to_https'] = true
nginx['ssl_certificate'] = "/etc/gitlab/ssl/gitlab.example.com.crt"
nginx['ssl_certificate_key'] = "/etc/gitlab/ssl/gitlab.example.com.key"
nginx['listen_port'] = 18080 # 换成其他空闲端口
  1. 创建 /etc/gitlab/ssl 目录并将密钥和证书复制到那里:
Terminal window
sudo mkdir -p /etc/gitlab/ssl
sudo chmod 755 /etc/gitlab/ssl
sudo cp gitlab.example.com.key gitlab.example.com.crt /etc/gitlab/ssl/
sudo chmod 600 /etc/gitlab/ssl/gitlab.example.com.*
  1. 重新加载配置
Terminal window
sudo gitlab-ctl reconfigure

使用系统的 nginx 反向代理#

Terminal window
sudo vim /etc/nginx/sites-available/gitlab
sudo ln -s /etc/nginx/sites-available/gitlab /etc/nginx/sites-enable/gitlab
sudo nginx -t
sudo service nginx reload
server {
listen 443 ssl;
listen [::]:443 ssl;
server_name gitlab.sample.com;
ssl_certificate /etc/nginx/gitlab.sample.com.pem;
ssl_certificate_key /etc/nginx/gitlab.sample.com.key;
location / {
proxy_pass http://127.0.0.1:18080;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
}
}
GitLab(极狐)的部署和配置
https://fuwari.vercel.app/posts/建站/gitlab/极狐gitlab的部署和配置/
作者
Asuwee
发布于
2024-12-29
许可协议
CC BY-NC-SA 4.0