GitLab的安装部署

GitHub和GitLab的区别

相同点:二者都是基于web的Git仓库,在很大程度上GitLab是仿照GitHub来做的,它们都提供了分享开源项目的平台,为开发团队提供了存储、分享、发布和合作开发项目的中心化云存储的场所。

GitHub作为开源代码库及版本控制系统,拥有超过900万的开发者用户,目前仍然是最火的开源项目托管系统。GitHub同时提供公共仓库和私有仓库,但如果要使用私有仓库,是需要付费的。

而GitLab解决了这个问题,你可以在上面创建私人的免费仓库。

GitLab让开发团队对他们的代码仓库拥有更多的控制,相比于GitHub,它有不少的特色:

允许免费设置仓库权限;允许用户选择分享一个project的部分代码;允许用户设置project的获取权限,进一步的提升安全性;可以设置获取到团队整体的改进进度;通过innersourcing让不在权限范围内的人访问不到该资源。

从代码私有性方面来看,有时公司并不希望员工获取到全部的代码,这个时候GitLab无疑是更好的选择。但对于开源项目而言,GitHub依然是代码托管的首选。

GitLab基本介绍

GitLab是利用Ruby on Rails一个开源的版本管理系统,实现一个自托管的Git项目仓库,可通过Web界面进行访问公开的或者私人项目。
与Github类似,GitLab能够浏览源代码,管理缺陷和注释。可以管理团队对仓库的访问,它非常易于浏览提交过的版本并提供一个文件历史库。团队成员可以利用内置的简单聊天程序(Wall)进行交流。
它还提供一个代码片段收集功能可以轻松实现代码复用,便于日后有需要的时候进行查找。

Git的家族成员

Git:是一种版本控制系统,是一个命令,是一种工具。
Gitlib:是用于实现Git功能的开发库。
Github:是一个基于Git实现的在线代码托管仓库,包含一个网站界面,向互联网开放。
GitLab:是一个基于Git实现的在线代码仓库托管软件,你可以用gitlab自己搭建一个类似于Github一样的系统,一般用于在企业、学校等内部网络搭建git私服。

Gitlab的服务构成

Nginx:静态web服务器。
gitlab-shell:用于处理Git命令和修改authorized keys列表。
gitlab-workhorse: 轻量级的反向代理服务器。
logrotate:日志文件管理工具。
postgresql:数据库。
redis:缓存数据库。
sidekiq:用于在后台执行队列任务(异步执行)。
unicorn:An HTTP server for Rack applications,GitLab Rails应用是托管在这个服务器上面的。

GitLab工作流程

这里写图片描述

GitLab Shell
GitLab Shell有两个作用:为GitLab处理Git命令、修改authorized keys列表。
当通过SSH访问GitLab Server时,GitLab Shell会:

限制执行预定义好的Git命令(git push, git pull, git annex)
调用GitLab Rails API 检查权限
执行pre-receive钩子(在GitLab企业版中叫做Git钩子)
执行你请求的动作 处理GitLab的post-receive动作
处理自定义的post-receive动作

当通过http(s)访问GitLab Server时,工作流程取决于你是从Git仓库拉取(pull)代码还是向git仓库推送(push)代码。
如果你是从Git仓库拉取(pull)代码,GitLab Rails应用会全权负责处理用户鉴权和执行Git命令的工作;
如果你是向Git仓库推送(push)代码,GitLab Rails应用既不会进行用户鉴权也不会执行Git命令,它会把以下工作交由GitLab Shell进行处理:

调用GitLab Rails API 检查权限
执行pre-receive钩子(在GitLab企业版中叫做Git钩子)
执行你请求的动作
处理GitLab的post-receive动作
处理自定义的post-receive动作

GitLab Workhorse

GitLab Workhorse是一个敏捷的反向代理。它会处理一些大的HTTP请求,比如文件上传、文件下载、Git push/pull和Git包下载。其它请求会反向代理到GitLab Rails应用,即反向代理给后端的unicorn。


GitLab环境部署

企业版7.3
内存2G以上
虚拟机可以使用上网功能


手动部署

虚拟机上网

[root@server1 ~]# vim /etc/sysconfig/network-scripts/ifcfg-eth0 

GATEWAY=172.25.8.250

[root@server1 ~]# vim /etc/resolv.conf 

