在 Linux 环境下加速 GitLab(自建或 gitlab.com) 通常可以从 网络、Git 配置、GitLab 服务本身、CI/CD 几个层面来做。下面按常见场景给你一个实用清单。
# 开启长连接
git config --global http.version HTTP/1.1
git config --global http.postBuffer 524288000
# 复用连接(大幅提速)
git config --global http.keepAlive true
git@gitlab.com:user/repo.git
SSH 通常比 HTTPS 快,尤其在弱网环境。
git clone --depth=1 git@gitlab.com:user/repo.git
git clone -b main --single-branch git@gitlab.com:user/repo.git
# git 走代理
git config --global http.proxy http://127.0.0.1:7890
git config --global https.proxy http://127.0.0.1:7890
# 取消
git config --global --unset http.proxy
# 使用公共 DNS
/etc/resolv.conf
nameserver 8.8.8.8
nameserver 1.1.1.1
# /etc/sysctl.conf
net.core.rmem_max=16777216
net.core.wmem_max=16777216
net.ipv4.tcp_window_scaling=1
sysctl -p
# gitlab.rb
gitaly['configuration'] = {
cgroups: true
}
GitLab 对磁盘 IO 极其敏感。
gitlab_rails['gitlab_ci_enabled'] = false # 不用 CI 就关
grafana['enable'] = false
prometheus['enable'] = false
gitlab-runner 缓存cache:
paths:
- node_modules/
gitlab-runner register
比共享 Runner 快很多。
test:
parallel: 4
git config --global -l
ping gitlab.com
curl -I https://gitlab.com
如果你能说明:
我可以给你更精准的加速方案。