Centos7系統(tǒng)下配置Git服務(wù)器(4)--yum安裝配置GitLab-CE

0x0 GitLab介紹

gitlab 不用說,大家都知道是做什么的,gitlab 分為 Gitlab Community Edition(gitlab社區(qū)版又稱gitlab-ce)、Gitlab Enterprise Edition(gitlab企業(yè)版又稱gitlab-ee);ce和ee的區(qū)別在于ce的功能在ee里面都有,而EE里有的功能CE不一定支持。如果要用高級(jí)功能,就花錢向gitlab團(tuán)隊(duì)采購(gòu)吧!!

注意:官方推薦最低物理配置是2核,4G,推薦4C 8G

主機(jī)規(guī)劃

名稱 主機(jī)規(guī)劃 配置 安裝軟件 系統(tǒng)
gitlab01 10.0.0.158 4C 8G yum install -y gitlab-ce Centos7.6 1810

0x1 GitLab架構(gòu)

image

gitlab使用ruby on rails框架編寫的一個(gè)web界面的代碼倉(cāng)庫(kù)管理系統(tǒng),在運(yùn)行中使用了數(shù)據(jù)庫(kù)(postgresql[可以使用其他數(shù)據(jù)庫(kù)代替如mysql])、redis、nginx、gitlab-shell等組件來保證gitlab的正常運(yùn)行。

Gitlab的服務(wù)構(gòu)成

名稱 作用 備注
Nginx服務(wù) 靜態(tài)web服務(wù)器 比較重要
gitlab-shell 用于處理Git命令和修改authorized keys列表 Ruby
workhorse 輕量級(jí)的反向代理服務(wù)器 go語言
logrotate 日志文件管理工具
postgresql 數(shù)據(jù)庫(kù)
redis 緩存數(shù)據(jù)庫(kù)
sidekiq 用于在后臺(tái)執(zhí)行隊(duì)列任務(wù)(異步執(zhí)行) Ruby
unicorn An HTTP server for Rack applications,GitLab Rails應(yīng)用是托管在這個(gè)服務(wù)器上面的。 Ruby Web Server,主要使用Ruby編寫

0x2 安裝GitLab

Centos7中可以直接通過配置yum源然后使用yum進(jìn)行一鍵安裝

Step 1 配置yum源

國(guó)內(nèi)可以使用的清華大學(xué)的鏡像源安裝GitLab,相關(guān)配置及安裝參照:https://mirror.tuna.tsinghua.edu.cn/help/gitlab-ce/
以下內(nèi)容寫入yum源配置文件:/etc/yum.repos.d/gitlab-ce.repo

[gitlab-ce]
name=Gitlab CE Repository
baseurl=https://mirrors.tuna.tsinghua.edu.cn/gitlab-ce/yum/el$releasever/
gpgcheck=0
enabled=1

Step2 安裝

gitlab-ce一鍵安裝后可以利用rpm -ql gitlab-ce查詢其文件安裝路徑及相關(guān)文件路徑,其默認(rèn)安裝路徑為/opt/gitlab/、程序數(shù)據(jù)及配置文件保存路徑為/var/opt/gitlab下。

相關(guān)默認(rèn)位置

代碼倉(cāng)庫(kù)保存位置:/var/opt/gitlab/git-data/repositories/
代碼倉(cāng)庫(kù)備份位置:/var/opt/gitlab/backups/
postgresql數(shù)據(jù)及配置目錄:/var/opt/gitlab/postgresql/data/
redis默認(rèn)配置目錄:/var/opt/gitlab/redis
gitlab主要配置文件:/etc/gitlab/gitlab.rb

yum makecache
yum install -y gitlab-ce

執(zhí)行過程如下

[root@gitlab ~]# cd /etc/yum.repos.d/
[root@gitlab yum.repos.d]# ls
CentOS-Base.repo  CentOS-Debuginfo.repo  CentOS-Media.repo    CentOS-Vault.repo
CentOS-CR.repo    CentOS-fasttrack.repo  CentOS-Sources.repo
[root@gitlab yum.repos.d]# vim gitlab-ce.repo
[root@gitlab yum.repos.d]# yum makecache
Loaded plugins: fastestmirror
Determining fastest mirrors
 * base: mirrors.neusoft.edu.cn
 * extras: mirrors.neusoft.edu.cn
 * updates: mirrors.tuna.tsinghua.edu.cn
base                                                                                               | 3.6 kB  00:00:00     
extras                                                                                             | 2.9 kB  00:00:00     
gitlab-ce                                                                                          | 2.9 kB  00:00:00     
updates                                                                                            | 2.9 kB  00:00:00     
(1/10): extras/7/x86_64/other_db                                                                   | 100 kB  00:00:00     
(2/10): gitlab-ce/7/primary_db                                                                     | 3.4 MB  00:00:01     
(3/10): gitlab-ce/7/other_db                                                                       |  32 kB  00:00:00     
(4/10): extras/7/x86_64/filelists_db                                                               | 207 kB  00:00:01     
(5/10): base/7/x86_64/other_db                                                                     | 2.6 MB  00:00:09     
(6/10): updates/7/x86_64/filelists_db                                                              | 3.5 MB  00:00:08     
(7/10): updates/7/x86_64/other_db                                                                  | 387 kB  00:00:00     
(8/10): base/7/x86_64/filelists_db                                                                 | 7.3 MB  00:00:11     
(9/10): updates/7/x86_64/primary_db                                                                | 5.9 MB  00:00:14     
(10/10): gitlab-ce/7/filelists_db                                                                  | 278 MB  00:00:27     
Metadata Cache Created
[root@gitlab yum.repos.d]# yum install -y gitlab-ce
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * base: mirrors.neusoft.edu.cn
 * extras: mirrors.neusoft.edu.cn
 * updates: mirrors.tuna.tsinghua.edu.cn
Resolving Dependencies
--> Running transaction check
---> Package gitlab-ce.x86_64 0:12.6.4-ce.0.el7 will be installed
--> Processing Dependency: policycoreutils-python for package: gitlab-ce-12.6.4-ce.0.el7.x86_64
--> Running transaction check
---> Package policycoreutils-python.x86_64 0:2.5-33.el7 will be installed
--> Processing Dependency: policycoreutils = 2.5-33.el7 for package: policycoreutils-python-2.5-33.el7.x86_64
--> Processing Dependency: setools-libs >= 3.3.8-4 for package: policycoreutils-python-2.5-33.el7.x86_64
--> Processing Dependency: libsemanage-python >= 2.5-14 for package: policycoreutils-python-2.5-33.el7.x86_64
--> Processing Dependency: audit-libs-python >= 2.1.3-4 for package: policycoreutils-python-2.5-33.el7.x86_64
--> Processing Dependency: python-IPy for package: policycoreutils-python-2.5-33.el7.x86_64
--> Processing Dependency: libqpol.so.1(VERS_1.4)(64bit) for package: policycoreutils-python-2.5-33.el7.x86_64
--> Processing Dependency: libqpol.so.1(VERS_1.2)(64bit) for package: policycoreutils-python-2.5-33.el7.x86_64
--> Processing Dependency: libcgroup for package: policycoreutils-python-2.5-33.el7.x86_64
--> Processing Dependency: libapol.so.4(VERS_4.0)(64bit) for package: policycoreutils-python-2.5-33.el7.x86_64
--> Processing Dependency: checkpolicy for package: policycoreutils-python-2.5-33.el7.x86_64
--> Processing Dependency: libqpol.so.1()(64bit) for package: policycoreutils-python-2.5-33.el7.x86_64
--> Processing Dependency: libapol.so.4()(64bit) for package: policycoreutils-python-2.5-33.el7.x86_64
--> Running transaction check
---> Package audit-libs-python.x86_64 0:2.8.5-4.el7 will be installed
--> Processing Dependency: audit-libs(x86-64) = 2.8.5-4.el7 for package: audit-libs-python-2.8.5-4.el7.x86_64
---> Package checkpolicy.x86_64 0:2.5-8.el7 will be installed
---> Package libcgroup.x86_64 0:0.41-21.el7 will be installed
---> Package libsemanage-python.x86_64 0:2.5-14.el7 will be installed
---> Package policycoreutils.x86_64 0:2.5-29.el7 will be updated
---> Package policycoreutils.x86_64 0:2.5-33.el7 will be an update
---> Package python-IPy.noarch 0:0.75-6.el7 will be installed
---> Package setools-libs.x86_64 0:3.3.8-4.el7 will be installed
--> Running transaction check
---> Package audit-libs.x86_64 0:2.8.4-4.el7 will be updated
--> Processing Dependency: audit-libs(x86-64) = 2.8.4-4.el7 for package: audit-2.8.4-4.el7.x86_64
---> Package audit-libs.x86_64 0:2.8.5-4.el7 will be an update
--> Running transaction check
---> Package audit.x86_64 0:2.8.4-4.el7 will be updated
---> Package audit.x86_64 0:2.8.5-4.el7 will be an update
--> Finished Dependency Resolution