nameserver 114.114.114.114
[root@foundation8 ~]# iptables -t nat -I POSTROUTING -s 172.25.8.0/24 -j MASQUERADE
[root@server1 ~]# ping baidu.com
PING baidu.com (123.125.115.110) 56(84) bytes of data.
64 bytes from 123.125.115.110 (123.125.115.110): icmp_seq=1 ttl=48 time=99.3 ms
64 bytes from 123.125.115.110 (123.125.115.110): icmp_seq=2 ttl=48 time=52.2 ms
64 bytes from 123.125.115.110 (123.125.115.110): icmp_seq=3 ttl=48 time=45.8 ms

1.配置yum源

vim /etc/yum.repos.d/gitlab-ce.repo

[gitlab-ce]
name=gitlab-ce
baseurl=http://mirrors.tuna.tsinghua.edu.cn/gitlab-ce/yum/el7
Repo_gpgcheck=0
Enabled=1
gpgcheck=0

2、更新本地yum缓存

[root@server1 ~]# yum repolist
[root@server1 ~]# yum makecache
Loaded plugins: product-id, search-disabled-repos, subscription-manager
This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register.
gitlab-ce                                                | 2.9 kB     00:00     
source7.3                                                | 4.1 kB     00:00     
(1/4): source7.3/filelists_db                              | 3.3 MB   00:00     
(2/4): source7.3/other_db                                  | 1.5 MB   00:00     
(3/4): gitlab-ce/other_db                                  |  23 kB   00:00     
(4/4): gitlab-ce/filelists_db                              | 185 MB   00:58     
Metadata Cache Created

3、安装GitLab社区版

[root@server1 ~]# yum install gitlab-ce -y        # 自动安装最新版
[root@server1 ~]# gitlab-ctl start                # 启动所有 gitlab 组件;

GitLab常用命令

gitlab-ctl start                                 # 启动所有 gitlab 组件;
gitlab-ctl stop                                  # 停止所有 gitlab 组件;
gitlab-ctl restart                               # 重启所有 gitlab 组件;
gitlab-ctl status                                # 查看服务状态;
gitlab-ctl reconfigure                           # 启动服务;
vim /etc/gitlab/gitlab.rb                        # 修改默认的配置文件;
gitlab-rake gitlab:check SANITIZE=true --trace   # 检查gitlab;
gitlab-ctl tail                                  # 查看日志;
[root@server1 ~]# vim /etc/gitlab/gitlab.rb 

  13 external_url 'http://172.25.8.1'            # 访问gitlib的地址

[root@server1 ~]# gitlab-ctl reconfigure

这里写图片描述

GitLab使用

登录GitLab
1、在浏览器的地址栏中输入ECS服务器的公网IP即可登录GitLab的界面
在浏览器访问
http://172.25.8.1
这里写图片描述
这里写图片描述
这里写图片描述
这里写图片描述
这里写图片描述

[root@server1 ~]# ssh-keygen
[root@server1 ~]# cat .ssh/id_rsa.pub

这里写图片描述
这里写图片描述
这里写图片描述

[root@server1 ~]# yum install git -y
[root@server1 ~]# git config --global user.name "zmy"
[root@server1 ~]# git config --global user.email "143365432@qq.com"
[root@server1 ~]# git clone git@server1:root/test.git
Cloning into 'test'...
The authenticity of host 'server1 (172.25.8.1)' can't be established.
ECDSA key fingerprint is b2:90:c6:d0:1e:f1:c2:3d:18:fb:84:88:6a:4c:41:fe.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added 'server1,172.25.8.1' (ECDSA) to the list of known hosts.
warning: You appear to have cloned an empty repository.
[root@server1 ~]# cd test/
[root@server1 test]# echo "test" > /root/test.sh
[root@server1 test]# cp /root/test.sh ./
[root@server1 test]# git add test.sh
[root@server1 test]# git commit -m "test.sh"
[master (root-commit) 19a1ccb] test.sh
 1 file changed, 1 insertion(+)
 create mode 100644 test.sh
 [root@server1 test]# git commit -m "test.sh"
[master (root-commit) 19a1ccb] test.sh
 1 file changed, 1 insertion(+)
 create mode 100644 test.sh
[root@server1 test]# git push -u origin master
Counting objects: 3, done.
Writing objects: 100% (3/3), 206 bytes | 0 bytes/s, done.
Total 3 (delta 0), reused 0 (delta 0)
To git@server1:root/test.git
 * [new branch]      master -> master
Branch master set up to track remote branch master from origin.

这里写图片描述
这里写图片描述

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值