HMK's blog

保持思考|00后|等待


  • Home
  • Archive
  • Tags
  •   

© 2026 Hekang

Theme Typography by Makito

Proudly published with Hexo

gitlab

Posted at 2026-07-08 devops 

Gitlab

GitLab是什么?

  • Devops生命周期工具
  • Git仓库管理
  • Wiki文档管理
  • Issue跟踪
  • CI/CD

GitLab安装部署

下载二进制包

1
root@gitlab:~# wget  https://mirrors.tuna.tsinghua.edu.cn/gitlab-ce/apt/packages.gitlab.com/gitlab/gitlab-ce/ubuntu/noble/pool/main/g/gitlab-ce/gitlab-ce_19.0.3-ce.0_amd64.deb

安装

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
root@gitlab:~# dpkg -i gitlab-ce_19.0.3-ce.0_amd64.deb
Selecting previously unselected package gitlab-ce.
(Reading database ... 75522 files and directories currently installed.)
Preparing to unpack gitlab-ce_19.0.3-ce.0_amd64.deb ...
Unpacking gitlab-ce (19.0.3-ce.0) ...
Setting up gitlab-ce (19.0.3-ce.0) ...
It looks like GitLab has not been configured yet; skipping the upgrade script.
. ..
:c: ,cc'
:ccc: 'cccc.
:ccccc, cccccc
.ccccccc :cccccc:
cccccccc: .cccccccc'
:ccccccccc;..............'cccccccccc'
cccccccccccccccccccccccccccccccccccccc'
:ooolccccccccccccccccccccccccccccccllooo
ooooooollccccccccccccccccccccccclooooooo
;ooooooooollcccccccccccccccccloooooooool
oooooooooooolccccccccccccloooooooooooo.
.ooooooooooooolcccccclloooooooooooo;
cooooooooooooolllooooooooooooo.
loooooooodxkkxddoooooooo.
.ooodxkkkkkkkkxdooo;
.kkkkkkkkkkkk:
;kkkkkkx
:d

Thank you for installing GitLab!
GitLab was unable to detect a valid hostname for your instance.
Please configure a URL for your GitLab instance by setting `external_url`
configuration in /etc/gitlab/gitlab.rb file.
Then, you can start your GitLab instance by running the following command:
sudo gitlab-ctl reconfigure

For a comprehensive list of configuration options please see the Omnibus GitLab readme
https://gitlab.com/gitlab-org/omnibus-gitlab/blob/master/README.md

Help us improve the installation experience, let us know how we did with a 1 minute survey:
https://gitlab.fra1.qualtrics.com/jfe/form/SV_6kVqZANThUQ1bZb?installation=omnibus&release=19-0

配置 编辑/etc/gitlab/gitlab.rb 可以看见默认的域名配置。如果测试使用可以默认使用该域名,不在做其他配置。

external_url ‘http://gitlab.devops.com‘

重新配置

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
gitlab-ctl reconfigure


获取密码
root@gitlab:~# cat /etc/gitlab/initial_root_password
# WARNING: This password is only valid if ALL of the following are true:
# • You set it manually via the GITLAB_ROOT_PASSWORD environment variable
# OR the gitlab_rails['initial_root_password'] setting in /etc/gitlab/gitlab.rb
# • You set it BEFORE the initial database setup (typically during first installation)
# • You have NOT changed the password since then (via web UI or command line)
#
# If this password doesn't work, reset the admin password using:
# https://docs.gitlab.com/security/reset_user_password/#reset-the-root-password

Password: Z6F1MYQ5FB67xchikT5e0eCE7qsPAEVe1Mcshz8nZOM=

# NOTE: This file is automatically deleted after 24 hours on the next reconfigure run.

服务运行控制

1
2
3
###启动服务
gitlab-ctl start
###重启服务

image-20260706153710-qijblri

docker部署

1
2
3
4
5
6
7
8
9
10
11

