Gitlab搭建部署及配置


本篇內容:

  --->Gitlab搭建部署

  --->Gitlab項目創建及用戶管理

    |-->創建用戶及群組

      |->創建用戶

      |->創建群組

    |-->創建項目並設置權限

 

 

搭建於虛擬機:

  CentOS Linux release 7.9.2009 (Core)

  3.10.0-1160.el7.x86_64

  (1處理器,8GB內存,生產環境要根據實際需要,此軟件還是比較吃內存的)

 


 

 

Gitlab搭建部署

 

下載地址:

  https://packages.gitlab.com/gitlab/gitlab-ce

  https://mirrors.cloud.tencent.com/gitlab-ce/

[root@localhost opt]# ls -lh
total 865M
-rw-r--r--. 1 root root 865M Aug  7 23:29 gitlab-ce-13.12.9-ce.0.el7.x86_64.rpm

 

安裝所需的依賴軟件並開啟服務:

[root@localhost opt]# yum install -y curl postfix cronie policycoreutils-python

 

安裝Gitlab的rpm包:

    ##需要一些時間,稍等等
[root@localhost opt]# rpm -ivh gitlab-ce-13.12.9-ce.0.el7.x86_64.rpm 
warning: gitlab-ce-13.12.9-ce.0.el7.x86_64.rpm: Header V4 RSA/SHA1 Signature, key ID f27eab47: NOKEY
Preparing...                          ################################# [100%]
Updating / installing...
   1:gitlab-ce-13.12.9-ce.0.el7       ################################# [100%]
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

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=13-12

 

編輯配置文件:

  這里提示一下,配置文件版本上有所不同,比如,我這篇寫的時候示例是 13.12.9 版本,但是在實際應用之后 安裝的是 14 的版本,按照下面的配置方式已經報錯啦;

  不過報錯中會給予提示,https://docs.gitlab.com/ee/administration/operations/puma.html   官網的文檔,主要是 unicorn 已經棄用,需要切換到 Puma ;

[root@localhost opt]# vim /etc/gitlab/gitlab.rb
    ... ...
    ##設置地址,填寫主機的IP地址即可
    ##下面兩個端口設置是直接添加的
external_url 'http://192.168.180.129'

    ##端口這里要設置,根據需求指定
    ##最初我這里沒有指定,一直提示我網頁重定向,不能訪問
unicorn['port'] = 8765
nginx['listen_port'] = 9876

    ##可以編輯自己制定的目錄位置存放數據,記得創建目錄
    ##設置多個目錄位置,{ } 之間需要用 , 分隔
git_data_dirs({
  "default" => {
    "path" => "/codeData/git-data"
   },
  "test1" => {
    "path" => "/codeData/test1/"
   }
})
    ... ...
    ... ...
    ##這里是配置文件里默認帶的模板,配置是可以復制來修改
 612 # git_data_dirs({
 613 #   "default" => {
 614 #     "path" => "/mnt/nfs-01/git-data"
 615 #    }
 616 # })
    ... ...
    ... ...

    ##編輯保存配置文件后,若是自己指定了數據目錄,則需要創建
[root@localhost opt]# mkdir -pv /codeData
mkdir: created directory ‘/codeData’

 

 

 配置初始化:

    ##初始化配置時間比較長,耐心等等
[root@localhost opt]# gitlab-ctl reconfigure
    ... ...
    ... ...
Recipe: monitoring::grafana
  * runit_service[grafana] action restart (up to date)

Running handlers:
Running handlers complete
Chef Infra Client finished, 595/1565 resources updated in 04 minutes 24 seconds

Notes:
It seems you haven't specified an initial root password while configuring the GitLab instance.
On your first visit to  your GitLab instance, you will be presented with a screen to set a
password for the default admin account with username `root`.

gitlab Reconfigured!

 

啟動服務:

    ##啟動服務
[root@localhost opt]# gitlab-ctl start
ok: run: alertmanager: (pid 3793) 281s
ok: run: gitaly: (pid 3686) 285s
ok: run: gitlab-exporter: (pid 3693) 284s
ok: run: gitlab-workhorse: (pid 3666) 286s
ok: run: grafana: (pid 3810) 280s
ok: run: logrotate: (pid 2485) 496s
ok: run: nginx: (pid 3051) 413s
ok: run: node-exporter: (pid 3677) 285s
ok: run: postgres-exporter: (pid 3804) 280s
ok: run: postgresql: (pid 2739) 473s
ok: run: prometheus: (pid 3705) 283s
ok: run: puma: (pid 2947) 431s
ok: run: redis: (pid 2527) 490s
ok: run: redis-exporter: (pid 3695) 284s
ok: run: sidekiq: (pid 2975) 425s

    ##相應的,也有停止服務和重啟服務
    ##停止服務
[root@localhost opt]# gitlab-ctl stop
    ##重啟服務
[root@localhost opt]# gitlab-ctl restart

 注意:記得關閉firewalld和selinux;

 

修改默認的 root 密碼:

[root@localhost ~]# gitlab-rails console
--------------------------------------------------------------------------------
 Ruby:         ruby 2.7.2p137 (2020-10-01 revision 5445e04352) [x86_64-linux]
 GitLab:       13.12.9 (af9df3fee54) FOSS
 GitLab Shell: 13.18.1
 PostgreSQL:   12.6
