Gitlab的介绍及使用

Gitlab 
一、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? 
颜值高 
简洁大方

2011年,Github已经取代Sourceforge,成为最活跃的代码交流社区。这意味着在Open Source Community(开源社区),Git取代了SVN已经成为事实。

1.3.1 Github界面

1.3.2 Sourceforge界面

二、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 安装 
1、关闭SELinux

下面的命令实现永久关闭SELinux

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

下面的命令实现临时关闭SELinux

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

永久修改下主机名,需要重启系统之后生效

[root@git ~]# vi /etc/sysconfig/network 
NETWORKING=yes 
HOSTNAME=git.server.com #修改成你自己的主机名

临时修改

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

添加域名

[root@git ~]#cat /etc/hosts 
192.168.201.131 git.server.com 
2、关闭firewall

临时关闭

[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 
3、同步时间 
[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 
4、配置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 
5、安装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 
6、修改下配置文件 
[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,证明成功

7、启动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 
8、登录 
http://192.168.201.131/users/sign_in 
由于第一次登陆,需要设置密码

登录

登录之后的界面

9、卸载 
重新安装清理 
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 "[email protected]
[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://[email protected]': 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 [email protected] 
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 [email protected]: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 



本文转自 维度2018 51CTO博客,原文链接:http://blog.51cto.com/xinsz08/1915883,如需转载请自行联系原作者

你可能感兴趣的:(git,运维,ruby)