[原創]CI持續整合系統環境---部署Gitlab環境完整記錄

散盡浮華發表於2016-07-07

 

Gitlab是一個程式碼託管平臺,在實際工作中,對程式碼管理十分有用。廢話不多說,下面是對我自己搭建的Gitlab環境做一記錄:
1)安裝
------------------------------------------------------------------------
或者直接下載bitnami-gitlab-7.1.1-0-linux-x64-installer.run
下載地址:http://pan.baidu.com/s/1i4RaCKH
提取密碼:tcia

bitnami-gitlab-8.5.1-0-linux-x64-installer.run版本
下載地址:https://pan.baidu.com/s/1i5pbFlb
提取密碼:eq2d

-------------------------------------------------------------------------
Gitlab的安裝採用的是一鍵安裝方式
[root@115 ~]#cd /opt
[root@115 ~]#wget https://bitnami.com/redirect/to/39039/bitnami-gitlab-8.8.4-0-linux-x64-installer.run
[root@115 ~]#chmod 755 bitnami-gitlab-8.8.4-0-linux-x64-installer.run
[root@115 ~]#./bitnami-gitlab-7.1.1-0-linux-x64-installer.run                       //一路回車

---------------------------------------------------------------------
Welcome to the Bitnami Gitlab Stack Setup Wizard.
---------------------------------------------------------------------
Select the components you want to install; clear the components you do
not want
to install. Click Next when you are ready to continue.
GitLab : Y (Cannot be edited)
GitLab CI [Y/n] :Y
Is the selection above correct? [Y/n]: Y
---------------------------------------------------------------------
Installation folder
Please, choose a folder to install Bitnami Gitlab Stack
Select a folder [/opt/gitlab-7.4.3-0]:
---------------------------------------------------------------------
Create Admin account
Bitnami Gitlab Stack admin user creation
Email Address [xschao@xxx.com]:
Login [xschao]:
Password :xxxxxxxxxxx
Please confirm your password :
---------------------------------------------------------------------
-------
Hostname that will be used to create internal URLs. If this value is
incorrect,
you may be unable to access your Gitlab installation from other computers.
It is
advisable to use a Domain instead of an IP address for compatibility with
different browsers.
Domain [127.0.0.1]:                             //這裡最好寫外網 ip 或者域名
Do you want to configure mail support? [y/N]: y
---------------------------------------------------------------------
Configure SMTP Settings
This is required so your application can send notifications via email.
Default email provider:
[1] GMail
[2] Custom
Please choose an option [1] : 1
---------------------------------------------------------------------
Configure SMTP Settings
This data is stored in the application configuration files and may be
visible to
others. For this reason, it is recommended that you do not use your
personal
account credentials.
GMail address []: xschao.test@gmail.com
GMail password :
Re-enter :
---------------------------------------------------------------------
Setup is now ready to begin installing Bitnami Gitlab Stack on your
computer.
Do you want to continue? [Y/n]: Y
---------------------------------------------------------------------
-------
Please wait while Setup installs Bitnami Gitlab Stack on your computer.
Installing
0% ______________ 50% ______________ 100%

2)啟動命令
[root@115 ~]#/opt/gitlab-8.8.4-0/ctlscript.sh start/restart/stop

3)訪問
http://ip:埠
在遠端可以使用ssh方式連線gitlab並clone程式碼
需要先將遠端客戶端機器的公鑰放到Gitlab的SSH Keys裡面,做成無密碼的信任關係
------------------------------------------------------------------------------------------------------------------------------------------
修改gitlab的訪問埠,需要修改下面幾個檔案:
/opt/gitlab-8.8.4-0/apache2/conf/httpd.conf
/opt/gitlab-8.8.4-0/apache2/conf/bitnami/bitnami.conf
/opt/gitlab-8.8.4-0/apps/gitlab/gitlab-shell/config.yml
/opt/gitlab-8.8.4-0/apps/gitlab/htdocs/config/gitlab.yml
------------------------------------------------------------------------------------------------------------------------------------------
修改gitlab訪問的ip或域名
/opt/gitlab-8.8.4-0/apps/gitlab/gitlab-shell/config.yml
/opt/gitlab-8.8.4-0/apps/gitlab/htdocs/config/gitlab.yml

