在 Linux 上给 GitLab(包括 GitLab CE/EE 自托管)做“限速”,常见有几种层面,取决于你想限什么:
GitLab 默认使用 Nginx 作为反向代理。
编辑:
vim /etc/gitlab/gitlab.rb
添加或修改:
nginx['enable'] = true
# 限制单连接速度为 1MB/s
nginx['custom_gitlab_server_config'] = "
limit_rate 1m;
"
或者更细一点(针对 clone / push):
nginx['custom_gitlab_server_config'] = "
location ~ ^/.*\.git/ {
limit_rate 1m;
}
"
gitlab-ctl reconfigure
gitlab-ctl restart nginx
SSH 本身不支持“限速”,但可以用 tc(Linux 流量控制)。
示例(限制 eth0 出口 5Mbps):
tc qdisc add dev eth0 root tbf rate 5mbit burst 32kbit latency 400ms
⚠️ 这是全局限速,影响所有流量。
编辑 gitlab.rb:
gitlab_rails['rate_limiter_enabled'] = true
# 每个 IP 每分钟最多 600 次请求
gitlab_rails['rack_attack_git_basic_auth'] = {
'enabled' => true,
'ip_whitelist' => [],
'maxretry' => 10,
'findtime' => 60,
'bantime' => 3600
}
然后:
gitlab-ctl reconfigure
在 .gitlab-ci.yml 中:
variables:
GIT_DEPTH: "1"
减少 clone 体积。
# 限制整台机器出口 10Mbps
wondershaper eth0 10240 10240
limit_ratetc / wondershaper如果你能说清楚:
我可以给你更精确的配置。