Gitlab是一個代碼託管平臺,在實際工做中,對代碼管理十分有用。廢話很少說,下面是對我本身搭建的Gitlab環境作一記錄:
1)安裝
------------------------------------------------------------------------
或者直接下載bitnami-gitlab-7.1.1-0-linux-x64-installer.run
下載地址:http://pan.baidu.com/s/1i4RaCKH
提取密碼:tcialinux
bitnami-gitlab-8.5.1-0-linux-x64-installer.run版本
下載地址:https://pan.baidu.com/s/1i5pbFlb
提取密碼:eq2dnginx
-------------------------------------------------------------------------
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 //一路回車git
---------------------------------------------------------------------
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%shell
2)啓動命令
[root@115 ~]#/opt/gitlab-8.8.4-0/ctlscript.sh start/restart/stopapache
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.ymlvim
例如我這裏修改以下:以前是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/windows
[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: falsebash
最後重啓服務
[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"裏app
好比:
使用「王士博」帳號登錄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圖片更換便可,注意圖片名稱不要變!
1 2 3 4 |
|
----------------------解決gitlab上上傳頭像圖片不顯示問題----------------------
以下,在gitlab登錄用戶的設置裏面上傳頭像
若是上傳頭像不顯示,是由於目錄權限的問題,解決辦法以下:
1 2 3 |
|
-----------------------------設置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
........
***************當你發現本身的才華撐不起野心時,就請安靜下來學習吧***************