Linux 上 GitLab 占用内存高,是比较常见且“正常”的现象,主要原因在于 GitLab 不是一个单一程序,而是一整套服务集合。下面从原因 → 排查 → 优化 三个层面说明。
一个标准 GitLab(Omnibus 安装)会同时运行:
这些服务各自都会吃内存,合起来很容易 2~4GB 起步。
都会让 Gitaly + Git 瞬时占用大量内存。
GitLab 默认假设:
你有一定规模的团队在用
所以:
free -h
top
htop
sudo gitlab-ctl status
ps aux --sort=-%mem | head
常见大户:
pumasidekiqpostgresgitaly编辑:
sudo vim /etc/gitlab/gitlab.rb
puma['worker_processes'] = 2
puma['min_threads'] = 1
puma['max_threads'] = 4
重新配置:
sudo gitlab-ctl reconfigure
sidekiq['concurrency'] = 5
prometheus_monitoring['enable'] = false
postgresql['shared_buffers'] = "256MB"
postgresql['max_connections'] = 100
sudo fallocate -l 2G /swapfile
sudo mkswap /swapfile
sudo swapon /swapfile
puma['worker_processes'] = 2
sidekiq['concurrency'] = 4
prometheus_monitoring['enable'] = false
postgresql['shared_buffers'] = "256MB"
✅ 以下情况不必担心:
可以考虑替代方案:
如果你愿意,可以告诉我:
我可以直接帮你给出一套最合适的 gitlab.rb 配置。