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


 

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
........


免責聲明!

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



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