在 CentOS 上安装 GitLab(社区版 GitLab CE)最常用、最稳定的方式是使用 官方 Omnibus 安装包。下面分别给出 CentOS 7 和 CentOS 8/Stream 的推荐做法,并包含常见配置与排错说明。
| 项目 | 最低 | 推荐 |
|---|---|---|
| CPU | 2 核 | 4 核 |
| 内存 | 4 GB | 8 GB+ |
| 磁盘 | 20 GB | 50 GB+ |
⚠️ GitLab 对内存要求较高,2 GB 内存容易卡死。
systemctl stop firewalld
systemctl disable firewalld
或使用 firewalld 放行 80 / 443 端口。
yum install -y curl policycoreutils openssh-server openssh-clients
启动 SSH:
systemctl enable sshd
systemctl start sshd
curl https://packages.gitlab.com/install/repositories/gitlab/gitlab-ce/script.rpm.sh | bash
yum install -y gitlab-ce
安装过程较慢,请耐心等待。
编辑配置文件:
vim /etc/gitlab/gitlab.rb
修改访问地址(非常重要):
external_url 'http://gitlab.example.com'
如果是公网服务器,替换为:
external_url 'http://你的IP或域名'
gitlab-ctl reconfigure
首次初始化需要 5~10 分钟。
浏览器访问:
http://服务器IP
首次登录会要求设置 root 密码。
⚠️ CentOS 8 已 EOL,推荐使用 Rocky / AlmaLinux,但 GitLab 仍支持。
dnf install -y curl policycoreutils openssh-server
curl https://packages.gitlab.com/install/repositories/gitlab/gitlab-ce/script.rpm.sh | bash
dnf install -y gitlab-ce
gitlab-ctl reconfigure
# 查看状态
gitlab-ctl status
# 启动 / 停止 / 重启
gitlab-ctl start
gitlab-ctl stop
gitlab-ctl restart
# 查看日志
gitlab-ctl tail
# 查看配置
gitlab-rake gitlab:env:info
external_url 'https://gitlab.example.com'
letsencrypt['enable'] = true
letsencrypt['auto_renew'] = true
重新配置:
gitlab-ctl reconfigure
原因:
解决:
free -h
gitlab-ctl restart
检查:
ss -lntp | grep 80
gitlab-ctl status
| 方式 | 适合 |
|---|---|
| Omnibus(推荐) | 生产环境 |
| Docker | 测试 / 快速体验 |
如需要 Docker 安装 GitLab 教程,可以告诉我。
✅ CentOS 7 + GitLab CE + Omnibus 安装
命令速览:
yum install -y curl policycoreutils openssh-server
curl https://packages.gitlab.com/install/repositories/gitlab/gitlab-ce/script.rpm.sh | bash
yum install -y gitlab-ce
gitlab-ctl reconfigure
如果你愿意,我可以:
只要告诉我你的 CentOS 版本 + 使用场景 即可。