1. 程式人生 > >簡單Gitlab伺服器的搭建(Gitlab+GerRit+Jenkins)

簡單Gitlab伺服器的搭建(Gitlab+GerRit+Jenkins)

目前程式碼版本控制分為兩種:集中式管理SVN和分散式管理Git,微軟近期以75億美元收購了Github平臺,而GitLab也頗受企業喜愛,因為Github平臺只能提供一個私有倉庫,而Gitlab伺服器可以企業自己搭建。下面就是簡單Gitlab伺服器的搭建過程。

伺服器硬體配置介紹:

如果低於4GB+2vCPU請不要嘗試,浪費時間。

就算你配置好了,啟動了,clone和push程式碼時也會有各種問題,類似API不可讀等。

清華開源軟體映象站wget下載安裝ce版本:

yum -y install policycoreutils openssh-server openssh-clients postfix
yum install policycoreutils-python
systemctl enable postfix && systemctl start postfix
wget https://mirrors.tuna.tsinghua.edu.cn/gitlab-ce/yum/el7/gitlab-ce-9.0.13-ce.0.el7.x86_64.rpm
rpm -i gitlab-ce-10.8.4-ce.0.el7.x86_64.rpm

如果安裝postfix時出現了以下錯誤:parameter inet_interfaces: no local interface found for ::1

解決方案如下: vi /etc/postfix/main.cf 修改配置 inet_interfaces = localhost 為 inet_interfaces = all

完成以上安裝步驟在配置檔案/etc/gitlab/gitlab.rb中新增:

external_url 'http://your IP:your port'

執行配置命令:

gitlab-ctl reconfigure 

修改配置檔案 修改:

vim ./gitlab/embedded/service/gitlab-shell/config.yml

gitlab_url: "http://IP:port"

啟動Gitlab:

gitlab-ctl start 

如果頁面開啟沒有輸入管理員密碼的請刪除資料儲存目錄重新安裝,如果還是不行請換版本安裝。

如果在建立庫之後無法通過點選建立庫檔案按鈕來建立,網頁回覆為沒許可權讀則替換版本,這是8版本中的一個bug。

管理員賬號為root

之後生成ssh祕鑰並且將公鑰複製到賬號下的ssh管理區域,便於程式碼無祕下載和之後利用各伺服器外掛來溝通。

 ssh-keygen -t rsa -C 'your email' 

之後可以建立庫和建立組管理的庫,我們可以給組下的成員相關的許可權級別,是Owner、Master、Developer、Reporter、Guest。測試ssh配置

ssh -T [email protected]**.**.***.***
Welcome to GitLab, Administrator!

建立一個私有倉庫之後,除了管理員,其他成員只能clone,不能push,這也為GerRit的git review提供了保證,在 Replication外掛(GerRit中介紹)中可以使用管理員許可權來同步倉庫

如果在ssh新增公鑰之後還是需要輸入密碼,這個時候可能是git使用者被鎖。

出錯資訊如下:

vim /var/log/secure:
Jun 17 22:32:22 jiche sshd[14931]: reprocess config line 50: Deprecated option RSAAuthentication
Jun 17 22:32:22 jiche sshd[14931]: User git not allowed because account is locked
Jun 17 22:32:22 jiche sshd[14931]: input_userauth_request: invalid user git [preauth]
Jun 17 22:32:24 jiche sshd[14931]: Connection closed by **.**.***.*** port 47170 [preauth]

原因:git使用者沒有設定密碼

解除git使用者被鎖狀態,以root許可權執行後重啟服務:

#passwd -u -f git
Unlocking password for user git.
passwd: Success