极狐GitLab私有化部署指南
参考资料
修订记录
日期 内容 2022.10.15 创建文档 2023.09.20 增加16.1版本上传许可证的方式 2023.11.14 增加Runner安装示例 2023.11.24 增加安全扫描配置说明 2024.02.23 删除CentOS 8/Ubuntu 18.04支持的相关内容 2024.05.09 增加许可证密钥的导入方法,增加关闭AutoDevOps的方法 2024.10.11 更新EXTERNAL_URL的配置,增加HTTPS协议配置的方法
1. 环境资源
| 用户规模 | 0~500 | 500~1000 |
|---|---|---|
| 操作系统 | Ubuntu 20.04 ; CentOS 7 ; Debian 9/10/11 ; AlmaLinux 8 / RHEL | |
| 节点数量 | GitLab-Server * 1 ; GitLab-Runner * N (N>=0) | |
| 浏览器支持 | Mozilla FireFox ; Google Chrome ; Chromium ; MicroSoft Edge ; Apple Safari | |
| CPU(核) | 8C+ | 16C+ |
| 内存(GB) | 16G+ | 32G+ |
| 磁盘(GB) | 500G 或 按需 ; SSD(不可使用NFS) | 1T 或 按需 ; SSD(不可使用NFS) |
2. 在线安装
2.1 安装最新版本
访问官方网站,通过官方Linux安装包方式安装:
GitLab最新版下载安装_GitLab中文免费版-极狐GitLab中文官方网站

2.2 安装指定版本
-
安装依赖、配置极狐GitLab 软件源镜像。
1 2 3 4 5 6 7 8 9 10 11 12 13 14# Ubuntu sudo apt-get update sudo apt-get install -y curl openssh-server ca-certificates tzdata perl #CentOS sudo yum install -y curl policycoreutils-python openssh-server perl sudo systemctl enable sshd sudo systemctl start sshd sudo firewall-cmd --permanent --add-service=http sudo firewall-cmd --permanent --add-service=https sudo systemctl reload firewalld # 配置下载源 curl -fsSL https://get.gitlab.cn | /bin/bash -
查询极狐GitLab版本,如
16.11.2-jh.0。1 2 3 4 5 6 7 8 9# Ubuntu sudo apt policy gitlab-jh ## 或者 sudo apt madison gitlab-jh # RHEL/CentOS 7 sudo yum list --showduplicates gitlab-jh # RHEL/AlmaLinux 8 sudo dnf list --showduplicates gitlab-jh -
安装指定版本极狐GitLab。
1 2 3 4 5 6 7 8 9# Ubuntu apt install gitlab-jh=16.11.2-jh.0 # RHEL/CentOS 7 yum install gitlab-jh-16.11.2-jh.0 # RHEL/AlmaLinux 8 dnf install gitlab-jh-16.11.2-jh.0 # 不指定版本号安装最新版本 apt install gitlab-jh -
默认配置下需确保22、80、443端口可对外提供访问。
3. 离线安装
-
从官方仓库下载指定版本的Linux安装包到本地,并传入离线环境中。
-
安装极狐GitLab。
1 2 3 4# Ubuntu / Debian dpkg -i <gitlab离线安装包,如gitlab-jh_15.1.0-jh.0_amd64>.deb # CentOS 7 rpm -ivh <gitlab离线安装包>.rpm -
默认配置下需确保22、80、443端口可对外提供访问。
4. 初始密码
安装完成后,极狐GitLab将随机生成一个密码并存储在/etc/gitlab/initial_root_password文件中(出于安全原因,24 小时后会自动删除),使用cat /etc/gitlab/initial_root_password命令获取root用户的初始密码。
5. 修改访问地址
编辑/etc/gitlab/gitlab.rb,修改external_url为GitLab的访问地址:
-
如果要设置为IP,一般只支持HTTP协议,如
http://192.168.x.x,测试阶段推荐用该方式 -
如果要设置为HTTP协议的域名,需要将该域名的DNS解析到GitLab所在服务器IP,如
http://gitlab.example.com -
如果要设置为HTTPS协议的域名,有3种方式
-
使用GitLab自带的Let’s Encrypt自动申请SSL证书:
- 服务器可以访问外网
- GitLab使用默认的80/443端口
- 已经设置好DNS
- 修改
external_url为该域名,如https://gitlab.example.com
-
使用CA机构提供的SSL证书:参考文档进行配置
-
使用自签SSL证书:会引起其他组件、系统与GitLab通讯认证问题,处理较为复杂,不推荐使用
-
-
修改完成执行以下命令:
1gitlab-ctl reconfigure
6. 修改显示语言
显示语言是按个人用户进行设置:
-
参照下图进入“用户中心——偏好设置”