例如我這裡修改如下:之前是ip訪問(假設埠是8081,ip為111.112.113.45),現在改為域名訪問(假設域名為git.huanqiu.net)
[root@115 ~]# vim /opt/gitlab-8.8.4-0/apps/gitlab/gitlab-shell/config.yml
.......
gitlab_url: http://git.huanqiu.net:8081/

[root@115 ~]# vim /opt/gitlab-8.8.4-0/apps/gitlab/htdocs/config/gitlab.yml
.......
gitlab:
## Web server settings (note: host is the FQDN, do not include http://)
host: git.huanqiu.net
port: 8081 # Set to 443 if using HTTPS, see installation.md#using-https for additional HTTPS configuration details
https: false

最後重啟服務
[root@115 gitlab-8.8.4-0]# pwd
/opt/gitlab-8.8.4-0
[root@115 gitlab-8.8.4-0]# ./ctlscript.sh restart

最好在/etc/hosts檔案裡做下對映(此步驟不是必須)
[root@115 ~]# vim /etc/hosts
111.112.113.45 git.huanqiu.net
--------------------------------------------------------------------------------------------------------------------------------------
linux客戶端使用ssh方式連線gitlab
其實只需要將linux客戶機的公鑰內容拷貝到gitlab的“Profile Settings”->"SSH Keys"裡

比如:
使用“王士博”賬號登陸gitlab
同一個gitlab賬號下可以新增多個Keys,也就是可以對應多臺客戶機的Keys,也可以是同一臺客戶機的不同賬號下的Keys;
注意Keys中公鑰內容可以通過郵件去識別,也可以不跟郵件識別(比如在linux客戶機和windows本地都產生公私鑰,公鑰內容中的郵件可以都用wangshibo@huanqiu.com)特別注意一點:新增不同客戶機上的相關賬號公鑰後,就只能在這個賬號狀態下進行git程式碼下載。比如下面新增了客戶機的wangshibo賬號下的公鑰,就只能在這臺主機的wangshibo賬號下進行git程式碼下載,在root賬號下是下載不了的,會一直提示輸入密碼.....
1)首先需要在linux客戶機上生成公私鑰
[root@test-huanqiu ~]# useradd wangshibo
[root@test-huanqiu ~]# su - wangshibo
[wangshibo@redmine ~]$ ssh-keygen -t rsa -C “wangshibo@huanqiu.com" //也可以不跟-C進行後面的郵件識別,一路回車
......
......
[wangshibo@test-huanqiu ~]$ cd .ssh/
[wangshibo@test-huanqiu .ssh]$ ls
id_rsa id_rsa.pub
[wangshibo@test-huanqiu .ssh]$ cp id_rsa.pub authorized_keys
[wangshibo@localhost .ssh]$ cat id_rsa.pub
ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEAmMF2BG6uDnPYukynYfvWT7jbwYlaqEOEuN2Z3CKvIX0WhiM0mRwsRYXpR2snUXrXhki6CTR3frUzgbdIe+KMN9f9LxsnEeyWWheiGdNj6nm4UgondFA0rW6N5zGXHbDz7Q/clr/jX6K7ChhLd4iH7yKsZFCwo827xIVD0D+oFTQKRaC/eXS5FVFgsEE8FlGOt9hOwBT85dwaNBaSJ2+xfc9CADGYdyVE06FAGbbM+76QAvxllvIr8RJmVamd3dME1fi8lXgn7CLQKZE/4lTfOFNTw3BGtcgD9MwQfE2pwdrLK92tHaaaZ28kYChkAdNrlDnWL6e7ady9IkPQwGaUMw== wangshibo@huanqiu.com

2)將上面產生的公鑰內容新增到gitlab上,如下:

可以在下面的“Title”處註明公鑰資訊,方便管理

 

 檢視已新增的Keys

3)在客戶機通過ssh連線gitlab,比如下載gitlab的test工程程式碼,進行操作。操作步驟如下:

 