root@gitlab:~# mkdir -p /data/devops05/gitlab/{config,logs,data}
root@gitlab:~# chmod +x -R /data/devops05/gitlab
docker run -itd --name gitlab \
-p 443:443 \
-p 8076:8076 \
--restart always \
-v /data/devops05/gitlab/config:/etc/gitlab \
-v /data/devops05/gitlab/logs:/var/lib/gitlab \
-v /data/devops05/gitlab/data:/var/opt/gitlab \
gitlab/gitlab-ce:19.0.1

GitLab组织配置

  • Namespaces 用户空间
  • Members 组织空间
  • Groups 子组空间

‍

Manage project 管理项目

  • Create a project 创建项目
  • Import a project 导入项目
  • Git push 上传项目

image-20260706165650-sbs784m

创建项目,权限集成如果上层是private 那么只能创建private的project

‍

‍

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
[root@jenkins demotest]# git config  user.email "yangxu@example.com"
[root@jenkins demotest]# git config user.name "yangxu"
[root@jenkins demotest]# git commit -m 'yangxu'
[main 071fbb1] yangxu
1 file changed, 2 insertions(+)
create mode 100644 yangxu.sh
[root@jenkins demotest]# git push
warning: push.default is unset; its implicit value is changing in
Git 2.0 from 'matching' to 'simple'. To squelch this message
and maintain the current behavior after the default changes, use:

git config --global push.default matching

To squelch this message and adopt the new behavior now, use:

git config --global push.default simple

See 'git help config' and search for 'push.default' for further information.
(the 'simple' mode was introduced in Git 1.7.11. Use the similar mode
'current' instead of 'simple' if you sometimes use older versions of Git)

Counting objects: 4, done.
Delta compression using up to 2 threads.
Compressing objects: 100% (2/2), done.
Writing objects: 100% (3/3), 310 bytes | 0 bytes/s, done.
Total 3 (delta 0), reused 0 (delta 0)
To git@gitlab.devops.com:root/demotest.git
3e286a2..071fbb1 main -> main
[root@jenkins demotest]#
[root@jenkins demotest]# git config user.email "yangxu@example.com"
[root@jenkins demotest]# git config user.name "yangxu"
[root@jenkins demotest]# git commit -m 'yangxu'
[main 071fbb1] yangxu
1 file changed, 2 insertions(+)
create mode 100644 yangxu.sh
[root@jenkins demotest]# git push
warning: push.default is unset; its implicit value is changing in
Git 2.0 from 'matching' to 'simple'. To squelch this message
and maintain the current behavior after the default changes, use:

git config --global push.default matching

To squelch this message and adopt the new behavior now, use:

git config --global push.default simple

See 'git help config' and search for 'push.default' for further information.
(the 'simple' mode was introduced in Git 1.7.11. Use the similar mode
'current' instead of 'simple' if you sometimes use older versions of Git)

Counting objects: 4, done.
Delta compression using up to 2 threads.
Compressing objects: 100% (2/2), done.
Writing objects: 100% (3/3), 310 bytes | 0 bytes/s, done.
Total 3 (delta 0), reused 0 (delta 0)
To git@gitlab.devops.com:root/demotest.git
3e286a2..071fbb1 main -> main
[root@jenkins demotest]#

image-20260706172234-ejioabx

Project visibility

  • public 公开
  • Internal 内部
  • Private 私密

GitLab用户管理

  • 用户基本操作
  • 用户角色管理

界面基本操作

GitLab系统管理

  • 版本更新
  • Webhook触发器
  • 邮件消息通知

Jenkins 创建Pineline

Triggers - 触发远程构建

1
2
3
4
5
root@gitlab:~# curl -u devops:devops "http://192.168.11.100:8080/job/gitlab-webhook-test/build?token=devops"
root@gitlab:~#


或者 /buildWithParameters?token=TOKEN_NAME

GitLab -Admin - Settings - Network - Outbound-request

√ Allow requests to the local network from webhooks and integrations

403 Jenkins 安装 Strict Crumb Issuer

‍

邮箱消息通知

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
cat /etc/gitlab/gitlab.rb
gitlab_rails['smtp_enable'] = true
gitlab_rails['smtp_address'] = "smtp.qq.com"
gitlab_rails['smtp_port'] = 465
gitlab_rails['smtp_user_name'] = "2733885168@qq.com"
gitlab_rails['smtp_password'] = "****"
gitlab_rails['smtp_domain'] = "smtp.qq.com"
gitlab_rails['smtp_authentication'] = "login"
gitlab_rails['smtp_enable_starttls_auto'] = false
gitlab_rails['smtp_tls'] = true
#gitlab_rails['smtp_pool'] = false

