1. 程式人生 > >CentOS7安裝GitLab的過程詳解

CentOS7安裝GitLab的過程詳解

安裝Gitlab

Step 1.安準基礎依賴

$ yum install -y curl policycoreutils-python openssh-server

Step 2.安裝Postfix

說明:Postfix是一個郵件伺服器,GitLab傳送郵件需要用到

$  yum install -y postfix

啟動postfix並設定為開機啟動
$ systemctl enable postfix
$ systemctl start postfix

 

Step 3.部署GitLab過程

1.新增GitLab社群版Package

$ curl https://packages.gitlab.com/install/repositories/gitlab/gitlab-ce/script.rpm.sh | sudo bash

2.安裝GitLab社群版

$ yum install -y gitlab-ce

3.安裝成功後會看到gitlab-ce列印了以下圖形

 

Step 4.配置GitLab站點Url

說明:GitLab預設的配置檔案路徑是/etc/gitlab/gitlab.rb

預設的站點Url配置項是:
external_url 'http://gitlab.example.com'

這裡我將GitLab站點Url修改為http://192.168.82.144
也可以用IP代替域名,這裡根據自己需求來即可


#修改配置檔案
$ vim /etc/gitlab/gitlab.rb

#配置首頁地址(大約在第15行)
external_url 'http://192.168.82.144'

 

Step 5.啟動並訪問GitLab

1.啟動

$ gitlab-ctl reconfigure


完成後將會看到如下輸出
Running handlers:
Running handlers complete
Chef Client finished, 513/1343 resources updated in 04 minutes 39 seconds
gitlab Reconfigured!

2.訪問GitLab

 

這時候會提示為管理員賬號設定密碼。管理員賬號預設username是root
設定完成之後即可使用root賬號登入,登陸後會進入歡迎介面。

 

Step 6.GitLab常用配置

1、禁用建立組許可權

GitLab預設所有的註冊使用者都可以建立組。但對於團隊來說,通常只會給Leader相關許可權。
雖然可以在使用者管理介面取消許可權,但畢竟不方便。我們可以通過配置GitLab預設禁用建立組許可權。

修改配置檔案
$ vim /etc/gitlab/gitlab.rb

#開啟gitlab_rails['gitlab_default_can_create_group'] 選項,並將值設定為false
### GitLab user privileges
gitlab_rails['gitlab_default_can_create_group'] = false

儲存後,重新配置並啟動GitLab
$ gitlab-ctl reconfigure


Step 7.建立群組

說明:群組主要的目的是聚合一群使用者和它們維護的專案,只要在如下的介面中新增群組相關資訊最後點選建立就可以

Step 8.建立使用者

建立完群組後就需要建立使用者賬號,通常在企業裡都是員工向管理源請求加入某個群組,管理員會根據員工提供的個人系資訊直接建立賬號,並且將賬號新增到對應的群組中

 

Step 9.建立專案

說明:專案的建立也很簡單可以在之前建立的群組裡新增專案,這樣整個專案就歸所在群組維護,可以為專案增加各種維護人員,需要注意的是專案裡的master分支等特殊分支developer使用者無法更新,只有master使用者才有許可權更新

 

Step 10.許可權設定--群組

1.開啟設定,點已建立的群組

 

2.將需要新增到這個群組的使用者選中

3.選擇許可權(身份)

 

Step 9.配置gitlab傳送郵件 

$  vim /etc/gitlab/gitlab.rb

gitlab_rails['smtp_enable'] = true
gitlab_rails['smtp_address'] = "smtp.exmail.qq.com"
gitlab_rails['smtp_port'] = 465
gitlab_rails['smtp_user_name'] = "[email protected]"
gitlab_rails['smtp_password'] = "password"
gitlab_rails['smtp_authentication'] = "login"
gitlab_rails['smtp_enable_starttls_auto'] = true
gitlab_rails['smtp_tls'] = true
gitlab_rails['gitlab_email_from'] = '[email protected]'


修改後重啟
gitlab-ctl restart