Debian系统下可从操作系统层与GitLab组件层两处入手,对CPU、内存、文件句柄、进程数等进行限制与优化,兼顾稳定性与性能。
一 操作系统层限制
-
文件句柄与进程数
- 临时生效:
- 查看/调整:ulimit -n(文件描述符)、ulimit -u(进程数)
- 永久生效(推荐在 /etc/security/limits.conf 或 /etc/security/limits.d/*.conf 中配置,例如对 git 用户或 root):
- root soft nofile 65536
- root hard nofile 65536
- root soft nproc 8192
- root hard nproc 8192
- 说明:修改后需重新登录会话或在 systemd 服务中显式声明才能继承;Debian 上常见做法是结合 limits.conf 与 systemd 的 LimitNOFILE/LimitNPROC 使用。
-
内核与系统级参数
- 提高系统可打开文件数:编辑 /etc/sysctl.conf,设置 fs.file-max=65536(或更高),执行 sysctl -p 生效。
- 降低 swap 倾向以减少抖动:设置 vm.swappiness=10(根据负载与内存大小微调)。
二 GitLab组件层关键参数
三 监控与故障排查
-
日志定位
- 组件日志:/var/log/gitlab/puma/.log、/var/log/gitlab/sidekiq/.log
- 全局错误:/var/log/gitlab/gitlab-error.log
- 服务异常(频繁重启、端口冲突、依赖异常)优先查看对应日志与服务状态。
-
资源与告警
- 建议启用内置监控(Prometheus + Grafana)观察 CPU、内存、队列、延迟等关键指标,结合阈值告警及时调参。
四 快速配置示例
-
场景:8GB 内存单机,中等并发
-
思路:Puma 按 CPU 核心数配置,Sidekiq 与 DB 连接池适度下调,Redis 设置内存上限,启用 Sidekiq 内存保护
-
/etc/security/limits.conf(或 limits.d/gitlab.conf)
- root soft nofile 65536
- root hard nofile 65536
- root soft nproc 8192
- root hard nproc 8192
-
/etc/gitlab/gitlab.rb(示例值,需按实际调整)
- puma[‘worker_processes’] = 4
- puma[‘min_threads’] = 2
- puma[‘max_threads’] = 8
- sidekiq[‘concurrency’] = 10
- sidekiq[‘max_memory_killer’][‘enable’] = true
- gitlab_rails[‘db_pool’] = 20
- redis[‘maxmemory’] = “2gb”
-
使配置生效
- sudo gitlab-ctl reconfigure
- 如仅调整 Puma:sudo gitlab-ctl restart puma
-
可选系统级优化
- /etc/sysctl.conf:fs.file-max=65536;vm.swappiness=10;执行 sysctl -p 生效。