-
下拉找到“本地化——语言”,选择指定的语言并保存

-
刷新网页生效
7. 关闭AutoDevOps
不论您是否需要使用GitLab CI,都建议您关闭AutoDevOps功能,避免产生莫名的流水线错误。
- 在“管理中心——CICD——持续集成和部署”取消勾选“所有项目默认使用Auto DevOps流水线”,然后保存更改。

8. 上传许可证
-
root/管理员账号登录极狐GitLab。
-
参照下图在“管理中心——设置——通用——添加许可证”中上传许可证:

-
如果不能识别并上传
.gitlab-license文件,可以用记事本打开许可证文件,复制其中的内容并参照下图在“管理中心——设置——通用——添加许可证——输入许可证密钥”粘贴:
9. 安装GitLab Runner(可选)
9.1 GitLab Runner简介
如果需要使用GitLab CI实现CI/CD流水线、启用GitLab内置的代码质量扫描、启用GitLab DevSecOps能力,需要安装GitLab Runner。
GitLab Runner类似Jenkins Agent/Slave,部署在需要执行CI/CD、质量/安全扫描的服务器上,与GitLab Server通讯,接收GitLab Server下发的流水线任务并执行相关的脚本。
其中,启用GitLab内置的代码质量扫描和DevSecOps能力仅支持Docker或K8S类型的Runner,且Runner所在的服务器需要有访问外网的权限(GitLab代码质量扫描和DevSecOps能力需访问外网的漏洞库以实现实时更新。支持配置网络出口白名单,也支持离线环境部署,但较为复杂,一般通过极狐GitLab专业服务来交付,测试期间不建议考虑这些方式)。

9.2 GitLab Runner安装示例
GitLab Runner可配置在:
- 实例级:即该Runner可被整个实例的所有项目使用。
- 群组级:即该Runner可被该群组下的所有项目使用。
- 项目级:即仅支持被该项目使用。
以在实例级安装Docker类型的Runner为例:
-
在需要安装GitLab Runner的服务器上安装好Docker
-
进入GitLab“管理中心——CI/CD——Runner”,点击“新建实例runner”。

-
设置“标签”,用于区分不同的Runner,点击“创建runner”。

-
在安装好Docker的服务器上执行以下命令。注意,该安装方式将Runner的配置文件存放在宿主机的
/srv/gitlab-runner/config目录。1 2 3 4docker run -d --name gitlab-runner --restart always \ -v /srv/gitlab-runner/config:/etc/gitlab-runner \ -v /var/run/docker.sock:/var/run/docker.sock \ gitlab/gitlab-runner:latest -
注册Runner:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17docker exec -it gitlab-runner # Enter the GitLab instance URL (for example, https://gitlab.com/): # 输入第2步中,步骤1命令中的url,如:https://gitlab.jhgitlab.com # Enter the registration token: # 输入第2步中,步骤1命令中的token,如:glrt-hRsg_XR5vwgndRM2ofid # Enter a name for the runner. This is stored only in the local config.toml file: # 输入Runner的名称,如:docker # Enter an executor: custom, shell, ssh, docker+machine, instance, kubernetes, docker, docker-windows, parallels, virtualbox, docker-autoscaler: # 输入Runner的类型,这里是:docker # Enter the default Docker image (for example, ruby:2.7): # 输入默认镜像,如:ubuntu:22.04 # Runner registered successfully. Feel free to start it, but if it's running already the config should be automatically reloaded! # 验证Runner docker exec -it gitlab-runner verify # Verifying runner... is valid runner=hRsg_XR5v -
注册Runner成功

-
如果希望该Runner运维未指定标签(Tags)的任务(Job),需要将Runner中的“运行未打标签的作业”打勾,并“保存更改”

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20# 某项目的流水线脚本 .gitlab-ci.yml stages: - build - deploy # 没有指定Tags,只能运行在勾选了“运行未打标签的作业”的Runner下 build-job: stage: build script: - echo "Compiling the code..." - echo "Compile complete." # 指定Tags为docker,只能运行在标签是“docker”的Runner下 deploy-job: stage: deploy tags: - docker script: - echo "Deploying application..." - echo "Application successfully deployed."
9.3 GitLab Runner安装方式
其他安装方式如下:
- Linux(物理机、虚拟机):https://docs.gitlab.cn/runner/install/linux-repository.html
- MacOS(物理机、虚拟机): https://docs.gitlab.cn/runner/install/osx.html
- Windows(物理机、虚拟机): https://docs.gitlab.cn/runner/install/windows.html
- Docker:https://docs.gitlab.cn/runner/install/docker.html
- K8S:https://docs.gitlab.cn/runner/install/kubernetes.html









