温馨提示×

ubuntu gitlab怎么优化

小樊
44
2026-10-04 20:16:57
栏目: 智能运维

下面从系统层面、GitLab 自身配置、日常使用三个维度,给你一份在 Ubuntu 上优化 GitLab 的实用清单(适用于自托管 GitLab CE/EE)。


一、系统层面优化(Ubuntu)

1. 服务器硬件建议

  • CPU:4 核起步(CI 多的话 8 核+)
  • 内存:
    • 最小 4GB(不推荐)
    • 推荐 8GB+(GitLab + Sidekiq + PostgreSQL)
  • 磁盘:
    • 使用 SSD
    • 单独挂载 /var/opt/gitlab

2. 系统参数优化

# 增大文件描述符
ulimit -n 65535

/etc/security/limits.conf

* soft nofile 65535
* hard nofile 65535

/etc/sysctl.conf

vm.swappiness=10
net.core.somaxconn=1024
sysctl -p

3. 使用国内镜像(国内服务器)

  • apt 源
  • GitLab 安装源
  • Docker 镜像(如果用 runner)

二、GitLab 自身配置优化

配置文件:

/etc/gitlab/gitlab.rb

修改后执行:

gitlab-ctl reconfigure

1. 限制并发,防止 OOM

sidekiq['concurrency'] = 10
puma['worker_processes'] = 2
puma['min_threads'] = 4
puma['max_threads'] = 8

2. 关闭不用的功能

gitlab_rails['lfs_enabled'] = false   # 不用 LFS 可关
prometheus['enable'] = false          # 不需要监控可关
grafana['enable'] = false

3. 数据库优化(PostgreSQL)

postgresql['shared_buffers'] = "2GB"
postgresql['work_mem'] = "16MB"
postgresql['max_connections'] = 200

4. 仓库存储优化

  • 定期清理:
gitlab-rake gitlab:cleanup:project_uploads
gitlab-rake gitlab:cleanup:orphan_job_artifact_files
  • 启用 Gitaly 优化(默认已启用)

三、GitLab Runner 优化(CI/CD)

1. 使用 Docker Executor

[[runners]]
  executor = "docker"
  [runners.docker]
    tls_verify = false
    image = "alpine"
    privileged = false

2. 限制并发

concurrent = 4

3. 使用缓存

cache:
  paths:
    - node_modules/

四、日常维护优化

1. 自动备份

0 2 * * * /opt/gitlab/bin/gitlab-backup create

2. 定期清理旧备份

find /var/opt/gitlab/backups -mtime +7 -delete

3. 监控资源

gitlab-ctl status
htop
df -h

五、如果你遇到具体问题

可以告诉我:

  • GitLab 版本
  • Ubuntu 版本
  • 是卡顿 / 内存爆 / CI 慢 / 访问慢?
  • 是否用 Docker

我可以给你针对性优化方案。

0 踩