--------------------------------------------------------------------------------
Loading production environment (Rails 6.0.3.7)
irb(main):001:0> user = User.where(id:1).first
=> #<User id:1 @root>
irb(main):002:0> user.password='123456789'
=> "123456789"
irb(main):003:0> user.password_confirmation='123456789'
=> "123456789"
irb(main):004:0> user.save!
Enqueued ActionMailer::MailDeliveryJob (Job ID: 6db44a2e-890d-427b-b9ae-77facab8c8cf) to Sidek
iq(mailers) with arguments: "DeviseMailer", "password_change", "deliver_now", {:args=>[#<Globa
lID:0x00007f69b12c3248 @uri=#<URI::GID gid://gitlab/User/1>>]}
=> true
irb(main):005:0>

 

瀏覽器訪問:http://192.168.180.129:9876/

這里上來會提示我們修改密碼:

 

 

這里的郵箱需要你設置一個開通了SMTP的郵箱,若想上述步驟是沒有設置的,那么填寫了新的密碼下一步之后,會提示如下(直接翻譯,英語看費勁):

郵箱的配置是選擇性的,可以有,也可以沒有;

當你沒有配置的時候下面會有一行:已經有登錄和密碼,直接進行登錄(第一個頁面下面也有:Already have login and password? Sign in)

 

 

我們直接點擊跳轉到登錄即可:

 

 

 

接下來——

  我們把他設置為中文界面(注意:並不是全部漢化,但足夠你分清功能,方便使用);

 

滾動至最下方即可找到,選擇后記得點擊 Save changes 保存;

 

 

--返回目錄--


 

 

Gitlab項目創建及用戶管理

 

首先來看一下管理中心的界面,你需要做的管理,都在這里可以找到:

 

 

 

創建用戶及群組

 

  創建用戶

View latest users 是查看當前已經存在的用戶的列表;

 

點擊 新建用戶 進入創建用戶的界面(填寫信息后記得確認保存 Create user):

 

 

這里有幾項需要說明:

1、第一項名稱,是你登錄時用的賬戶名,而第二項 Username 則是你登陸后你個人顯示的名字;

2、電子郵件可以是隨便的,若你設置了stmp郵箱,可以發送郵件,那么可以填寫真實的郵件地址,用來日常接受郵件;

3、密碼問題,首次創建的用戶沒有密碼,這個密碼需要你創建賬號后,再次進入用戶設置進行初始化設置;

  初始化密碼后的第一次登錄(每次初始化都是)會要求你重新設置密碼,之后不進行重置設置便會一直可以使用;

4、普通用戶和管理員用戶差別在於可見的項目以及各種管理,這個用戶的權限是針對整個Gitlab的;

 

 

  創建群組

View latest groups 是查看當前已經存在的群組的列表;

 

點擊 新建群組 進入創建群組的界面(填寫信息后記得保存):

 

 

這里有幾項需要說明:

1、可見性級別,私有是你需要自己設定哪些用戶和群組可以查看,內部則是可以登錄到Gitlab的所有用戶均可查看,而公開是所有人,只要進入網頁,當然,我們部署的是本地內部的項目;

  (公司內部使用,我都是創建的私有,管理員可以查看任何,但是其他人要設置權限,不要給太大了)

2、允許創建新項目和子群組的這兩個中,維護者 相當於管理員 ,但是他不是 擁有者 ,這個相應的需要區分一下,依然遵從工作流程給予合適的最小權限即可;

 

 

群組這里涉及到一個添加組員的操作:

點擊管理界面的 View latest groups 來查看現有的群組;

 

 

將指定的用戶添加到群組里;

 

 

用戶組內的身份權限需要設定一下:

  Guest 只能看;

  Reporter 可以看,可以克隆,其他不行;

  Developer 開發者權限,可以各種修改,提交什么的,開發人員的用戶,給到這個就行;

  Maintainer 維護者,也就是管理員,權限比較大,對代碼的操作也是非常多,權限都給了,但是他不能刪除項目;

  Owner 擁有者,這個就不要隨便給了,為所欲為了(僅限這個群組);

 

 

 

創建項目並設置權限

這里只說新建空白項目做個例子,導入跟隨提示即可(創建非常簡單,主要是相應的設置);

點擊 新建項目 之后進入界面,里面三項:創建空白項目,模板創建 和 導入;

 

 

 創建后新倉庫會有提示,是一些基本操作,之后需要的是你把代碼放到這里:

 

 

管理設置需要進入 管理中心 點擊 View latest projects 進入項目列表:

 

 

 

 

這里和群組添加成員的界面類似,邀請單獨的用戶和群組都是在此設置:

  說明一下,每個成員用戶都有自己的郵箱,當你邀請成員時,點擊下拉列表可能會出現郵箱地址讓你選擇,它會自動為你選擇到相應的用戶;

  當你直接去點這個輸入框的位置時就會顯示郵箱地址,你需要讓光標在輸入框中顯示,那么它顯示的就是用戶列表了;

  過期時間你可以不設定,代表的是永不過期;

 

 

 

--返回目錄--


 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM