GitLab是利用 Ruby on Rails 一個(gè)開源的版本管理系統(tǒng)初肉,實(shí)現(xiàn)一個(gè)自托管的Git項(xiàng)目倉庫,可通過Web界面進(jìn)行訪問公開的或者私人項(xiàng)目轨域。它擁有與Github類似的功能,能夠?yàn)g覽源代碼,管理缺陷和注釋隅茎。可以管理團(tuán)隊(duì)對(duì)倉庫的訪問嫉沽,它非常易于瀏覽提交過的版本并提供一個(gè)文件歷史庫辟犀。團(tuán)隊(duì)成員可以利用內(nèi)置的簡(jiǎn)單聊天程序(Wall)進(jìn)行交流。它還提供一個(gè)代碼片段收集功能可以輕松實(shí)現(xiàn)代碼復(fù)用绸硕,便于日后有需要的時(shí)候進(jìn)行查找堂竟。
官網(wǎng)寫的安裝已經(jīng)很全面,后面基本都是web可視化操作玻佩,考驗(yàn)Git能力出嘹,我這里就照抄下來啦。
Centos 6.7 Install Gitlab
1. Config git info
[root@gitlab-machine ~]# git config --global user.name "whoami"
[root@gitlab-machine ~]# git config --global user.email "whoami@itweet.cn"
[root@gitlab-machine ~]# git config --global color.ui true
[root@gitlab-machine ~]# git config --list
user.name=whoami
user.email=whoami@itweet.cn
color.ui=true
2.Install and configure the necessary dependencies
If you install Postfix to send email please select 'Internet Site' during setup. Instead of using Postfix you can also use Sendmail or configure a custom SMTP server and configure it as an SMTP server.
On Centos 6 and 7, the commands below will also open HTTP and SSH access in the system firewall.
[root@gitlab-machine ~]# sudo yum install curl openssh-server openssh-clients postfix cronie
[root@gitlab-machine ~]# sudo service postfix start
[root@gitlab-machine ~]# sudo chkconfig postfix on
[root@gitlab-machine ~]# sudo lokkit -s http -s ssh
3. Add the GitLab package server and install the package
curl -sS https://packages.gitlab.com/install/repositories/gitlab/gitlab-ce/script.rpm.sh | sudo bash
sudo yum install gitlab-ce
If you are not comfortable installing the repository through a piped script, you can find the entire script here and select and download the package manually and install using
Download RPM Package:
https://packages.gitlab.com/gitlab/gitlab-ce
curl -LJO https://packages.gitlab.com/gitlab/gitlab-ce/packages/el/6/gitlab-ce-XXX.rpm/download
rpm -i gitlab-ce-XXX.rpm
For example
[root@gitlab-machine ~]# lsof -i :80|wc -l
0
[root@gitlab-machine ~]# netstat -lntp|grep 80|wc -l
0
[root@gitlab-machine ~]# ls -l gitlab-ce-8.7.0-ce.0.el6.x86_64.rpm
-rwxr-xr-x 1 root root 261779557 May 2 14:06 gitlab-ce-8.7.0-ce.0.el6.x86_64.rpm
[root@gitlab-machine ~]# rpm -ivh gitlab-ce-8.7.0-ce.0.el6.x86_64.rpm
Preparing... ########################################### [100%]
1:gitlab-ce ########################################### [100%]
hostname: Host name lookup failure
gitlab: Thank you for installing GitLab!
gitlab: To configure and start GitLab, RUN THE FOLLOWING COMMAND:
sudo gitlab-ctl reconfigure
gitlab: GitLab should be reachable at http://gitlab.example.com
gitlab: Otherwise configure GitLab for your system by editing /etc/gitlab/gitlab.rb file
gitlab: And running reconfigure again.
gitlab:
gitlab: For a comprehensive list of configuration options please see the Omnibus GitLab readme
gitlab: https://gitlab.com/gitlab-org/omnibus-gitlab/blob/master/README.md
gitlab:
It looks like GitLab has not been configured yet; skipping the upgrade script.
4.Configure and start GitLab
[root@gitlab-machine ~]# sudo gitlab-ctl reconfigure
Starting Chef Client, version 12.6.0
...omit...
Running handlers:
Running handlers complete
Chef Client finished, 221/300 resources updated in 01 minutes 24 seconds
gitlab Reconfigured!
[root@gitlab-machine ~]# lsof -i :80
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
nginx 2392 root 6u IPv4 83966 0t0 TCP *:http (LISTEN)
nginx 2394 gitlab-www 6u IPv4 83966 0t0 TCP *:http (LISTEN)
[root@gitlab-machine ~]# netstat -lnop|grep 80|wc -l
3
修改gitlab倉庫地址
[root@gitlab-server data]# cat /etc/gitlab/gitlab.rb |grep git_data
# git_data_dir "/var/opt/gitlab/git-data"
git_data_dir "/data/gitlab/git-data"
[root@gitlab-server data]# sudo gitlab-ctl reconfigure
[root@gitlab-server data]# sudo gitlab-ctl restart
5咬崔、Browse to the hostname and login
On your first visit, you'll be redirected to a password reset screen to provide the password for the initial administrator account. Enter your desired password and you'll be redirected back to the login screen.
The default account's username is root. Provide the password you created earlier and login. After login you can change the username if you wish.
For configuration and troubleshooting options please see the Omnibus GitLab documentation
If you are located in China, try using https://mirror.tuna.tsinghua.edu.cn/help/gitlab-ce/
訪問地址http://gitlab.itweet.cn:80 (需要提前映射好域名和ip地址到hosts文件),第一次訪問税稼,提示’Change your password‘頁面烦秩,你可以輸入密碼,此密碼即為root密碼郎仆;然后可用此密碼登錄root用戶只祠,比如我這里設(shè)置為root/admin123。
[圖片上傳失敗...(image-f6d7f0-1513993971279)]
6扰肌、入門使用
基本都是web可視化操作抛寝。這里我簡(jiǎn)單減少幾個(gè)概念吧。
6.1 Project 可以發(fā)起一個(gè)項(xiàng)目曙旭,查詢當(dāng)前用戶所擁有或者能管理的項(xiàng)目列表
6.2 Users 用戶管理模塊墩剖,管理員可見。
6.3 Groups 組織機(jī)構(gòu)夷狰,公司管理岭皂;比如一個(gè)公司可以開啟一個(gè)groups下面有很多開發(fā)人員。
6.4 Deploy keys 免密碼ssh驗(yàn)證沼头,git提交或者拉去代碼爷绘,可以免密碼驗(yàn)證。
6.5 SSH keys
當(dāng)我們從GitHub或者GitLab上clone項(xiàng)目或者參與項(xiàng)目時(shí)进倍,我們需要證明我們的身份土至。一種可能的解決方法是我們?cè)诿看卧L問的時(shí)候都帶上賬戶名、密碼猾昆,另外一種辦法是在本地保存一個(gè)唯一key陶因,在你的賬戶中也保存一份該key,在你訪問時(shí)帶上你的key即可垂蜗。GitHub楷扬、GitLab就是采用key來驗(yàn)證你的身份的,并且利用RSA算法來生成這個(gè)密鑰贴见。
[root@gitlab-machine ~]# git config --list
user.name=whoami
user.email=whoami@itweet.cn
color.ui=true
[root@gitlab-machine ~]# ssh-keygen -t rsa -C "whoami@itweet.cn"
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa):
Created directory '/root/.ssh'.
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:
05:07:1c:92:ec:ec:79:cd:09:96:a3:8e:a3:13:bf:e2 xujiang@itweet.cn
The key's randomart image is:
+--[ RSA 2048]----+
| ..o+o. |
| o..o |
| o .. |
| o =. |
| . +S= . |
| . + . + |
| o o . |
| o + . |
| .E+.o |
+-----------------+
[root@gitlab-machine ~]# cat .ssh/id_rsa.pub
ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEAtWly2W39tM88fNrPHDoutQUe/iZZonOs/Qf8ZVxF+Kyivj8PrvlR83MmPoBbGwF/YOn5EHROEBy2EAFCHk+zQZ9uHJlsRF4EU6Aq5yZBfOTA8erdllDIy25BLITAhNe4AXmcGKJMl/TmNBWmN5+GjmTyL5l85+hMTUM3cUT8WVhPDFGlm+3UPh1AwptlDOe+t0XX6dl39BZ3i1CTmh+X38Q1K7RHkIjSSeUZQANGzJlfENQqse/zhENvUftk4EwRXL6+RIPwdk+ijAvnKGIwIfSx75u51E29jvvnP8FidU0HnBsbbedFg6cWlnMj/6AgXxnP22skmEBRAlRb7qO/zQ== xujiang@itweet.cn
添加烘苹,id_rsa.pub到ssh keys 頁面,即可完成認(rèn)證片部。如下驗(yàn)證:
[root@gitlab-machine data]# git clone git@gitlab.itweet.cn:xujiang/test.git
Initialized empty Git repository in /data/test/.git/
The authenticity of host 'gitlab.itweet.cn (192.168.1.125)' can't be established.
RSA key fingerprint is d4:2d:bb:87:cf:41:ff:fd:64:b7:66:56:45:f2:d1:64.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added 'gitlab.itweet.cn,192.168.1.125' (RSA) to the list of known hosts.
remote: Counting objects: 6, done.
remote: Compressing objects: 100% (4/4), done.
Receiving objects: 100% (6/6), 4.30 KiB, done.
remote: Total 6 (delta 0), reused 0 (delta 0)
[root@gitlab-machine data]# pwd
/data
[root@gitlab-machine data]# tree
.
└── test
├── LICENSE
└── README.md
2 directories, 2 files
For Examples
[root@gitlab-machine data]# cd test/
[root@gitlab-machine test]# cat hello.py
#!/usr/bin/python
print("hello itweet.cn!")
[root@gitlab-machine test]# git add hello.py
[root@gitlab-machine test]# git commit -m 'first python script...'
[master 25bddfa] first python script...
1 files changed, 2 insertions(+), 0 deletions(-)
create mode 100644 hello.py
[root@gitlab-machine test]# git push origin master
Counting objects: 4, done.
Compressing objects: 100% (2/2), done.
Writing objects: 100% (3/3), 351 bytes, done.
Total 3 (delta 0), reused 0 (delta 0)
To git@gitlab.itweet.cn:whoami/test.git
f0eb0f6..25bddfa master -> master
6.6 導(dǎo)入項(xiàng)目可以支持來自多個(gè)主流代碼托管地,可以是本地初始化項(xiàng)目镣衡。
[圖片上傳失敗...(image-942858-1513993971279)]
[圖片上傳失敗...(image-91bac1-1513993971279)]
[圖片上傳失敗...(image-7db04-1513993971279)]
導(dǎo)入成功后,基本上可以看到档悠,所有的github相關(guān)的代碼廊鸥,版本都會(huì)獲取過來。包括社區(qū)全部完整的信息辖所。更多功能參考:https://about.gitlab.com/gitlab-ce-features/
Git GUI
Git-scm: https://git-scm.com/downloads
-
SourceTree: https://www.sourcetreeapp.com/
- SourceTree 是 Windows 和Mac OS X 下免費(fèi)的 Git 和 Hg 客戶端惰说,擁有可視化界面,容易上手操作奴烙。同時(shí)它也是Mercurial和Subversion版本控制系統(tǒng)工具助被。支持創(chuàng)建剖张、提交切诀、clone揩环、push、pull 和merge等操作幅虑。
Markdown format document
For windows:
- MakrdownPad
- http://www.markdownpad.com/
For Mac:
- Mou,Mweb
- http://25.io/mou/
FAQ
I. 如果提示:“You won't be able to pull or push project code via SSH until you add an SSH key to your profile Don't show again | Remind later”
解決:需要本地配置.ssh免密碼登錄丰滑,可以通過ssh隧道git clone項(xiàng)目,效率會(huì)高得多倒庵。II. Gitlab 項(xiàng)目地址不對(duì)褒墨,希望是自己的域名地址,如:“git@gitlab.example.com:itweet.cn/hadoop.git”,希望是:“git@gitlab.itweet.cn:itweet.cn/hadoop.git”
解決:
[root@gitlab-machine ~]# sudo vim /etc/gitlab/gitlab.rb
## external_url 'http://gitlab.example.com'
external_url 'http://gitlab.itweet.cn'
[root@gitlab-machine gitlab]# sudo gitlab-ctl reconfigure
[root@gitlab-machine ~]# sudo gitlab-ctl restart
- III. Email發(fā)送郵件失敗
需要發(fā)送郵件的用戶擎宝,比如使用qq發(fā)送郁妈,需要SMTP settings,并且發(fā)郵件用戶開啟smtp/impi功能。
For examples
gitlab_rails['smtp_enable'] = true
gitlab_rails['smtp_address'] = "smtp.exmail.qq.com"
gitlab_rails['smtp_port'] = 465
gitlab_rails['smtp_user_name'] = "xxxx@xx.com"
gitlab_rails['smtp_password'] = "password"
gitlab_rails['smtp_authentication'] = "login"
gitlab_rails['smtp_ssl'] = true
gitlab_rails['smtp_enable_starttls_auto'] = true
gitlab_rails['smtp_tls'] = false
參考:https://gitlab.com/gitlab-org/omnibus-gitlab/blob/master/doc/settings/configuration.md#configuring-the-external-url-for-gitlab
https://gitlab.com/gitlab-org/omnibus-gitlab/blob/master/doc/settings/smtp.md#smtp-on-localhost
http://itweet.github.io/2015/07/12/git-manual/
https://help.github.com/desktop/guides/getting-started/
原創(chuàng)文章绍申,轉(zhuǎn)載請(qǐng)注明: 轉(zhuǎn)載自Itweet的博客
本博客的文章集合:
http://www.itweet.cn/blog/archive/