阿里云-云小站(无限量代金券发放中)
【腾讯云】云服务器、云数据库、COS、CDN、短信等热卖云产品特惠抢购

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

160次阅读
没有评论

共计 5162 个字符,预计需要花费 13 分钟才能阅读完成。

一、前言

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

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

GitLab 的详细介绍:请点这里
GitLab 的下载地址:请点这里 

正文完
星哥说事-微信公众号
post-qrcode
 
星锅
版权声明:本站原创文章,由 星锅 2022-01-21发表,共计5162字。
转载说明:除特殊说明外本站文章皆由CC-4.0协议发布,转载请注明出处。
【腾讯云】推广者专属福利,新客户无门槛领取总价值高达2860元代金券,每种代金券限量500张,先到先得。
阿里云-最新活动爆款每日限量供应
评论(没有评论)
验证码
【腾讯云】云服务器、云数据库、COS、CDN、短信等云产品特惠热卖中