温馨提示×

CentOS如何快速部署GitLab

小樊
47
2026-08-29 19:54:47
栏目: 智能运维

CentOS(7/8/Stream) 上快速部署 GitLab,最推荐、最省事的方式是使用 GitLab 官方 Omnibus 包。下面是生产可用、步骤最少的完整方案。


一、准备环境(建议)

  • CPU:4 核+
  • 内存:8 GB+(GitLab 较吃内存)
  • 磁盘:至少 50 GB
  • 系统:CentOS 7 / 8 / Stream
  • 网络:能访问外网(或配置国内镜像)

二、关闭 SELinux(推荐)

setenforce 0
sed -i 's/^SELINUX=.*/SELINUX=disabled/' /etc/selinux/config

三、安装依赖

yum install -y curl policycoreutils openssh-server openssh-clients
systemctl enable sshd
systemctl start sshd

四、添加 GitLab 官方仓库(关键)

✅ CentOS 7 / 8 通用

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

如果你只需要 CE(社区版),把 gitlab-ee 换成 gitlab-ce


五、安装 GitLab

方式 1️⃣:直接安装(默认域名)

EXTERNAL_URL="http://gitlab.example.com" yum install -y gitlab-ee

✅ 推荐方式(使用本机 IP)

EXTERNAL_URL="http://你的服务器IP" yum install -y gitlab-ee

安装过程约 3–10 分钟


六、初始化 GitLab

gitlab-ctl reconfigure

✅ 成功后你会看到类似:

gitlab Reconfigured!

七、访问 GitLab

浏览器访问:

http://服务器IP

第一次登录

  • 用户名:root
  • 密码:
cat /etc/gitlab/initial_root_password

⚠️ 密码只显示一次,建议立即修改


八、常用管理命令

gitlab-ctl status        # 查看状态
gitlab-ctl restart      # 重启
gitlab-ctl stop         # 停止
gitlab-ctl tail         # 查看日志

九、配置防火墙(如开启)

firewall-cmd --permanent --add-service=http
firewall-cmd --permanent --add-service=https
firewall-cmd --reload

十、可选优化(强烈建议)

1️⃣ 修改 GitLab 配置

vim /etc/gitlab/gitlab.rb

常见修改:

external_url 'http://gitlab.example.com'
gitlab_rails['time_zone'] = 'Asia/Shanghai'

修改后执行:

gitlab-ctl reconfigure

2️⃣ 内存优化(低配服务器)

 sidekiq['max_concurrency'] = 10
 puma['worker_processes'] = 2
 puma['min_threads'] = 1
 puma['max_threads'] = 2

十一、使用国内镜像(国内服务器)

如果官方源慢,可切换为清华源:

vim /etc/yum.repos.d/gitlab_gitlab-ee.repo

替换为:

https://mirrors.tuna.tsinghua.edu.cn/gitlab-ee/

十二、版本选择建议

场景 推荐
企业/生产 GitLab EE
个人/学习 GitLab CE
内网 关闭 HTTPS,使用 HTTP

十三、总结(最快命令合集)

yum install -y curl
curl https://packages.gitlab.com/install/repositories/gitlab/gitlab-ee/script.rpm.sh | bash
EXTERNAL_URL="http://$(hostname -I | awk '{print $1}')" yum install -y gitlab-ee
gitlab-ctl reconfigure

如果你需要:

  • Docker 部署 GitLab
  • HTTPS + 域名
  • GitLab Runner + CI/CD
  • 国产化 / 离线安装

告诉我你的 CentOS 版本 + 使用场景,我可以给你定制方案。

0