Dependencies Resolved

==========================================================================================================================
 Package                              Arch                 Version                          Repository               Size
==========================================================================================================================
Installing:
 gitlab-ce                            x86_64               12.6.4-ce.0.el7                  gitlab-ce               697 M
Installing for dependencies:
 audit-libs-python                    x86_64               2.8.5-4.el7                      base                     76 k
 checkpolicy                          x86_64               2.5-8.el7                        base                    295 k
 libcgroup                            x86_64               0.41-21.el7                      base                     66 k
 libsemanage-python                   x86_64               2.5-14.el7                       base                    113 k
 policycoreutils-python               x86_64               2.5-33.el7                       base                    457 k
 python-IPy                           noarch               0.75-6.el7                       base                     32 k
 setools-libs                         x86_64               3.3.8-4.el7                      base                    620 k
Updating for dependencies:
 audit                                x86_64               2.8.5-4.el7                      base                    256 k
 audit-libs                           x86_64               2.8.5-4.el7                      base                    102 k
 policycoreutils                      x86_64               2.5-33.el7                       base                    916 k

Transaction Summary
==========================================================================================================================
Install  1 Package  (+7 Dependent packages)
Upgrade             ( 3 Dependent packages)

Total download size: 699 M
Downloading packages:
Delta RPMs disabled because /usr/bin/applydeltarpm not installed.
(1/11): audit-libs-2.8.5-4.el7.x86_64.rpm                                                          | 102 kB  00:00:00     
(2/11): audit-libs-python-2.8.5-4.el7.x86_64.rpm                                                   |  76 kB  00:00:00     
(3/11): libcgroup-0.41-21.el7.x86_64.rpm                                                           |  66 kB  00:00:00     
(4/11): checkpolicy-2.5-8.el7.x86_64.rpm                                                           | 295 kB  00:00:00     
(5/11): libsemanage-python-2.5-14.el7.x86_64.rpm                                                   | 113 kB  00:00:00     
(6/11): policycoreutils-2.5-33.el7.x86_64.rpm                                                      | 916 kB  00:00:00     
(7/11): audit-2.8.5-4.el7.x86_64.rpm                                                               | 256 kB  00:00:00     
(8/11): policycoreutils-python-2.5-33.el7.x86_64.rpm                                               | 457 kB  00:00:00     
(9/11): setools-libs-3.3.8-4.el7.x86_64.rpm                                                        | 620 kB  00:00:00     
(10/11): python-IPy-0.75-6.el7.noarch.rpm                                                          |  32 kB  00:00:01     
(11/11): gitlab-ce-12.6.4-ce.0.el7.x86_64.rpm                                                      | 697 MB  00:01:05     
--------------------------------------------------------------------------------------------------------------------------
Total                                                                                      11 MB/s | 699 MB  00:01:05     
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Updating   : audit-libs-2.8.5-4.el7.x86_64                                                                         1/14 
  Updating   : policycoreutils-2.5-33.el7.x86_64                                                                     2/14 
  Installing : audit-libs-python-2.8.5-4.el7.x86_64                                                                  3/14 
  Installing : setools-libs-3.3.8-4.el7.x86_64                                                                       4/14 
  Installing : libcgroup-0.41-21.el7.x86_64                                                                          5/14 
  Installing : checkpolicy-2.5-8.el7.x86_64                                                                          6/14 
  Installing : python-IPy-0.75-6.el7.noarch                                                                          7/14 
  Installing : libsemanage-python-2.5-14.el7.x86_64                                                                  8/14 
  Installing : policycoreutils-python-2.5-33.el7.x86_64                                                              9/14 
  Installing : gitlab-ce-12.6.4-ce.0.el7.x86_64                                                                     10/14 
  Updating   : audit-2.8.5-4.el7.x86_64                                                                             11/14 
  Cleanup    : policycoreutils-2.5-29.el7.x86_64                                                                    12/14 
  Cleanup    : audit-2.8.4-4.el7.x86_64                                                                             13/14 
  Cleanup    : audit-libs-2.8.4-4.el7.x86_64                                                                        14/14 
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.
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

  Verifying  : audit-libs-2.8.5-4.el7.x86_64                                                                         1/14 
  Verifying  : policycoreutils-python-2.5-33.el7.x86_64                                                              2/14 
  Verifying  : gitlab-ce-12.6.4-ce.0.el7.x86_64                                                                      3/14 
  Verifying  : audit-2.8.5-4.el7.x86_64                                                                              4/14 
  Verifying  : libsemanage-python-2.5-14.el7.x86_64                                                                  5/14 
  Verifying  : python-IPy-0.75-6.el7.noarch                                                                          6/14 
  Verifying  : checkpolicy-2.5-8.el7.x86_64                                                                          7/14 
  Verifying  : policycoreutils-2.5-33.el7.x86_64                                                                     8/14 
  Verifying  : libcgroup-0.41-21.el7.x86_64                                                                          9/14 
  Verifying  : audit-libs-python-2.8.5-4.el7.x86_64                                                                 10/14 
  Verifying  : setools-libs-3.3.8-4.el7.x86_64                                                                      11/14 
  Verifying  : policycoreutils-2.5-29.el7.x86_64                                                                    12/14 
  Verifying  : audit-libs-2.8.4-4.el7.x86_64                                                                        13/14 
  Verifying  : audit-2.8.4-4.el7.x86_64                                                                             14/14 

