温馨提示×

centos如何离线装gitlab

小樊
42
2026-09-08 22:16:39
栏目: 智能运维

CentOS 离线环境中安装 GitLab,核心思路是:在能联网的机器上下载好 RPM 包及其依赖,再拷贝到离线机器上安装。下面给你一套最常用、最稳妥的方案


一、准备环境(离线机 & 联网机)

  • 离线机:CentOS 7 / 8(推荐 7)
  • 联网机:同版本 CentOS(用来下载包)
  • 架构一致(x86_64)

二、在联网机器下载 GitLab RPM 及依赖

1️⃣ 下载 GitLab RPM 包

以 GitLab CE 为例(社区版):

wget https://mirrors.tuna.tsinghua.edu.cn/gitlab-ce/yum/el7/gitlab-ce-16.11.3-ce.0.el7.x86_64.rpm

可到清华镜像查看版本:
https://mirrors.tuna.tsinghua.edu.cn/gitlab-ce/yum/el7/


2️⃣ 使用 yum 下载依赖(关键)

yum install --downloadonly --downloaddir=./gitlab_rpms gitlab-ce-16.11.3-ce.0.el7.x86_64.rpm

如果提示找不到,可先:

yum install yum-plugin-downloadonly

3️⃣ 打包拷贝到离线机

tar zcvf gitlab_rpms.tar.gz gitlab_rpms

U 盘 / scp / 其他手段拷贝到离线机。


三、离线机安装 GitLab

1️⃣ 解压

tar zxvf gitlab_rpms.tar.gz
cd gitlab_rpms

2️⃣ 本地安装(自动解决依赖)

yum localinstall -y *.rpm

或(老版本):

rpm -ivh *.rpm --nodeps --force

推荐用 yum localinstall


四、配置 GitLab

1️⃣ 修改配置文件

vi /etc/gitlab/gitlab.rb

常见修改:

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

或 IP:

external_url 'http://192.168.1.100'

2️⃣ 使配置生效(必须)

gitlab-ctl reconfigure

⏳ 第一次会比较慢(几分钟)


3️⃣ 启动服务

gitlab-ctl start

查看状态:

gitlab-ctl status

五、访问 GitLab

浏览器访问:

http://服务器IP

首次登录:

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

六、常见问题

❓ 80 / 8080 端口被占用

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

❓ 内存不足

GitLab 至少需要 4G 内存

❓ 想离线装 EE(企业版)

替换 RPM 源即可:

https://packages.gitlab.com/gitlab/gitlab-ee

七、一键总结(核心命令)

# 联网机
yum install --downloadonly --downloaddir=./gitlab_rpms gitlab-ce-xxx.rpm

# 离线机
yum localinstall -y *.rpm
gitlab-ctl reconfigure
gitlab-ctl start

如果你愿意,我可以:

  • ✅ 给你 CentOS 7 / 8 具体版本 RPM 链接
  • ✅ 写 离线安装脚本
  • ✅ 教你 GitLab + Nginx + HTTPS 离线配置

告诉我你的 CentOS 版本 & GitLab 版本需求 即可。

0