GitLab (v16.x) 簡述及安裝部署
GitLab 介紹
GitLab 的歷史
- GitLab 最初是一個完全免費的開源軟件,根據 MIT 許可證分發。2013 年 7 月,它被分為兩個不同的版本 - GitLab CE(社區版)和 GitLab EE(企業版)。GitLab EE 處于受限許可證下,但源代碼仍然公開可見,而 GitLab CE 許可模型保持不變。2017 年,GitLab 宣布他們的代碼將在 MIT 許可證下完全開源。
為什么使用 GitLab?
-
GitLab是在集中式服務器上管理git倉庫的好方法。GitLab讓你完全控制你的倉庫或項目,并允許你免費決定它們是公開還是私有的。
-
使用 GitLab 的主要好處是它允許所有團隊成員在項目的每個階段進行協作。GitLab 提供從規劃到創建的跟蹤,幫助開發人員自動化整個 DevOps 生命周期并實現最佳結果。越來越多的開發人員開始使用 GitLab,因為它具有廣泛的功能和可用的代碼塊。
Git,GitHub 與 GitLab 的區別
-
Git是一種版本控制系統,是一種工具,用于跟蹤修改和從遠程資源推送或拉取代碼的版本控制。
-
GitHub是一個目前全球最大的基于Git實現的在線代碼倉庫托管平臺,是一個公開的、免費的服務,它要求所有的代碼(除非你有一個付費賬戶)都是公開的。任何人都可以看到你推送到GitHub的代碼,并提供改進建議。
-
GitLab是一個基于Git實現的在線代碼倉庫軟件,你可以用GitLab自己搭建一個類似于GitHub一樣的倉庫,但是GitLab有完善的管理界面和權限控制,一般用于在企業、學校等內部網絡搭建Git私服。
-
GitHub和GiLlab兩個都是基于Web的Git遠程倉庫,它們都提供了分享開源項目的平臺,為開發團隊提供了存儲、分享、發布和合作開發項目的中心化云存儲的場所。從代碼的私有性上來看,GitLab 是一個更好的選擇。但是對于開源項目而言,GitHub 依然是代碼托管的首選。
特點
-
GitLab免費托管您的(私有)軟件項目。
-
GitLab是一個管理 Git 倉庫的平臺。
-
GitLab提供免費的公共和私有倉庫、問題跟蹤和維基。
-
GitLab是一個建立在Git之上的用戶友好的網絡界面層,它提高了使用Git的速度。
-
GitLab提供了自己的 持續集成 (CI)系統來管理項目,并提供用戶界面和GitLab的其他功能。
優勢
-
GitLab提供了 GitLab社區版 ,用戶可以定位他們的代碼在哪個服務器上。
-
GitLab免費提供無限數量的私有和公共倉庫。
-
Snippet 部分可以分享一個項目中的少量代碼,而不是分享整個項目。
缺點
-
在推送和提取倉庫時,它沒有GitHub快。
-
GitLab的界面在從一個頁面切換到另一個頁面時需要時間。
先決條件
建議使用至少具有以下各項的服務器:
- CPU 4 核是建議的最小核心數,最多支持500個用戶。
- 內存 4 GB RAM 是所需的最小內存大小,最多支持500個用戶。
GitLab 還要求文件系統準備好用于存儲 Git 倉庫和各種其它文件。
請注意,如果您使用 NFS(網絡文件系統),文件將通過網絡傳輸,根據實現,該網絡需要打開端口 111 和 2049
GitLab 架構圖

