温馨提示×

GitLab在CentOS上卡怎么办

小樊
43
2026-07-08 08:54:15
栏目: 智能运维

CentOS 上 GitLab 卡顿/变慢 是比较常见的问题,通常不是单一原因。下面按 排查顺序 + 解决方案 给你一个实用清单,适合生产环境快速定位。


一、先确认是不是“真卡”

先区分是 GitLab 慢 还是 服务器本身慢

top
htop
free -h
df -h

重点关注:

  • ✅ CPU 是否长期 > 80%
  • ✅ 内存是否几乎被吃满
  • ✅ 磁盘是否满(/var/opt/gitlab 最常见)

二、最常见原因 & 解决方案

1️⃣ 内存不足(最常见)

GitLab 非常吃内存,官方建议:

用户规模 最低内存
少量使用 8GB
团队使用 16GB
CI/CD 多 32GB+

检查

free -h

解决

关闭不必要的服务(强烈推荐)

编辑:

sudo vim /etc/gitlab/gitlab.rb

关闭 Prometheus / CI Runner(如果不用):

prometheus_monitoring['enable'] = false
gitlab_ci_runner['enable'] = false

然后:

sudo gitlab-ctl reconfigure
sudo gitlab-ctl restart

2️⃣ Swap 没开(CentOS 常见)

内存不够但没 Swap,系统直接卡死。

查看

swapon -s

创建 Swap(示例 4G)

sudo dd if=/dev/zero of=/swapfile bs=1M count=4096
sudo chmod 600 /swapfile
sudo mkswap /swapfile
sudo swapon /swapfile

开机自动挂载:

echo '/swapfile swap swap defaults 0 0' | sudo tee -a /etc/fstab

3️⃣ PostgreSQL 卡(数据库慢)

表现:

  • 页面能打开但点不动
  • Git push 慢

查看

gitlab-ctl tail postgresql

优化(小内存机器)

postgresql['shared_buffers'] = "256MB"
postgresql['max_connections'] = 100

然后:

gitlab-ctl reconfigure

4️⃣ Sidekiq / Puma 队列堆积

表现:

  • 页面加载慢
  • 后台任务不执行

查看

gitlab-ctl status
gitlab-rake gitlab:sidekiq:status

重启

gitlab-ctl restart sidekiq
gitlab-ctl restart puma

5️⃣ GitLab 版本太老

老版本在 CentOS 7 上特别容易卡。

查看版本

cat /opt/gitlab/version-manifest.txt

升级(推荐)

yum update gitlab-ee
gitlab-ctl reconfigure

⚠️ 升级前一定 备份

gitlab-backup create

6️⃣ CentOS 7 本身老化(重要)

⚠️ CentOS 7 已于 2024-06-30 EOL

  • 内核老
  • systemd / fs 性能差
  • GitLab 官方已不再强烈推荐

✅ 建议迁移到:

  • Rocky Linux 8/9
  • AlmaLinux
  • Ubuntu 22.04

三、快速“急救”方案(立即见效)

如果你现在就想让 GitLab 快一点:

# 重启所有服务
gitlab-ctl restart

# 清理缓存
gitlab-rake cache:clear

# 清理日志
gitlab-ctl cleanup

四、确认 GitLab 推荐配置

运行:

gitlab-rake gitlab:env:info

我可以帮你 直接看输出并判断哪里卡


五、如果你愿意,我可以更精准帮你

你可以直接贴出这些信息(打码即可):

  1. free -h
  2. top 前 10 行
  3. cat /etc/gitlab/gitlab.rb | grep -v "^#"
  4. GitLab 版本
  5. 是否开启 CI/CD

我可以直接给你 最小化内存优化配置

0