注意下面在git clone程式碼前進行的”Git global setup“全域性設定:
第一行對應的是gitlab的使用者名稱
第二行對應的是這個使用者下的Keys的名稱(如果建立公私鑰時,用-C “郵箱”方式進行祕鑰識別,那麼這裡就用郵箱;如果建立公私鑰時沒有用-C “郵箱”識別,那麼這裡對應的就只是單純的Keys的名稱了,在gitlab控制檯的SSH-Keys裡能檢視到)

注意:
使用ssh方式git clone下載程式碼時,本機必須要能連通gitlab機器的ssh服務埠(預設是22)。不然即便將公鑰新增上,也是徒勞!

----------------------------------------------------------------------------------------------------------------------------------------------
解決Gitlab的Gravatar頭像無法顯示的問題,如下:

解決辦法:

修改/opt/gitlab-8.8.4-0/apps/gitlab/htdocs/config/gitlab.yml檔案的下面兩行

.........

gravatar:
# gravatar urls: possible placeholders: %{hash} %{size} %{email}
#plain_url: "http://..." # default: http://www.gravatar.com/avatar/%{hash}?s=%{size}&d=identicon
plain_url: "http://gravatar.duoshuo.com/avatar/%{hash}?s=%{size}&d=identicon"               //新增這一行
# ssl_url: "https://..." # default: https://secure.gravatar.com/avatar/%{hash}?s=%{size}&d=identicon

.........

gravatar:
enabled: false                      //由true改為false

重啟服務

/opt/gitlab-8.8.4-0/ctlscript.sh restart

再次訪問,gravatar圖片就顯示出來了

----------------------修改gitlab的logo圖示----------------------

將下面路徑下的gitlab_logo.png圖片更換即可,注意圖片名稱不要變!

[root@localhost images]# pwd
/opt/gitlab-8.8.4-0/apps/gitlab/htdocs/app/assets/images
[root@localhost images]# ll gitlab_logo.png 
-rw-rw-r--. 1 git git 5189 6月  10 2016 gitlab_logo.png

----------------------解決gitlab上上傳頭像圖片不顯示問題----------------------

如下,在gitlab登陸使用者的設定裡面上傳頭像

如果上傳頭像不顯示,是因為目錄許可權的問題,解決辦法如下:

[root@localhost gitlab-8.8.4-0]# pwd
/opt/gitlab-8.8.4-0
[root@localhost gitlab-8.8.4-0]# chmod -R 777 apps/gitlab/htdocs/public/uploads

-----------------------------設定gitlab裡對應group的圖片----------------------------------------------
Edit編輯gitlab對應group,選擇"Group avatar"->點選"Choose file",上傳圖片即可!
如果上傳的group圖片不顯示,修改許可權:
#chmod 777 -R /opt/gitlab-8.8.4-0/apps/gitlab/htdocs/public/uploads/group

----------------------------------------------------------------------------------------------------------
下面記錄在windows客戶端使用TortoiseGit的ssh方式連線gitlab的記錄
下面兩個客戶端軟體的下載地址是:http://pan.baidu.com/s/1slqxcMp (提取密碼:keks)

 

 

 

======================================
需要注意的問題:
在通過ssh方式連線gitlab的時候,明明已經上傳了公鑰到gitlab了,但是在連線時候還是提示輸入密碼!

原因:
1)注意在git clone的時候,一定要使用git方式,別使用http方式。
2)公鑰上傳到gitlab,並且私鑰ppk檔案配對後,原則上來說在git bash裡面通過"ssh -p22 root@gitlab.zlibs.com"是能登入到gitlab伺服器的(gitlab.zlibs.com是gitlab伺服器主機名)。
3)如果gitlab.zlibs.com是通過代理層nginx轉到gitlab伺服器的,則需要在客戶機的hosts裡面做gitlab伺服器ip和其主機名的繫結關係。
4)在git bash裡面做git global setup:
git config --global user.name "wangshibo"
git config --global user.email "wangshibo@huanqiu.com"
git clone git@gitlab.zlibs.com:ops/ops-maintain.git
........

相關文章