一文搞懂GitLab安裝部署及服務配置


GitLab安裝部署

Git,GitHub,GitLab,這三個東東長得好像呀,都是個啥?

Git是Linus Torvalds(如果不知道這位大神是誰,請出門左轉,慢走不送~)為了幫助管理Linux內核而開發的一個開放源代碼的版本控制軟件。

GitHub,又名全球最大同行交友軟件(O(∩_∩)O哈哈~),是一個面向開源及私有項目的托管平台,因為僅僅支持Git作為唯一的版本庫格式,故名GitHub。

GitLab是由GitLabInc.開發的,是基於MIT許可證的Git倉庫管理工具,具有Wiki和Issue跟蹤功能,目前有企業版和社區版兩個分支,對於個人來說,社區版應該是完全夠用的。

其實,簡單來說,可以把GitLab看做是個個人版的GitHub,也就是說,可以在自己服務器上部署一套GitLab服務,該服務可以提供代碼倉庫托管等功能,用法與GibHub基本一致。

GitLab安裝

# 安裝並配置必要的依賴
[root@cos ~]# yum install -y curl policycoreutils-python openssh-server
[root@cos ~]# systemctl enable sshd
[root@cos ~]# systemctl start sshd
# CentOS7系統中,在防火牆打開場景下,打開HTTP, HTTPS和SSH訪問
[root@cos ~]# firewall-cmd --permanent --add-service=http
[root@cos ~]# firewall-cmd --permanent --add-service=https
[root@cos ~]# systemctl reload firewalld

# 安裝Postfix,用來發送通知郵件
[root@cos ~]# yum install postfix
[root@cos ~]# systemctl enable postfix
[root@cos ~]# systemctl start postfix

注意:為了避免下載失敗導致GitLab安裝失敗,可以配置清華鏡像,鏡像配置操作如下

# GitLab Community Edition鏡像使用幫助
# https://mirror.tuna.tsinghua.edu.cn/help/gitlab-ce/
# 1. 新建/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

使用yum安裝GitLab社區版

# yum安裝GitLab社區版
[root@cos ~]# yum makecache
[root@cos ~]# yum install gitlab-ce
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * base: mirrors.huaweicloud.com
 * epel: hkg.mirror.rackspace.com
 * extras: mirrors.huaweicloud.com
 * updates: mirrors.huaweicloud.com
Resolving Dependencies
--> Running transaction check
---> Package gitlab-ce.x86_64 0:12.9.1-ce.0.el7 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

=========================================================================================
 Package        Arch        Version            Repository        Size
=========================================================================================
Installing:
 gitlab-ce      x86_64      12.9.1-ce.0.el7    gitlab-ce         721 M

Transaction Summary
=========================================================================================
Install  1 Package

Total download size: 721 M
Installed size: 721 M
Is this ok [y/d/N]: y
Downloading packages:
gitlab-ce-12.9.1-ce.0.el7.x86_64.rpm                                                    | 721 MB  00:01:49     
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Installing : gitlab-ce-12.9.1-ce.0.el7.x86_64                                                            1/1 
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
GitLab now ships with a newer version of PostgreSQL (11.7), but it is not yet
enabled by default. To upgrade, please see:
https://docs.gitlab.com/omnibus/settings/database.html#upgrade-packaged-postgresql-server

Verifying  : gitlab-ce-12.9.1-ce.0.el7.x86_64                                                            1/1 

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

Complete!

安裝完成后,重點關注下面提示信息:

GitLab was unable to detect a valid hostname for your instance.
GitLab無法為你的GitLab檢測到有效的主機名。

Please configure a URL for your GitLab instance by setting `external_url`
configuration in /etc/gitlab/gitlab.rb file.
請通過配置`external_url`為你的GitLab實例配置一個URL,該配置項在/etc/gitlab/gitlab.rb文件中。

Then, you can start your GitLab instance by running the following command:
  sudo gitlab-ctl reconfigure
然后,通過運行sudo gitlab-ctl reconfigure啟動你的GitLab實例

注意:配置完成后,需要使用sudo gitlab-ctl reconfigure命令重新配置並啟動GitLab實例才行。

在GitLab安裝完成后,首次登錄時,需要配置GitLab管理員密碼,如下圖所示。

注意:管理員賬號為root,管理員密碼非常重要,是維護GitLab服務的重要賬戶,盡量不要搞忘了。

GitLab配置及內存優化

根據上面的安裝步驟安裝完成后后,啟動GitLab實例后,你可能會想,這下可以愉快的與GitLab玩耍了吧、

砰,一大盆涼水澆過來、

GitLab是非常吃內存和服務器性能的,為了在自己主機或者虛擬機上正常啟動和訪問,需要進行下面配置和調優。

先看下官方給出的推薦CPU,內存配置:

GitLab推薦至少2核CPU,只有1核的話,可能會導致GitLab服務卡死,無法正常對外服務。

由上可知,內存配置主要影響GitLab服務的並發用戶數量,對於自己使用來說,感覺2GB完全夠用了。

GitLab配置文件路徑:/etc/gitlab/gitlab.rb。下面對GitLab關鍵配置進行修改:

## GitLab URL
##! URL on which GitLab will be reachable.
##! 用戶訪問GitLab的URL地址
external_url 'http://cos'

###! Minimum worker_processes is 2 at this moment
###! GitLab默認開啟進程數為CPU核數+1,可以提高服務器的相應時間,太吃內存
###! GitLab的最小工作進程,該參數最小值為2,設為1可能導致服務器卡死
unicorn['worker_processes'] = 2

### **Only change these settings if you understand well what they mean**
###! 工程進程的內存限制,默認最小為400MB,最大為650MB
unicorn['worker_memory_limit_min'] = "200 * 1 << 20"
unicorn['worker_memory_limit_max'] = "300 * 1 << 20"

# sidekiq並發數默認值為25
sidekiq['concurrency'] = 5

###! Changing any of these settings requires a restart of postgresql.
###! By default, reconfigure reloads postgresql if it is running. If you
###! change any of these settings, be sure to run `gitlab-ctl restart postgresql`
###! after reconfigure in order for the changes to take effect.
##! **recommend value is 1/4 of total RAM, up to 14GB.**
##! 數據庫緩存,默認值為256MB
##!推薦值為1/4的RAM大小,按推薦值肯定崩了
postgresql['shared_buffers'] = "128MB"
##! 數據庫並發數
postgresql['max_worker_processes'] = 4

GitLab啟動

GitLab安裝配置完成后,我們可以通過gitlab-ctl start命令啟動,gitlab-ctl stop命令停止GitLab服務。

# 查看GitLab服務狀態
[root@cos ~]# gitlab-ctl status
run: gitaly: (pid 2202) 830s; run: log: (pid 2201) 830s
run: gitlab-workhorse: (pid 2212) 830s; run: log: (pid 2211) 830s
run: logrotate: (pid 2217) 830s; run: log: (pid 2214) 830s
run: nginx: (pid 2198) 830s; run: log: (pid 2197) 830s
run: postgresql: (pid 2204) 830s; run: log: (pid 2203) 830s
run: redis: (pid 2213) 830s; run: log: (pid 2210) 830s
run: sidekiq: (pid 2195) 830s; run: log: (pid 2193) 830s
run: unicorn: (pid 2196) 830s; run: log: (pid 2194) 830s

GitLab服務啟動后,我們可以通過Web頁面訪問GitLab服務。

接下來,會專門再寫一篇博客講述如何在Windows上通過Git客戶端像訪問GitHub一樣訪問GitLab,敬請期待~


免責聲明!

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



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