Installed:
  gitlab-ce.x86_64 0:12.6.4-ce.0.el7                                                                                      

Dependency Installed:
  audit-libs-python.x86_64 0:2.8.5-4.el7   checkpolicy.x86_64 0:2.5-8.el7               libcgroup.x86_64 0:0.41-21.el7  
  libsemanage-python.x86_64 0:2.5-14.el7   policycoreutils-python.x86_64 0:2.5-33.el7   python-IPy.noarch 0:0.75-6.el7  
  setools-libs.x86_64 0:3.3.8-4.el7       

Dependency Updated:
  audit.x86_64 0:2.8.5-4.el7         audit-libs.x86_64 0:2.8.5-4.el7         policycoreutils.x86_64 0:2.5-33.el7        

Complete!

0x4 gitlab配置修改

編輯vim /etc/gitlab/gitlab.rb

修改gitlab運(yùn)行外部URL默認(rèn)的訪問地址
# 未修gitlab.rb配置文件中nginx配置時(shí)這個(gè)配置默認(rèn)配置gitlab自帶的nginx端口
external_url 'http://10.0.0.158:8081'  
#編輯完畢退出 執(zhí)行以下命令使配置生效
gitlab-ctl reconfigure
#重新啟動(dòng)GitLab
gitlab-ctl restart

【注意】需要注意的是我們安裝gitlab的時(shí)候注意端口號(hào)占用的問題。

0x5 設(shè)置開機(jī)自啟動(dòng)和防火墻規(guī)則

#設(shè)置開機(jī)自動(dòng)啟動(dòng)
systemctl enable gitlab-runsvdir.service
#設(shè)置禁用開機(jī)自動(dòng)啟動(dòng)
systemctl disable gitlab-runsvdir.service
#添加對(duì)應(yīng)端口
[root@gitlab yum.repos.d]# sudo firewall-cmd --permanent --add-service=http
success
[root@gitlab yum.repos.d]# sudo systemctl reload firewalld
[root@gitlab yum.repos.d]# firewall-cmd --zone=public --add-port=8081/tcp --permanent 
success
[root@gitlab yum.repos.d]# firewall-cmd --reload
success
[root@gitlab yum.repos.d]# firewall-cmd --zone=public --list-ports
8081/tcp 80/tcp