Gitlab組件:
-
repository:代碼庫,可以是硬盤或 分布式文件系統。 -
Nginx:Web 入口。 -
gitlab-workhorse:輕量級反向代理服務器,可以處理一些大的HTTP請求(磁盤上的 CSS、JS 文件、文件上傳下載等),處理 Git Push/Pull 請求,處理到Rails 的連接會反向代理給后端的unicorn(修改由 Rails 發送的響應或發送給 Rails 的請求,管理 Rails 的長期 WebSocket 連接等)。 -
gitlab-shell:用于 SSH 交互,而不是 HTTP。gitlab-shell 通過 Redis 與 Sidekiq 進行通信,并直接或通過 TCP 間接訪問 Unicorn。用于處理Git命令和修改authorized keys列表。 -
Unicorn:Gitlab 自身的 Web 服務器(Ruby Web Server),包含了 Gitlab 主進程,負責處理快速/一般任務,與 Redis 一起工作,配置參考:CPU核心數 + 1 = unicorn workers數量。工作內容包括:-
通過檢查存儲在 Redis 中的用戶會話來檢查權限。
-
為 Sidekiq 制作任務。
-
從倉庫(warehouse)取東西或在那里移動東西。
-
-
Redis:緩存每個客戶端的sessions和后臺隊列,負責分發任務。Redis需求的存儲空間很小,大約每個用戶25KB。 -
Gitaly:后臺服務,專門負責訪問磁盤以高效處理 gitlab-shell 和 gitlab-workhorse 的git 操作,并緩存耗時操作。所有的 git 操作都通過 Gitaly 處理,并向 GitLab web 應用程序提供一個 API,以從 git(例如 title, branches, tags, other meta data)獲取屬性,并獲取 blob(例如 diffs,commits,files)。 -
Sidekiq:后臺核心服務,可以從redis隊列中提取作業并對其進行處理。后臺作業允許GitLab通過將工作移至后臺來提供更快的請求/響應周期。Sidekiq任務需要來自Redis。 -
數據庫(PostgreSQL/MySQL):包含以下信息:-
repository 中的數據(元數據,issue,合并請求 merge request 等)。
-
可以登錄 Web 的用戶(權限)。
-
-
mail_room:處理郵件請求?;貜?GitLab 發出的郵件時,GitLab 會調用此服務處理Sidekiq、Unicorn 和 GitLab-shell 的任務 。 -
logrotate:日志文件管理,切割。
組件操作命令
# nginx
gitlab-ctl start|stop|restart|status nginx
# unicorn
gitlab-ctl start|stop|restart|status unicorn
# sidekiq
gitlab-ctl start|stop|restart|status sidekiq
# postgresql
gitlab-ctl start|stop|restart|status postgresql
# redis
gitlab-ctl start|stop|restart|status redis
# gitlab
gitlab-ctl start|stop|restart|status|reconfigure
# supervisor
systemctl start|stop|restart|status gitlab-runsvdir.service
GitLab部署過程
準備環境
[root@GitServer ~]# cat /etc/redhat-release
CentOS Linux release 7.9.2009 (Core)
[root@GitServer ~]# uname -r
3.10.0-1160.el7.x86_64
[root@GitServer ~]# setenforce 0
[root@GitServer ~]# sed -i.bak '7s/enforcing/disabled/' /etc/selinux/config
[root@GitServer ~]# systemctl stop firewalld
[root@GitServer ~]# systemctl status firewalld
● firewalld.service - firewalld - dynamic firewall daemon
Loaded: loaded (/usr/lib/systemd/system/firewalld.service; disabled; vendor preset: enabled)
Active: inactive (dead)
Docs: man:firewalld(1)
[root@GitServer ~]# firewall-cmd --state
not running
安裝
- GitLab 官方 【gitlab-ce-16.4.2-ce.0.el7.x86_64.rpm】
- 清華大學開源軟件鏡像站【gitlab-ce-16.4.2-ce.0.el7.x86_64.rpm】
[root@GitLabServer ~]# yum install -y curl policycoreutils-python openssh-server perl postfix wget
[root@GitLabServer ~]# wget https://mirrors.tuna.tsinghua.edu.cn/gitlab-ce/yum/el7/gitlab-ce-16.4.2-ce.0.el7.x86_64.rpm
[root@GitLabServer ~]# yum localinstall gitlab-ce-16.4.2-ce.0.el7.x86_64.rpm
It looks like GitLab has not been configured yet; skipping the upgrade script.
*. *.
*** ***
***** *****
.****** *******
******** ********
,,,,,,,,,***********,,,,,,,,,
,,,,,,,,,,,*********,,,,,,,,,,,
.,,,,,,,,,,,*******,,,,,,,,,,,,
,,,,,,,,,*****,,,,,,,,,.
,,,,,,,****,,,,,,
.,,,***,,,,
,*,.
_______ __ __ __
/ ____(_) /_/ / ____ _/ /_
/ / __/ / __/ / / __ `/ __ \
/ /_/ / / /_/ /___/ /_/ / /_/ /
\____/_/\__/_____/\__,_/_.___/
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. # 注意:設置external_url
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=16-0
Verifying : gitlab-ce-16.4.2-ce.0.el7.x86_64 1/1
Installed:
gitlab-ce.x86_64 0:16.4.2-ce.0.el7
Complete!
修改GitLab配置
[root@GitLabServer ~]# hostname -I
172.16.70.191
[root@GitLabServer ~]# cp /etc/gitlab/gitlab.rb /etc/gitlab/gitlab.rb_bak
[root@GitLabServer ~]# diff /etc/gitlab/gitlab.rb /etc/gitlab/gitlab.rb_bak
32c32
# 例如1:external_url 'http://IP' # 默認端口80
# 例如2:external_url 'http://IP:PORT'
< external_url 'http://172.16.70.191:91' # 修改此行內容, 設置為本機IP:PORT
---
> external_url 'http://gitlab.example.com'
# 重載配置
[root@GitLabServer ~]# gitlab-ctl reconfigure
可選設置
# 啟動ssh服務&設置為開機啟動
systemctl enable sshd && sudo systemctl start sshd
# 設置postfix開機自啟,并啟動,postfix支持gitlab發信功能
systemctl enable postfix && systemctl start postfix
# 如系統防火墻是開啟狀態,則需設置允許策略
firewall-cmd --permanent --add-service=http
firewall-cmd --permanent --add-service=https
firewall-cmd --zone=public --add-port=PORT/tcp --permanent
systemctl reload firewalld
查看GitLab版本信息
[root@GitLabServer ~]# gitlab-rake gitlab:env:info
System information
System:
Current User: git
Using RVM: no
Ruby Version: 3.0.6p216
Gem Version: 3.4.19
Bundler Version:2.4.19
Rake Version: 13.0.6
Redis Version: 7.0.13
Sidekiq Version:6.5.7
Go Version: unknown
GitLab information
Version: 16.4.2
Revision: 67c88353b76
Directory: /opt/gitlab/embedded/service/gitlab-rails
DB Adapter: PostgreSQL
DB Version: 13.11
URL: http://172.16.70.191:91
HTTP Clone URL: http://172.16.70.191:91/some-group/some-project.git
SSH Clone URL: git@172.16.70.191:some-group/some-project.git
Using LDAP: no
Using Omniauth: yes
Omniauth Providers:
GitLab Shell
Version: 14.28.0
Repository storages:
- default: unix:/var/opt/gitlab/gitaly/gitaly.socket
GitLab Shell path: /opt/gitlab/embedded/service/gitlab-shell
Gitaly
- default Address: unix:/var/opt/gitlab/gitaly/gitaly.socket
- default Version: 16.4.2
- default Git Version: 2.42.0
Gitlab目錄結構
/opt/gitlab/ # 主目錄
/etc/gitlab/ # 放置配置文件
/var/opt/gitlab/ # 各個組件
/var/log/gitlab/ # 放置日志文件
/var/opt/gitlab/git-data/repositories # 數據庫的地址
/var/opt/gitlab/postgresql/data # gitlab組和項目的地址
/etc/gitlab/gitlab.rb # gitlab配置文件
端口信息
[root@GitLabServer ~]# netstat -ntpl
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 127.0.0.1:9229 0.0.0.0:* LISTEN 2637/gitlab-workhor
tcp 0 0 127.0.0.1:9168 0.0.0.0:* LISTEN 2653/ruby
tcp 0 0 127.0.0.1:8080 0.0.0.0:* LISTEN 2222/puma 6.3.1 (un
tcp 0 0 0.0.0.0:91 0.0.0.0:* LISTEN 2330/nginx: master # 對應前面設置external_url PORT
tcp 0 0 127.0.0.1:8082 0.0.0.0:* LISTEN 2252/sidekiq_export
tcp 0 0 127.0.0.1:9236 0.0.0.0:* LISTEN 2599/gitaly
tcp 0 0 127.0.0.1:8150 0.0.0.0:* LISTEN 2626/gitlab-kas
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 1270/sshd
tcp 0 0 127.0.0.1:8151 0.0.0.0:* LISTEN 2626/gitlab-kas
tcp 0 0 127.0.0.1:8153 0.0.0.0:* LISTEN 2626/gitlab-kas
tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN 875/master
tcp 0 0 127.0.0.1:8154 0.0.0.0:* LISTEN 2626/gitlab-kas
tcp 0 0 127.0.0.1:8155 0.0.0.0:* LISTEN 2626/gitlab-kas
tcp 0 0 127.0.0.1:8092 0.0.0.0:* LISTEN 2250/sidekiq 6.5.7
tcp 0 0 0.0.0.0:8060 0.0.0.0:* LISTEN 2330/nginx: master
tcp 0 0 127.0.0.1:9121 0.0.0.0:* LISTEN 2655/redis_exporter
tcp 0 0 127.0.0.1:9090 0.0.0.0:* LISTEN 2662/prometheus
tcp 0 0 127.0.0.1:9187 0.0.0.0:* LISTEN 2688/postgres_expor
tcp 0 0 127.0.0.1:9093 0.0.0.0:* LISTEN 2678/alertmanager
tcp 0 0 127.0.0.1:9100 0.0.0.0:* LISTEN 2647/node_exporter
tcp6 0 0 ::1:9168 :::* LISTEN 2653/ruby
tcp6 0 0 :::22 :::* LISTEN 1270/sshd
tcp6 0 0 ::1:25 :::* LISTEN 875/master
tcp6 0 0 :::9094 :::* LISTEN 2678/alertmanager
GitLab 密碼
獲取初始登錄密碼,默認登錄賬號:root
設置初始密碼:GitLab 14.0 開始引入。
默認情況下,Linux 軟件包安裝會自動為初始管理員用戶賬號 (root) 生成密碼,并將其存儲到 /etc/gitlab/initial_root_password 至少 24 小時。出于安全原因,24 小時后,此文件會被第一次 gitlab-ctl reconfigure 自動刪除。
[root@GitLabServer ~]# grep Password: /etc/gitlab/initial_root_password
Password: JPbE/qElViuH3O1REgsnA+9hB669393vA0f19NAe8RY=


設置簡體中文



其他設置
禁用注冊
默認情況下,任何訪問您的極狐GitLab 域名的用戶都可以注冊一個賬戶。對于運行面向公眾的極狐GitLab 實例的客戶,如果您不希望公眾用戶注冊賬戶,我們強烈建議您考慮禁用新注冊。
要禁用注冊:
在左側邊欄中,選擇 搜索或轉到。
選擇 管理中心。
選擇 設置 > 通用。
展開 注冊限制。
清除 已啟用注冊功能 復選框,然后選擇 保存修改。
重置/修改root密碼
使用Rake任務:GitLab 13.9 開始引入。
密碼長度設置為最少8個字符,且必須符合復雜性要求。
[root@GitLabServer ~]# gitlab-rake "gitlab:password:reset[root]"
Enter password: # 輸入新密碼
Confirm password: # 再次輸入
Password successfully updated for user with username root.
防止新用戶創建頂級群組
# 編輯 /etc/gitlab/gitlab.rb 并添加以下行:
gitlab_rails['gitlab_default_can_create_group'] = false
gitlab-ctl reconfigure
gitlab-ctl restart
防止用戶更改其用戶名
默認情況下,新用戶可以更改他們的用戶名。要禁用您的用戶更改其用戶名的能力:
編輯 /etc/gitlab/gitlab.rb 并添加以下行:
gitlab_rails['gitlab_username_changing_enabled'] = false
gitlab-ctl reconfigure
gitlab-ctl restart
出處:http://www.rzrgm.cn/zhangwencheng
版權:本文版權歸作者和博客園共有,歡迎轉載,但未經作者同意必須保留此段聲明,且在文章頁面明顯位置給出 原文鏈接
浙公網安備 33010602011771號