###! **Can be: 'none', 'peer', 'client_once', 'fail_if_no_peer_cert'**
###! Docs: http://api.rubyonrails.org/classes/ActionMailer/Base.html
# gitlab_rails['smtp_openssl_verify_mode'] = 'none'

# gitlab_rails['smtp_ca_path'] = "/etc/ssl/certs"
# gitlab_rails['smtp_ca_file'] = "/etc/ssl/certs/ca-certificates.crt"

### Email Settings

gitlab_rails['gitlab_email_enabled'] = true

###! If your SMTP server does not like the default 'From: gitlab@gitlab.example.com'
###! can change the 'From' with this setting.
gitlab_rails['gitlab_email_from'] = '2733885168@qq.com'
gitlab_rails['gitlab_email_display_name'] = 'GitLabAdmin'



gitlab-ctl stop
gitlab-ctl reconfigure

测试邮件

1
2
3
4
5
6
7
8
9
10
11
root@gitlab:~# gitlab-rails console
--------------------------------------------------------------------------------
Ruby: ruby 3.3.11 (2026-03-26 revision 1f2d15125a) [x86_64-linux]
GitLab: 19.0.3 (8b35963a1a5) FOSS
GitLab Shell: 14.51.0
PostgreSQL: 17.8
------------------------------------------------------------[ booted in 37.74s ]
Loading production environment (Rails 7.2.3.1)
gitlab(prod)> Notify.test_email('hemingkang0509@gmail.com','testemail','gitlab email test').deliver_now
=> #<Mail::Message:1034580, Multipart: false, Headers: <Date: Tue, 07 Jul 2026 03:22:37 +0000>, <From: GitLabAdmin <2733885168@qq.com>>, <Reply-To: GitLabAdmin <noreply@gitlab.devops.com>>, <To: hemingkang0509@gmail.com>, <Message-ID: <6a4c70fd19370_1042433044256e@gitlab.mail>>, <Subject: testemail>, <MIME-Version: 1.0>, <Content-Type: text/html; charset=UTF-8>, <Content-Transfer-Encoding: 7bit>, <Auto-Submitted: auto-generated>, <X-Auto-Response-Suppress: All>>

image-20260707112419-h7prjs5

GitLab CI/CD 简介

  • 开源
  • 无缝集成
  • 构建节点可扩展
  • 持续集成
  • 持续部署

GitLab Runner 配置

  • GitLab Runner 是运行PipeLine的节点;
  • GitLabRunner 的类型: Shared,Group,Specific;
  • 安装GitLabRunner
  • 注册GitLabRunner
  • 配置GitLabRunner

Install a Runner

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# Download the binary for your system
sudo curl -L --output /usr/local/bin/gitlab-runner https://gitlab-runner-downloads.s3.amazonaws.com/latest/binaries/gitlab-runner-linux-amd64

# Give it permission to execute
sudo chmod +x /usr/local/bin/gitlab-runner

# Create a GitLab Runner user
sudo useradd --comment 'GitLab Runner' --create-home gitlab-runner --shell /bin/bash

# Install and run as a service
sudo gitlab-runner install --user=gitlab-runner --working-directory=/home/gitlab-runner
sudo gitlab-runner start

# If using a `deb` package based distribution
curl -s https://packages.gitlab.com/install/repositories/runner/gitlab-runner/script.deb.sh | sudo bash
apt install -y gitlab-runner

# If using an `rpm` package based distribution
curl -s https://packages.gitlab.com/install/repositories/runner/gitlab-runner/script.rpm.sh | sudo bash
dnf install -y gitlab-runner

