Gitlab的介紹及使用

Gitlab 
1、GitLab簡介 
GitHub是2008年由Ruby on Rails編寫而成,與業界聞名的Github相似;但要將代碼上傳到 GitHub上面,並且將項目設爲私有還要收費。而 GitLab 則是開源免費的(社區版免費,企業版須要訂閱),可以瀏覽源代碼,管理缺陷和註釋,很是適合在團隊內部使用。 
1.1 Gitlab提供的功能 
代碼託管服務 
訪問權限控制 
問題跟蹤,bug的記錄、跟蹤和討論 
Wiki,項目中一些相關的說明和文檔 
代碼審查,能夠查看、評論代碼 
1.2 Gitlab(Github)和Git區別 
Github和Git是兩回事。 
Git是版本控制系統,Github是在線的基於Git的代碼託管服務。 
GitLab 是一個用於倉庫管理系統的開源項目。使用Git做爲代碼管理工具,可經過Web界面進行訪問公開的或者私人項目. 
1.3 Github PK Sourceforge 
爲何如今Github這麼火,以致於世界頂級公司和項目的源碼不少都託管在Github上 
Why? 
顏值高 
簡潔大方html

2011年,Github已經取代Sourceforge,成爲最活躍的代碼交流社區。這意味着在Open Source Community(開源社區),Git取代了SVN已經成爲事實。node

1.3.1 Github界面linux

1.3.2 Sourceforge界面nginx

2、Gitlab安裝 
2.1 環境配置 
硬件: 
Centos-6.x系列_x86_64 
Mem建議至少2G 
軟件: 
gitlab-ce.x86_64 0:8.8.0-ce 
server client 
192.168.201.131 192.168.201.130(做爲測試端) 
本次採用yum安裝方式 
2.2 安裝 
一、關閉SELinuxgit

下面的命令實現永久關閉SELinux

[root@git ~]# sed -i 's/^SELINUX=./#&/;s/^SELINUXTYPE=./#&/;/SELINUX=.*/a SELINUX=disabled' /etc/sysconfig/selinuxweb

下面的命令實現臨時關閉SELinux

[root@git ~]# setenforce 0 
setenforce: SELinux is disabledredis

永久修改下主機名,須要重啓系統以後生效

[root@git ~]# vi /etc/sysconfig/network 
NETWORKING=yes 
HOSTNAME=git.server.com #修改爲你本身的主機名sql

臨時修改

[root@git ~]#hostname git.server.comcentos

添加域名

[root@git ~]#cat /etc/hosts 
192.168.201.131 git.server.com 
二、關閉firewallruby

臨時關閉

[root@git yum.repos.d]# iptables -F 
[root@git yum.repos.d]# /etc/init.d/iptables stop 
iptables: Setting chains to policy ACCEPT: nat filter [ OK ] 
iptables: Flushing firewall rules: [ OK ] 
iptables: Unloading modules: [ OK ]

永久關閉,須要下次重啓系統以後生效

[root@git yum.repos.d]# chkconfig iptables off 
三、同步時間 
[root@git yum.repos.d]# ntpdate time.nist.gov 
10 Apr 11:00:04 ntpdate[40122]: step time server 216.229.0.179 offset 53747.856066 sec 
四、配置yum源 
[root@git yum.repos.d]# cat gitlab.repo 
[gitlab-ce] 
name=gitlab-ce 
baseurl=http://mirrors.tuna.tsinghua.edu.cn/gitlab-ce/yum/el6 
repo_gpgcheck=0 
gpgcheck=0 
enabled=1 
gpgkey=https://packages.gitlab.com/gpg.key 
註解: 
若是想要在centos7系列上安裝,只需把el6修改爲el7 
五、安裝Gitlab 
[root@git yum.repos.d]# yum install curl openssh-server openssh-clients postfix cronie -y 
[root@git yum.repos.d]# yum install gitlab-ce-8.8.0 -y 
六、修改下配置文件 
[root@git ~]# vi /etc/gitlab/gitlab.rb 
external_url 'http://git.server.com' 
external_url 修改爲本身的ip或者域名

修改配置文件以後,須要從新是配置文件生效下,初始化下

