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 [[email protected]]:
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
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 []: [email protected]
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或域名
例如我這裡修改如下:之前是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本地都産生公私鑰,公鑰内容中的郵件可以都用[email protected])。特别注意一點:添加不同客戶機上的相關賬号公鑰後,就隻能在這個賬号狀态下進行git代碼下載下傳。比如下面添加了客戶機的wangshibo賬号下的公鑰,就隻能在這台主機的wangshibo賬号下進行git代碼下載下傳,在root賬号下是下載下傳不了的,會一直提示輸入密碼.....
1)首先需要在linux客戶機上生成公私鑰
[root@test-huanqiu ~]# useradd wangshibo
[root@test-huanqiu ~]# su - wangshibo
[wangshibo@redmine ~]$ ssh-keygen -t rsa -C “[email protected]" //也可以不跟-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== [email protected]
2)将上面産生的公鑰内容添加到gitlab上,如下:

注意下面在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
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 [email protected]"是能登入到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 "[email protected]"
git clone [email protected]:ops/ops-maintain.git
........
*************** 當你發現自己的才華撐不起野心時,就請安靜下來學習吧!***************