注册Runner

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
[root@jenkins ~]#  sudo gitlab-runner register --url http://192.168.11.101/ --registration-token QeKcJ-yxDGaer1dsDmTn
sudo: gitlab-runner: command not found
[root@jenkins ~]# gitlab-runner register --url http://192.168.11.101/ --registration-token QeKcJ-yxDGaer1dsDmTn
Runtime platform arch=amd64 os=linux pid=5262 revision=24b9b726 version=19.1.1
Running in system-mode.

Enter the GitLab instance URL (for example, https://gitlab.com/):
[http://192.168.11.101/]:
Enter the registration token:
[QeKcJ-yxDGaer1dsDmTn]:
Enter a description for the runner:
[jenkins]: build01
Enter tags for the runner (comma-separated):
build,go,linux,maven
Enter optional maintenance note for the runner:

WARNING: Support for registration tokens and runner parameters in the 'register' command has been deprecated in GitLab Runner 15.6 and will be replaced with support for authentication tokens. For more information, see https://docs.gitlab.com/ci/runners/new_creation_workflow/
Registering runner... succeeded correlation_id=01KWXHZT05WF96RB6T1J9R667F runner=QeKcJ-yxD runner_name=build01
Enter an executor: kubernetes, ssh, parallels, custom, instance, docker, virtualbox, shell, docker-windows, docker-autoscaler, docker+machine:
shell
Runner registered successfully. Feel free to start it, but if it's running already the config should be automatically reloaded!

Configuration (with the authentication token) was saved in "/etc/gitlab-runner/config.toml"

验证:
gitlab-runner verify

gitlab-runner list

image-20260707140501-5c8gsj7

命令行注册

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
[root@jenkins ~]# gitlab-runner register \
--non-interactive \
--url "http://192.168.11.101" \
--registration-token "QeKcJ-yxDGaer1dsDmTn" \
--executor "shell" \
--description "build02" \
--tag-list "k8s,go" \
--run-untagged="true" \
--access-level="not_protected"
Runtime platform arch=amd64 os=linux pid=14461 revision=24b9b726 version=19.1.1
Running in system-mode.

WARNING: Support for registration tokens and runner parameters in the 'register' command has been deprecated in GitLab Runner 15.6 and will be replaced with support for authentication tokens. For more information, see https://docs.gitlab.com/ci/runners/new_creation_workflow/
Registering runner... succeeded correlation_id=01KWXKZ1VYBZVPKWMMED9RD8W8 runner=QeKcJ-yxD runner_name=build02
Runner registered successfully. Feel free to start it, but if it's running already the config should be automatically reloaded!

取消注册

1
2
3
4
5
6
7
8
9
10
11
[root@jenkins ~]# gitlab-runner list
Runtime platform arch=amd64 os=linux pid=21729 revision=24b9b726 version=19.1.1
Listing configured runners ConfigFile=/etc/gitlab-runner/config.toml
build01 Executor=shell Token=glrtr-ZV6NYPY9PMq-unyE_ArD URL=http://192.168.11.101:80
[root@jenkins ~]# gitlab-runner unregister --name build01
Runtime platform arch=amd64 os=linux pid=21902 revision=24b9b726 version=19.1.1
Running in system-mode.

Unregistering runner from GitLab succeeded correlation_id=01KWXN4TEG9F841A6VKGVZ6Z19 runner=ZV6NYPY9P runner_name=build01
Updated /etc/gitlab-runner/config.toml

注册Group Runner

1
2
3
4
5
6
7
8
9
gitlab-runner register \
--non-interactive \
--url "http://192.168.11.101" \
--registration-token "GR1348941XyZhvcathqT4spzAS3yv" \
--executor "shell" \
--description "build02" \
--tag-list "k8s,go" \
--run-untagged="true" \
--access-level="not_protected"

image-20260707150008-zctuvws

project runner

1
2
3
4
5
6
7
8
9
gitlab-runner register \
--non-interactive \
--url "http://192.168.11.101" \
--registration-token "GR1348941G8yNLRS_xpcybU66kcA2" \
--executor "shell" \
--description "project runner" \
--tag-list "k8s,go" \
--run-untagged="true" \
--access-level="not_protected"

‍

Share 

 Previous post: kubevirt安装 Next post: ceph_install 

© 2026 Hekang

Theme Typography by Makito

Proudly published with Hexo