[root@git ~]#gitlab-ctl reconfigure #這裏會花費必定的時間 
Recipe: gitlab::gitlab-rails 
* execute[clear the gitlab-rails cache] action run 
- execute /opt/gitlab/bin/gitlab-rake cache:clear 
* execute[clear the gitlab-rails cache] action run 
- execute /opt/gitlab/bin/gitlab-rake cache:clear 
Recipe: gitlab::unicorn 
* service[unicorn] action restart 
- restart service service[unicorn] 
Recipe: gitlab::redis 
* ruby_block[reload redis svlogd configuration] action create 
- execute the ruby block reload redis svlogd configuration 
Recipe: gitlab::postgresql 
* ruby_block[reload postgresql svlogd configuration] action create 
- execute the ruby block reload postgresql svlogd configuration 
Recipe: gitlab::unicorn 
* ruby_block[reload unicorn svlogd configuration] action create 
- execute the ruby block reload unicorn svlogd configuration 
Recipe: gitlab::sidekiq 
* ruby_block[reload sidekiq svlogd configuration] action create 
- execute the ruby block reload sidekiq svlogd configuration 
Recipe: gitlab::gitlab-workhorse 
* service[gitlab-workhorse] action restart 
- restart service service[gitlab-workhorse] 
* ruby_block[reload gitlab-workhorse svlogd configuration] action create 
- execute the ruby block reload gitlab-workhorse svlogd configuration 
Recipe: gitlab::nginx 
* ruby_block[reload nginx svlogd configuration] action create 
- execute the ruby block reload nginx svlogd configuration 
Recipe: gitlab::logrotate 
* ruby_block[reload logrotate svlogd configuration] action create 
- execute the ruby block reload logrotate svlogd configuration

Running handlers: 
Running handlers complete 
Chef Client finished, 222/303 resources updated in 08 minutes 35 seconds

若是在此期間沒有出現error,證實成功

七、啓動Gitlab服務 
[root@git ~]# gitlab-ctl start 
ok: run: gitlab-workhorse: (pid 1407) 263s 
ok: run: logrotate: (pid 1403) 263s 
ok: run: nginx: (pid 1404) 263s 
ok: run: postgresql: (pid 1405) 263s 
ok: run: redis: (pid 1402) 263s 
ok: run: sidekiq: (pid 1400) 263s 
ok: run: unicorn: (pid 1401) 263s 
gitlab-workhorse這個「工做馬」,就是gitlab-Git-http-server(GitlabV8.0出現,V8.2名稱變動爲Gitlab-workhorse) 
sidekiq 多線程啓動 
unicorn是ruby的http server,能夠經過http://localhost:8080端口訪問 
重啓服務的一些命令 
gitlab-ctl start|stop|status|restart 
八、登陸 
http://192.168.201.131/users/sign_in 
因爲第一次登錄,須要設置密碼

登陸

登陸以後的界面

九、卸載 
從新安裝清理 
1,卸載 
[root@git Gitlab-cn]# gitlab-ctl uninstall 
2,刪除文件 
[root@git Gitlab-cn]#rm -rf /etc/gitlab/* /var/log/gitlab/ /var/opt/gitlab/ /opt/gitlab/ 
2.3 漢化 
查看版本 
[root@git .ssh]# cat /opt/gitlab/embedded/service/gitlab-rails/VERSION 
8.8.0 
下載漢化包並漢化 
[root@git hanhua]# git clone https://gitlab.com/larryli/gitlab.git Gitlab-cn && cd Gitlab-cn

生成補丁,

[root@git Gitlab-cn]#git diff origin/8-8-stable origin/8-8-zh > /tmp/8.8.diff

備份/opt/gitlab/embedded/service目錄下的gitlab-rails目錄,該目錄下的內容主要是web應用部分

[root@git Gitlab-cn]#cp -rf /opt/gitlab/embedded/service/gitlab-rails /tmp/gitlab-rails

關閉gitlab這個服務

打補丁

[root@git Gitlab-cn]#patch -d /opt/gitlab/embedded/service/gitlab-rails -p1 < /tmp/8.8.diff 
。。。。 
patching file public/ci/build-canceled.svg 
patching file public/ci/build-failed.svg 
patching file public/ci/build-pending.svg 
patching file public/ci/build-running.svg 
patching file public/ci/build-skipped.svg 
patching file public/ci/build-success.svg 
patching file public/ci/build-unknown.svg 
patching file public/deploy.html 
至此打補丁完成

測試是否漢化成功 
[root@git ~]# gitlab-ctl start 
ok: run: gitlab-workhorse: (pid 1407) 263s 
ok: run: logrotate: (pid 1403) 263s 
ok: run: nginx: (pid 1404) 263s 
ok: run: postgresql: (pid 1405) 263s 
ok: run: redis: (pid 1402) 263s 
ok: run: sidekiq: (pid 1400) 263s 
ok: run: unicorn: (pid 1401) 263s 
登陸 
http://192.168.201.131/users/sign_in

