温馨提示×

如何在CentOS安装GitLab

小樊
55
2026-08-29 19:52:46
栏目: 智能运维

在 CentOS 上安装 GitLab(社区版 GitLab CE)最常用、最稳定的方式是使用 官方 Omnibus 安装包。下面分别给出 CentOS 7 和 CentOS 8/Stream 的推荐做法,并包含常见配置与排错说明。


一、安装前准备

1️⃣ 系统要求(建议)

项目 最低 推荐
CPU 2 核 4 核
内存 4 GB 8 GB+
磁盘 20 GB 50 GB+

⚠️ GitLab 对内存要求较高,2 GB 内存容易卡死。


2️⃣ 关闭或配置防火墙

systemctl stop firewalld
systemctl disable firewalld

或使用 firewalld 放行 80 / 443 端口。


二、CentOS 7 安装 GitLab(最常用)

1️⃣ 安装依赖

yum install -y curl policycoreutils openssh-server openssh-clients

启动 SSH:

systemctl enable sshd
systemctl start sshd

2️⃣ 添加 GitLab 官方仓库

curl https://packages.gitlab.com/install/repositories/gitlab/gitlab-ce/script.rpm.sh | bash

3️⃣ 安装 GitLab CE

yum install -y gitlab-ce

安装过程较慢,请耐心等待。


4️⃣ 配置 GitLab

编辑配置文件:

vim /etc/gitlab/gitlab.rb

修改访问地址(非常重要):

external_url 'http://gitlab.example.com'

如果是公网服务器,替换为:

external_url 'http://你的IP或域名'

5️⃣ 初始化 GitLab

gitlab-ctl reconfigure

首次初始化需要 5~10 分钟。


6️⃣ 访问 GitLab

浏览器访问:

http://服务器IP

首次登录会要求设置 root 密码。


三、CentOS 8 / Stream 安装 GitLab

⚠️ CentOS 8 已 EOL,推荐使用 Rocky / AlmaLinux,但 GitLab 仍支持。

1️⃣ 安装依赖

dnf install -y curl policycoreutils openssh-server

2️⃣ 添加仓库并安装

curl https://packages.gitlab.com/install/repositories/gitlab/gitlab-ce/script.rpm.sh | bash
dnf install -y gitlab-ce

3️⃣ 配置并初始化

gitlab-ctl reconfigure

四、常用 GitLab 管理命令

# 查看状态
gitlab-ctl status

# 启动 / 停止 / 重启
gitlab-ctl start
gitlab-ctl stop
gitlab-ctl restart

# 查看日志
gitlab-ctl tail

# 查看配置
gitlab-rake gitlab:env:info

五、配置 HTTPS(可选但推荐)

方式一:使用 Let’s Encrypt

external_url 'https://gitlab.example.com'

letsencrypt['enable'] = true
letsencrypt['auto_renew'] = true

重新配置:

gitlab-ctl reconfigure

六、常见问题排查

❌ 502 Whoops

原因:

  • 内存不足
  • 端口被占用
  • 服务未完全启动

解决:

free -h
gitlab-ctl restart

❌ 无法访问

检查:

ss -lntp | grep 80
gitlab-ctl status

七、是否需要 Docker 版本?

方式 适合
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

如果你愿意,我可以:

  • ✅ 给你 国内镜像加速方案
  • ✅ 教你 迁移 GitLab 数据
  • ✅ 配置 SMTP 邮件
  • ✅ 从 GitHub / Gitee 迁移仓库

只要告诉我你的 CentOS 版本 + 使用场景 即可。

0 踩