Gitlab 简明教程
GitLab - Installation
你可以通过安装 Git 版本控制系统和在 GitLab 网站中创建用户帐户来在不同的操作系统中安装 GitLab 执行器。
You can install the GitLab runner on different operating systems, by installing Git versioning system and creating user account in the GitLab site.
Git 是一个用于以下用途的版本控制系统:
Git is a version control system used for −
-
Handling the source code history of projects
-
Tracking changes made to files
-
Handling small and large projects with speed and efficiency
-
To collaborate with other developers on different projects
GitLab 是一个基于 Git 的平台,它通过创建用于管理代码的私有和公共仓库,来为软件开发周期提供远程访问 Git 仓库并提供帮助。
GitLab is a Git-based platform provides remote access to Git repositories and helpful for software development cycle by creating private and public repositories for managing the code.
GitLab 支持不同类型的操作系统,例如 Windows、Ubuntu、Debian、CentOS、open SUSE 和 Raspberry Pi 2。在本章中,我们将讨论如何在 Windows 和 Ubuntu 操作系统上安装 GitLab——
GitLab supports different types of operating systems such as Windows, Ubuntu, Debian, CentOS, open SUSE and Raspberry Pi 2. In this chapter, we will discuss about how to install GitLab on Windows and Ubuntu operating systems −
Installation of GitLab on Windows:
Step 1 − 首先在你的系统中创建一个名为“GitLab-Runner”的文件夹。例如,你可以把它创建到 C 盘中,即 C:\GitLab-Runner。
Step 1 − First create a folder called 'GitLab-Runner' in your system. For instance, you can create in C drive as C:\GitLab-Runner.
Step 2 − Now download the binary for x86 or amd64 and copy it in the folder created by you. Rename the downloaded binary to gitlab-runner.exe.
Step 3 − 打开命令提示符,并导航到你的创建文件夹。现在输入下面的命令,并按 Enter。
Step 3 − Open the command prompt and navigate to your created folder. Now type the below command and press enter.
C:\GitLab-Runner>gitlab-runner.exe register
Step 4 − 运行上面的命令之后,它会要求你输入 GitLab-CI 协调员 URL。
Step 4 − After running the above command, it will ask to enter the gitlab-ci coordinator URL.
Please enter the gitlab-ci coordinator URL (e.g. https://gitlab.com/):
https://gitlab.com
Step 5 − 为 runner 输入 gitlab-ci 令牌。
Step 5 − Enter the gitlab-ci token for the runner.
Please enter the gitlab-ci token for this runner:
xxxxx
-
To get the token, login to your GitLab account −

-
Now go to your project −

-
Click on the CI/CD option under Settings tab and expand the Runners Settings option.

-
Under Runners Settings section, you will get the token as shown in the image below −

Step 6 − 为 runner 输入 gitlab-ci 描述。
Step 6 − Enter the gitlab-ci description for the runner.
Please enter the gitlab-ci description for this runner:
[Admin-PC]: Hello GitLab Runner
Step 7 − 它会要求你为 runner 输入 gitlab-ci 标记。
Step 7 − It will ask to enter the gitlab-ci tags for the runner.
Please enter the gitlab-ci tags for this runner (comma separated):
tag1, tag2
你稍后可以在 GitLab 的用户界面里更改这些标记。
You can change these tags in the GitLab’s user interface later.
Step 8 − 你可以通过将 Runner 锁定到当前项目,将其设置为 true 值。
Step 8 − You can lock the Runner to current project by setting it to true value.
Whether to lock the Runner to current project [true/false]:
[true]: true
完成以上步骤后,你将看到“注册 runner……成功”的成功消息。
After completing above steps, you will get the successful message as 'Registering runner… succeeded'.
Step 9 − 现在输入 Runner 执行器来构建项目。
Step 9 − Now enter the Runner executor for building the project.
Please enter the executor: parallels, shell, docker+machine, kubernetes, docker-
ssh+machine, docker, docker-ssh, ssh, virtualbox:
docker
我们使用选择器为“docker”,它能创建构建环境,并轻松管理依赖项,以开发项目。
We have used the selector as 'docker' which creates build environment and manages the dependencies easily for developing the project.
Step 10 − 接下来它将要求为 docker 选择器设置默认图像。
Step 10 − Next it will ask for default image to be set for docker selector.
Please enter the default Docker image (e.g. ruby:2.1):
alpine:latest
Step 11 − 完成以上步骤后,它将显示“Runner 注册成功”的信息。下图将描述以上命令的工作流程——
Step 11 − After completing the above steps, it will display the message as 'Runner registered successfully'. The below image will describe the working flow of above commands −

Step 12 − 现在转到你的项目、点击设置部分中的 CI/CD 选项,你将看到该项目的已激活 Runner。
Step 12 − Now go to your project, click on the CI/CD option under Settings section and you will see the activated Runners for the project.

如以下所示,你可以在 GitLab-Runner 文件夹中的 config.toml 文件中看到 GitLab Runner 配置 −
You can see the GitLab Runner configuration in the config.toml file under the GitLab-Runner folder as shown below −
concurrent = 1
check_interval = 0
[[runners]]
name = "Hello GitLab Runner"
url = "https://gitlab.com"
token = "40ceed29eec231fa9e306629cae4d7"
executor = "docker"
[runners.docker]
tls_verify = false
image = "alpine:latest"
privileged = false
disable_cache = false
volumes = ["/cache"]
shm_size = 0
[runners.cache]
Installation of GitLab on Ubuntu
可以通过提供不同服务来运行 GitLab 的 Omnibus 软件包将 GitLab 安装在 Ubuntu 系统上。Omnibus 软件包提供 GitLab 的必要组件、建立配置和项目元数据,这些组件和元数据可以在用户系统中使用。
The GitLab can be installed on Ubuntu system by using Omnibus package which provides different services to run GitLab. The Omnibus package provides necessary components of GitLab, establishes the configurations and project metadata which can be used in user’s system.
以下步骤介绍如何在 Ubuntu 上安装 GitLab −
The following steps describe installation of GitLab on Ubuntu −
Step 1 − 首先,使用 SSH(安全外壳)登录到你的 GitLab 服务器。
Step 1 − First, login to your GitLab server using SSH (Secure Shell).
Step 2 − 接下来,下载 Omnibus 软件包 −
Step 2 − Next, download the Omnibus package −
wget https://downloads-packages.s3.amazonaws.com/ubuntu-14.04/gitlab-ce_7.10.4~omnibus-1_amd64.deb

Step 3 − 安装 Postfix −
Step 3 − Install the postfix −
sudo apt-get install postfix
Postfix 是一个用来发送电子邮件通知的开源邮件传输代理。
Postfix is a open source mail transfer agent used to deliver the email notifications.

Step 4 − 在安装 Postfix 时,它会询问安装类型;然后选择 Internet Site 选项。接下来,它会显示 Postfix 配置以及系统邮件名称,如图像中所示 −
Step 4 − While installing Postfix, it will ask type of installation; then select the Internet Site option. Next, it will show Postfix configuration along with the system mail name as shown in the image −

Step 5 − 安装 dpkg(debian 系统的软件包管理器)以管理已安装的软件包 −
Step 5 − Install the dpkg (package manager for debian system) for managing the installed packages −
sudo dpkg -i gitlab-ce_7.10.4~omnibus-1_amd64.deb

Step 6 − 为了让更改生效,你需要使用以下命令重新配置 GitLab −
Step 6 − To have the changes take effect, you need to reconfigure the GitLab by using the below command −
sudo gitlab-ctl reconfigure
Step 7 − 通过使用以下命令检查 GitLab 服务的状态 −
Step 7 − Check the status of the GitLab services by using below command −
sudo gitlab-ctl status
如果你想从源代码中安装 GitLab,那么要在服务器上安装一些依赖项,并且需要使用 PostgreSQL 来设置数据库。这在 Environment setup 章中进行了说明。你可以安装协调器来构建 Web 界面和控制构建实例。有关更多信息,你可以查看 Installation of Coordinator 章。
If you want to install GitLab from the source, then install some dependencies on the server and need to setup the database by using the PostgreSQL. It is described in the Environment setup chapter. You can install the coordinator to build a web interface and control build instances. For more information, you can check the Installation of Coordinator chapter.