0x6 瀏覽器中打開地址

Step1 http://10.0.0.158:8081 登陸成功會(huì)提示修改管理密碼

Step2 用管理員root 和自己修改的密碼登陸系統(tǒng)

【注意】如果瀏覽器輸入地址出現(xiàn)502,檢查你的端口號(hào)是否已經(jīng)被占用了,修改端口重新編譯使配置生效即可,記得添加防火墻規(guī)則。

[root@gitlab ~]# 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:9100          0.0.0.0:*               LISTEN      12432/node_exporter 
tcp        0      0 127.0.0.1:9229          0.0.0.0:*               LISTEN      12319/gitlab-workho 
tcp        0      0 127.0.0.1:8080          0.0.0.0:*               LISTEN      15579/unicorn maste 
tcp        0      0 127.0.0.1:9168          0.0.0.0:*               LISTEN      12302/puma 4.3.1.gi 
tcp        0      0 0.0.0.0:8081            0.0.0.0:*               LISTEN      15598/nginx: master 
tcp        0      0 127.0.0.1:8082          0.0.0.0:*               LISTEN      15539/sidekiq 5.2.7 
tcp        0      0 127.0.0.1:9236          0.0.0.0:*               LISTEN      12290/gitaly        
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN      9479/sshd           
tcp        0      0 127.0.0.1:3000          0.0.0.0:*               LISTEN      15607/grafana-serve 
tcp        0      0 127.0.0.1:25            0.0.0.0:*               LISTEN      9630/master         
tcp        0      0 0.0.0.0:8060            0.0.0.0:*               LISTEN      15598/nginx: master 
tcp        0      0 127.0.0.1:9121          0.0.0.0:*               LISTEN      12480/redis_exporte 
tcp        0      0 127.0.0.1:9090          0.0.0.0:*               LISTEN      12463/prometheus    
tcp        0      0 127.0.0.1:9187          0.0.0.0:*               LISTEN      12438/postgres_expo 
tcp        0      0 127.0.0.1:9093          0.0.0.0:*               LISTEN      12269/alertmanager  
tcp6       0      0 ::1:9168                :::*                    LISTEN      12302/puma 4.3.1.gi 
tcp6       0      0 :::22                   :::*                    LISTEN      9479/sshd           
tcp6       0      0 ::1:25                  :::*                    LISTEN      9630/master         
tcp6       0      0 :::9094                 :::*                    LISTEN      12269/alertmanager 

0x7 配置完畢使用GitLab創(chuàng)建項(xiàng)目

主頁面上有個(gè)4個(gè)功能 創(chuàng)建一個(gè)項(xiàng)目、創(chuàng)建一個(gè)組、添加人員、配置

選擇第一個(gè) 創(chuàng)建一個(gè)新的項(xiàng)目

設(shè)置完畢以后,這樣就創(chuàng)建了好了項(xiàng)目,并把該項(xiàng)目托管到了我們的GitLab服務(wù)器上。

選擇右上角藍(lán)色Clone按鈕生成git和http方式訪問項(xiàng)目的路徑
客戶端Centos7或Windows中可以通過git clone命令把項(xiàng)目克隆下來。

這里需要注意的是通過git@10.0.0.158:8081/root/helloworld.git 這種方式克隆方式需要配置SSH KEY

[root@gitlab home]# git clone http://10.0.0.158:8081/root/helloworld.git
Cloning into 'helloworld'...
Username for 'http://10.0.0.158:8081': root
Password for 'http://root@10.0.0.158:8081': 
remote: Enumerating objects: 3, done.
remote: Counting objects: 100% (3/3), done.
remote: Total 3 (delta 0), reused 0 (delta 0)
Unpacking objects: 100% (3/3), done.
[root@gitlab home]# ls
azkaban  helloworld
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。
禁止轉(zhuǎn)載,如需轉(zhuǎn)載請(qǐng)通過簡(jiǎn)信或評(píng)論聯(lián)系作者。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容