2.4 實戰測試 
http客戶端測試

建立測試目錄

[root@client ~]# mkdir test2 
[root@client ~]# cd test

把服務器的上倉庫clone下來

[root@cleint test2]# git clone http://git.server.com/root/test.git 
Cloning into 'test'... 
warning: You appear to have cloned an empty repository. 
Checking connectivity... done. 
[root@git test2]# ls 
test 

[root@cleint test2]# git config --global user.name "Administrator" 
[root@client test2]# git config --global user.email "admin@example.com" 
[root@client test2]# cd test/ 
[root@client test]# ls 
[root@client test]# touch README.md 
[root@client test]# vi README.md 
[root@client test]# git add README.md 
[root@client test]# git commit -m "add README" 
[master (root-commit) 874889b] add README 
1 file changed, 1 insertion(+) 
create mode 100644 README.md 
[root@client test]# git push -u origin master 
Username for 'http://git.server.com': root 
Password for 'http://root@git.server.com': adminroot 
Counting objects: 3, done. 
Writing objects: 100% (3/3), 223 bytes | 0 bytes/s, done. 
Total 3 (delta 0), reused 0 (delta 0) 
To http://git.server.com/root/test.git 
* [new branch] master -> master 
Branch master set up to track remote branch master from origin. 
從web上查看test倉庫下是否上傳了README.md這個文件

上傳成功 
ssh客戶端測試

生成公鑰

[root@node6 .ssh]# ssh-keygen 
Generating public/private rsa key pair. 
Enter file in which to save the key (/root/.ssh/id_rsa): 
Enter passphrase (empty for no passphrase): 
Enter same passphrase again: 
Your identification has been saved in /root/.ssh/id_rsa. 
Your public key has been saved in /root/.ssh/id_rsa.pub. 
The key fingerprint is: 
d9:0d:43:2b:17:cc:3b:01:fa:c9:cb:2c:6e:b7:27:6d root@node6 
The key's randomart image is: 
+--[ RSA 2048]----+ 
| .+o | 
| . .+o | 
| . . =o | 
| o *o+ | 
| S ... | 
| o . | 
| . +. | 
| ...o E | 
| ....= | 
+-----------------+ 
[root@node6 .ssh]# 
[root@node6 .ssh]# ls 
id_rsa id_rsa.pub 
[root@node6 .ssh]# cat id_rsa.pub 
ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEAoOLsYhPPlHPOnGh6SoVDPlVn2o8rfO55J60Gz7E0EDB0ugKgTu4VGOE8vVta7HH5exNAjw2UqHIliYcmVvrj5eFbvXLdLYGypiMfuP4H7dVwGXfxSzeG17aIbZma0fpB2bTQr3tN+nVA7tokVSmO+jC61/H6Qj9G1TEiedq0wtTuSQ8pza5hyeWRO9oi0W7ccZkYg7lSQ3Eo2n2/RJbmQHWdIcoBO8c64h5vq/gB1s7ZjHKUjSFvGTyHu7uYE6yD2PXylavLfq2FHUc4syV8yAvyW2ehgIcc+xDWMFC85SNuPvTOt0YNzG628gWB2lm+D8CPhZBUbz2IUkFN0jEdyQ== root@node6

添加這個(若是是真實的域名,這步不須要作)

[root@node6 .ssh]# vi /etc/hosts 
192.168.201.131 git.server.com

測試是否可用

[root@node6 .ssh]# ssh -T git@git.server.com 
The authenticity of host 'git.server.com (192.168.201.131)' can't be established. 
RSA key fingerprint is 45:1f:76:55:cb:72:fe:65:22:75:10:eb:d5:2e:35:d5. 
Are you sure you want to continue connecting (yes/no)? yes 
Warning: Permanently added 'git.server.com,192.168.201.131' (RSA) to the list of known hosts. 
Welcome to GitLab, Administrator! 
證實成功

拉取數據

[root@node6 .ssh]# git clone git@git.server.com:root/test.git Initialized empty Git repository in /root/.ssh/test/.git/ remote: Counting objects: 3, done. remote: Total 3 (delta 0), reused 0 (delta 0) Receiving objects: 100% (3/3), 223 bytes, done 

相關文章
相關標籤/搜索