温馨提示×

centos gitlab咋优化

小樊
41
2026-09-30 00:59:12
栏目: 智能运维

在 CentOS 上优化 GitLab,通常从系统资源、GitLab 自身配置、数据库与缓存、存储与网络、日常维护几个方面入手。下面给你一套实用优化清单(适用于 GitLab CE/EE,CentOS 7/8)。


一、系统层面优化(CentOS)

1. 关闭无用服务

systemctl disable --now postfix
systemctl disable --now firewalld   # 如有外部防火墙可关

(保留必要安全策略)

2. 调整内核参数(高并发)

编辑 /etc/sysctl.conf:

net.core.somaxconn = 1024
net.ipv4.tcp_max_syn_backlog = 8192
vm.swappiness = 10

执行:

sysctl -p

3. 文件描述符

ulimit -n 65535

在 /etc/security/limits.conf:

* soft nofile 65535
* hard nofile 65535

二、GitLab 核心配置优化

配置文件:/etc/gitlab/gitlab.rb

1. 根据内存调整 Sidekiq / Puma

示例(4G 内存):

puma['worker_processes'] = 2
puma['worker_timeout'] = 60

sidekiq['concurrency'] = 10

8G 以上:

puma['worker_processes'] = 4
sidekiq['concurrency'] = 20

修改后:

gitlab-ctl reconfigure
gitlab-ctl restart

三、数据库 & 缓存优化

1. PostgreSQL(GitLab 内置)

postgresql['shared_buffers'] = "512MB"
postgresql['max_connections'] = 200

2. Redis

redis['maxmemory'] = "512mb"
redis['maxmemory_policy'] = "allkeys-lru"

四、存储优化(非常重要)

1. 仓库放独立磁盘

git_data_dirs({
  "default" => {
    "path" => "/data/gitlab/git-data"
  }
})

2. 开启 Gitaly 优化

gitaly['configuration'] = {
  concurrency: {
    'rpc' => 16
  }
}

五、Web & 访问优化

1. 使用 HTTPS + 压缩

nginx['enable'] = true
nginx['client_max_body_size'] = '250m'

2. 反向代理(推荐)

前端用 Nginx / Caddy,关闭 GitLab 自带 Nginx:

nginx['enable'] = false

六、定期维护(防止越来越慢)

1. 清理任务

gitlab-rake gitlab:cleanup:orphan_job_artifact_files
gitlab-rake gitlab:cleanup:project_uploads

2. 自动备份但别太频繁

gitlab_rails['backup_keep_time'] = 604800

七、监控与问题定位

gitlab-ctl status
gitlab-rails console
top -c
df -h

推荐开启:

  • Prometheus(GitLab 自带)
  • Grafana

八、最低配置建议

规模 CPU 内存
小团队 2核 4G
中型 4核 8G
企业 8核+ 16G+

如果你愿意,可以告诉我:

  • GitLab 版本
  • CentOS 版本
  • 当前内存/CPU
  • 主要卡在哪(页面慢 / 构建慢 / clone 慢)

我可以给你针对性配置文件。

0 踩