站长资讯网
最全最丰富的资讯网站

CentOS 7下版本管理 GitLab 的安装及管理

一、前言

GitLab是利用 Ruby on Rails 一个开源的版本管理系统,实现一个自托管的 Git 项目仓库,可通过 Web 界面进行访问公开的或者私人项目。

它拥有与 Github 类似的功能,能够浏览源代码,管理缺陷和注释。可以管理团队对仓库的访问,它非常易于浏览提交过的版本并提供一个文件历史库。

团队成员可以利用内置的简单聊天程序(Wall)进行交流。

它还提供一个代码片段收集功能可以轻松实现代码复用,便于日后有需要的时候进行查找。

1、Git的家族成员

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

2、Gitlab的服务构成

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

CentOS 7下版本管理 GitLab 的安装及管理

3、GitLab工作流程

CentOS 7下版本管理 GitLab 的安装及管理

4、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进行处理:
1.调用GitLab Rails API
2.检查权限执行pre-receive钩子(在GitLab企业版中叫做Git钩子)
3.执行你请求的动作
4.处理GitLab的post-receive动作
5.处理自定义的post-receive动作

5、GitLab Workhorse

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

二、Gitlab 的安装

1、安装和配置必要的依赖关系

yum install -y curl policycoreutils-python openssh-server openssh-clients

2、添加 Gitlab 仓库

新建/etc/yum.repos.d/gitlab-ce.repo,内容为

[gitlab-ce]
name=Gitlab CE Repository
baseurl=https://mirrors.tuna.tsinghua.edu.cn/gitlab-ce/yum/el$releasever/
gpgcheck=0
enabled=1

3、安装 Gitlab (Omnibus方式)

yum makecache
EXTERNAL_URL=”http://git.linuxidc.com” yum install -y gitlab-ce

注:EXTERNAL_URL 指定访问的域名。
如何安装其他版本,可以通过清华大学源选择对应版本:http://mirrors.tuna.tsinghua.edu.cn/gitlab-ce/yum/el7/ 。

4、配置启动

gitlab-ctl reconfigure

三、Gitlab 管理

1、Gitlab备份

使用 Gitlab 一键安装包安装 Gitlab 非常简单, 同样的备份恢复与迁移也非常简单. 使用一条命令即可创建完整的Gitlab 备份:

gitlab-rake gitlab:backup:create

使用以上命令会在/var/opt/gitlab/backups目录下创建一个名称类似为1481598919_gitlab_backup.tar的压缩包, 这个压缩包就是 Gitlab 整个的完整部分, 其中开头的:1481598919是备份创建的日期,/etc/gitlab/gitlab.rb配置文件须备份,/var/opt/gitlab/nginx/conf nginx配置文件,/etc/postfix/main.cfpostfix 邮件配置备份。

2、Gitlab恢复

Gitlab的从备份恢复也非常简单:

# 停止相关数据连接服务
gitlab-ctl stop unicorn
gitlab-ctl stop sidekiq

# 从1481598919编号备份中恢复
gitlab-rake gitlab:backup:restore BACKUP=1481598919

# 启动Gitlab
sudo gitlab-ctl start

3、Gitlab自动备份

实现每天凌晨2点进行一次自动备份:通过crontab使用备份命令实现

0 2 * * * /opt/gitlab/bin/gitlab-rake gitlab:backup:create

四、Gitlab的使用

Git global setup

git config –global user.name “linuxidc”
git config –global user.email “admin@linuxidc.com”

Create a new repository

git clone http://git.linuxidc.com/ios/app1.git
cd app1
touch README.md
git add README.md
git commit -m “add README”
git push -u origin master

Existing folder

cd existing_folder
git init
git remote add origin http://git.linuxidc.com/ios/app1.git
git commit -m “Initial commit”
git push -u origin master

Existing Git repository

cd existing_repo
git remote add origin http://git.linuxidc.com/ios/app1.git
git push -u origin –all
git push -u origin –tags

五、Gitlab 的升级

因为我们使用 Omnibus GitLab package 进行安装,所以我们的升级相对比较简单,也建议大家使用这种方式安装,我目前的版本是10.0.4要升级到11.2.3,这算是大版本升级,根据官方文档的要求,我们需要先升级到10.x的最高版本。

CentOS 7下版本管理 GitLab 的安装及管理

1、升级过渡版本 10.8.7

升级过程中会对数据进行自动备份,不用担心数据安全。

# 下载对应版本的 rpm 包
wget https://mirrors.tuna.tsinghua.edu.cn/gitlab-ce/yum/el7/gitlab-ce-10.8.7-ce.0.el7.x86_64.rpm

# 安装此过渡版本
rpm -Uvh gitlab-ce-10.8.7-ce.0.el7.x86_64.rpm

CentOS 7下版本管理 GitLab 的安装及管理

2、升级最新版本 11.2.3

# 下载最新版本的 rpm 包
wget https://mirrors.tuna.tsinghua.edu.cn/gitlab-ce/yum/el7/gitlab-ce-11.2.3-ce.0.el7.x86_64.rpm

# 安装最新版本
rpm -Uvh gitlab-ce-11.2.3-ce.0.el7.x86_64.rpm

#升级过程
warning: gitlab-ce-11.2.3-ce.0.el7.x86_64.rpm: Header V4 RSA/SHA1 Signature, key ID f27eab47: NOKEY
Preparing…                          ################################# [100%]
gitlab preinstall: Automatically backing up only the GitLab SQL database (excluding everything else!)
Dumping database …
Dumping PostgreSQL database gitlabhq_production … [DONE]
done
Dumping repositories …
[SKIPPED]
Dumping uploads …
[SKIPPED]
Dumping builds …
[SKIPPED]
Dumping artifacts …
[SKIPPED]
Dumping pages …
[SKIPPED]
Dumping lfs objects …
[SKIPPED]
Dumping container registry images …
[DISABLED]
Creating backup archive: 1535946629_2018_09_03_10.8.7_gitlab_backup.tar … done
Uploading backup archive to remote storage  … skipped
Deleting tmp directories … done
done
Deleting old backups … skipping
Updating / installing…
  1:gitlab-ce-11.2.3-ce.0.el7        #############################    ( 87%)
……
……

    _______ __  __          __
    / ____(_) /_/ /  ____ _/ /_
  / / __/ / __/ /  / __ `/ __
  / /_/ / / /_/ /___/ /_/ / /_/ /
  ____/_/__/_____/__,_/_.___/

Upgrade complete! If your GitLab server is misbehaving try running
  sudo gitlab-ctl restart
before anything else.
If you need to roll back to the previous version you can use the database
backup made during the upgrade (scroll up for the filename).

3、升级成功

CentOS 7下版本管理 GitLab 的安装及管理

更多GitLab相关教程见以下内容

CentOS7安装GitLab、汉化及使用  http://www.info110.com/Linux/2017-11/148223.htm
CentOS 7安装部署GitLab服务器  http://www.info110.com/Linux/2017-06/144990.htm
CentOS 7.x上GitLab搭建详细教程  http://www.info110.com/Linux/2017-12/149766.htm
CentOS 7安装部署GitLab服务器  http://www.info110.com/Linux/2017-06/144990.htm
CentOS 7使用Docker搭建GitLab服务器  http://www.info110.com/Linux/2018-04/151725.htm
Ubuntu 16.04搭建GitLab服务器 http://www.info110.com/Linux/2018-01/150319.htm

快速学会CentOS配置GitLab  http://www.info110.com/Linux/2018-08/153345.htm

赞(0)
分享到: 更多 (0)