在 CentOS 上离线安装 GitLab,核心思路是:
在一台能联网的机器上下载 RPM 包及其依赖 → 拷贝到目标机器 → 离线安装。
下面以 GitLab CE(社区版) 为例,适用于 CentOS 7 / 8(Rocky / Alma 同理)。
yum install -y yum-utils
curl https://packages.gitlab.com/install/repositories/gitlab/gitlab-ce/script.rpm.sh | bash
mkdir -p /opt/gitlab-offline
cd /opt/gitlab-offline
yumdownloader --resolve --destdir=. gitlab-ce
会下载:
- gitlab-ce-*.rpm
- 所有依赖(openssl、postfix、policycoreutils 等)
直接从官网下载单个 RPM:
wget https://packages.gitlab.com/gitlab/gitlab-ce/packages/el/7/gitlab-ce-16.5.1-ce.0.el7.x86_64.rpm/download.rpm
mv download.rpm gitlab-ce.rpm
⚠️ 不推荐,容易缺依赖
使用 U 盘 / 内网 SCP:
scp -r /opt/gitlab-offline root@离线服务器IP:/opt/
cd /opt/gitlab-offline
yum localinstall -y *.rpm
或单独安装 GitLab:
rpm -ivh gitlab-ce-*.rpm
vi /etc/gitlab/gitlab.rb
修改:
external_url 'http://gitlab.example.com'
或 IP:
external_url 'http://192.168.1.100'
gitlab-ctl reconfigure
⏳ 第一次会比较慢(5–15 分钟)
gitlab-ctl start
gitlab-ctl status
浏览器访问:
http://服务器IP
首次登录:
rootcat /etc/gitlab/initial_root_password
⚠️ 24 小时后该文件会被删除
external_url 'http://IP:8080'
nginx['listen_port'] = 8080
编辑:
unicorn['worker_processes'] = 2
postgresql['shared_buffers'] = "256MB"
在联网机器执行:
yum install --downloadonly --downloaddir=/opt/deps 依赖名
# 下载新版本 rpm
yumdownloader gitlab-ce
# 离线机器
rpm -Uvh gitlab-ce-new.rpm
gitlab-ctl reconfigure
如果你愿意,我可以:
你用的是 CentOS 几?GitLab CE 还是 EE?