温馨提示×

centos gitlab如何离线装

小樊
57
2026-10-05 20:02:32
栏目: 智能运维

在 CentOS 上离线安装 GitLab,核心思路是:
在一台能联网的机器上下载 RPM 包及其依赖 → 拷贝到目标机器 → 离线安装。

下面以 GitLab CE(社区版) 为例,适用于 CentOS 7 / 8(Rocky / Alma 同理)。


一、准备环境(目标机器 & 下载机器)

1. 系统要求

  • CentOS 7 x86_64(推荐)
  • 至少 4GB 内存(2GB 也能跑,但容易 OOM)
  • 已关闭或放通防火墙(或后续配置)

二、在「能联网的机器」下载 GitLab RPM 及依赖

方式一(推荐):用 yumdownloader 下载完整依赖

1. 安装工具

yum install -y yum-utils

2. 添加 GitLab 官方源

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

3. 下载 GitLab 及所有依赖

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/

四、在「离线 CentOS」安装 GitLab

1. 安装依赖(如果有)

cd /opt/gitlab-offline
yum localinstall -y *.rpm

或单独安装 GitLab:

rpm -ivh gitlab-ce-*.rpm

2. 配置 GitLab

vi /etc/gitlab/gitlab.rb

修改:

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

或 IP:

external_url 'http://192.168.1.100'

3. 初始化 GitLab

gitlab-ctl reconfigure

⏳ 第一次会比较慢(5–15 分钟)


4. 启动 & 查看状态

gitlab-ctl start
gitlab-ctl status

五、访问 GitLab

浏览器访问:

http://服务器IP

首次登录:

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

⚠️ 24 小时后该文件会被删除


六、常见问题

1. 端口冲突(80/8080)

external_url 'http://IP:8080'
nginx['listen_port'] = 8080

2. 内存不足

编辑:

unicorn['worker_processes'] = 2
postgresql['shared_buffers'] = "256MB"

3. 离线机器缺依赖

在联网机器执行:

yum install --downloadonly --downloaddir=/opt/deps 依赖名

七、离线升级(后续)

# 下载新版本 rpm
yumdownloader gitlab-ce
# 离线机器
rpm -Uvh gitlab-ce-new.rpm
gitlab-ctl reconfigure

如果你愿意,我可以:

  • 给你 具体版本 RPM 下载链接
  • 写 一键离线安装脚本
  • 帮你做 GitLab + Nginx + HTTPS 内网方案

你用的是 CentOS 几?GitLab CE 还是 EE?

0 踩