前言
好久沒有更新過部落格了,最近的工作确實比較忙(可以說忙的要死),前幾個月也在搞黑馬的線上教育,基本上已經差不多完成了,線上教育項目的文章也完成了大半,今天剛好有時間做個
gitlab
安裝記錄。
最近公司換了新的代碼伺服器,之前伺服器是在亞馬遜上,價格相對貴點,為了節約成本這次換到了國内的雲伺服器;公司把
Git
私服也換了,之前用的
gitblit
,此次更新到了
gitlab-ce(社群版)
;特此記錄下安裝、部署的過程。
相對來說
gitlab
的功能以及界面等,都要比
gitblit
好一些;但是就安裝來說,
gitlab
的安裝比
gitblit
的安裝要複雜很多。
GitLab介紹
GitLab
是由
GitLab Inc.
開發,使用
MIT許可證
的基于網絡的
Git倉
庫管理工具,且具有
wiki
和
issue
跟蹤功能。
GitLab
由烏克蘭程式員
Dmitriy Zaporozhets
和
Valery Sizov
開發,它由
Ruby
寫成。後來,一些部分用
Go
語言重寫。
主要功能
- 倉庫管理
- 公倉和私倉 (權限配置設定)
- 團隊和群組管理
- CI/CD工具
- GitLab工作流
- …
安裝環境介紹
伺服器
作業系統 | 記憶體 | 硬碟 | IP |
---|---|---|---|
CentOS 7 | 4G | 20G | 192.168.136.201 |
該伺服器為我本地虛拟機,需要保證伺服器能夠正常連接配接外網。
安裝
安裝依賴(必要工作)
安裝必要的依賴,無論
Omnibus
和
Docker
安裝都需要。
# 依賴安裝
sudo yum install -y curl policycoreutils-python openssh-server
# 啟動ssh服務
sudo systemctl enable sshd
sudo systemctl start sshd
# 設定防火牆政策允許 http以及https
sudo firewall-cmd --permanent --add-service=http
sudo firewall-cmd --permanent --add-service=https
sudo systemctl reload firewalld
# 安裝postfix并運作(gatlab預設郵件服務使用postfix)
sudo yum install postfix
sudo systemctl enable postfix
sudo systemctl start postfix
Omnibus安裝(yum)
擷取安裝包
# 擷取社群版
curl https://packages.gitlab.com/install/repositories/gitlab/gitlab-ce/script.rpm.sh | sudo bash
安裝gitlab
# 實際路徑以你的伺服器IP為準,也可以直接使用域名
# 安裝過程可能會有點緩慢
sudo EXTERNAL_URL="http://192.168.136.201" yum install -y gitlab-ce
如果此步不能下載下傳的可以使用
Plan B
。
Plan B(推薦)
使用清華大學的鏡像源
使用
vi
或者
vim
指令建立檔案:
/etc/yum.repos.d/gitlab_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
執行安裝指令
sudo EXTERNAL_URL="http://192.168.136.201" yum install -y gitlab-ce
此時下載下傳速度應該就會快很多,但是安裝仍需要一些時間,請耐心等待。
看到這個狐狸标志說明安裝成功了。
啟動GitLab
sudo gitlab-ctl reconfigure
通路測試
通路:
http://192.168.136.201/
到此使用
Omnibus
安裝完成。
Docker安裝
Docker
的安裝、運作,就不在這裡列出了,不會的兄弟可以百度一下哦,比較簡單。
拉取鏡像
# 拉取鏡像(可能需要一些時間,耐心等待)
docker pull gitlab/gitlab-ce:latest
如果速度實在太慢,可以給
Docker
挂阿裡雲的鏡像加速器,具體操作,可以百度一下。
鏡像還是蠻大的,建議挂鏡像加速器。
運作容器
# 先建立目錄用于挂載容器資料
mkdir -p /root/gitlat/
# 運作容器
sudo docker run --detach \
--hostname 192.168.136.201 \
--publish 443:443 --publish 80:80 --publish 22222:22 \
--name gitlab-ce \
--restart always \
--volume /root/gitlat/config:/etc/gitlab \
--volume /root/gitlat/logs:/var/log/gitlab \
--volume /root/gitlat/data:/var/opt/gitlab \
gitlab/gitlab-ce:latest
檢視啟動日志:
docker logs gitlab-ce
排錯
- cannot create regular file ‘/etc/gitlab/gitlab.rb’: Permission denied
重新開機容器。# 修改selinux配置 vim /etc/selinux/config # 将SELINUX=enforcing改為SELINUX=disabled,修改後需要重新開機 reboot # 重新開機成功後檢視selinux狀态 sestatus # 執行指令得到一下結果 # SELinux status: disabled
-
各種端口占用問題
建議使用全新的機器安裝部署
,否則就更換映射端口吧。gitlab
通路測試
通路:
http://192.168.136.201/
測試建立了賬号和項目,沒有問題。