GitLab

一、版本控制介绍

版本控制是指对软件开发过程中各种程序代码、配置文件及说明文档等文件变更的管理,是软件配置管理的核心思想之一。

版本控制最主要的功能就是追踪文件的变更。它将什么时候、什么人更改了文件的什么内容等信息如实地了记录下来。

每一次文件的改变,文件的版本号都将增加。除了记录版本变更外,版本控制的另一个重要功能是并行开发

软件开发往往是多人协同作业,版本控制可以有效地解决版本的同步以及不同开发者之间的开发通信问题,提高协同开发的效率。

并行开发中最常见的不同版本软件的错误(Bug)修正问题也可以通过版本控制中分支与合并的方法有效地解决。

具体来说,在每一项开发任务中,都需要首先设定开发基线,确定各个配置项的开发初始版本,在开发过程中,开发人员基于开发基线的版本,开发出所需的目标版本。

当发生需求变更时,通过对变更的评估,确定变更的影响范围,对被影响的配置项的版本进行修改,根据变更的性质使配置项的版本树继续延伸或产生新的分支,形成新的目标版本,而对于不受变更影响的配置项则不应发产生变动。

同时,应能够将变更所产生的对版本的影响进行记录和跟踪。必要时还可以回退到以前的版本。例如当开发需求或需求变更被取消时,就需要有能力将版本回退到开发基线版本。

在曾经出现过的季度升级包拆包和重新组包的过程中,其实就是将部分配置项的版本回退到开发基线,将对应不同需求的不同分支重新组合归并,形成新的升级包版本。

版本控制是软件配置管理的核心功能。所有置于配置库中的元素都应自动予以版本的标识,并保证版本命名的唯一性

版本在生成过程中,自动依照设定的使用模型自动分支、演进。除了系统自动记录的版本信息以外,为了配合软件开发流程的各个阶段。

还需要定义、收集一些元数据来记录版本的辅助信息和规范开发流程,并为今后对软件过程的度量做好准备。

当然如果选用的工具支持,这些辅助数据将能直接统计出过程数据,从而方便软件过程改进活动的进行。

对于配置库中的各个基线控制项,应该根据其基线的位置和状态来设置相应的访问权限。一般来说,对于基线版本之前的各个版本都应处于被锁定的状态,如需要对它们进行变更,则应按照变更控制的流程来进行操作。

GitLab的特点包括但不限于:
  1. 开源:GitLab 是开源的,这意味着你可以自由地使用、修改和分发它。

  2. Git 仓库管理:提供完整的 Git 仓库管理功能,包括分支管理、标签、提交历史等。

  3. 代码审查:通过合并请求(Merge Requests)进行代码审查,支持代码的并行开发和质量控制。

  4. 问题跟踪:内置的问题跟踪系统,方便团队成员报告、讨论和解决项目中的问题。

  5. 持续集成/持续部署(CI/CD):集成了 CI/CD 工具,支持自动化测试、构建和部署流程。

  6. 访问控制:提供细粒度的访问控制,可以设置不同的用户角色和权限。

  7. 多环境支持:支持多个环境(如开发、测试、生产)的配置和管理。

  8. 安全性:提供多种安全功能,包括双因素认证、LDAP/AD 集成、审计日志等。

  9. 自托管和云服务:既可以在本地服务器上自托管,也可以使用 GitLab.com 提供的云服务。

  10. 集成:可以与许多其他工具和服务集成,如 Slack、Jira、Confluence 等。

  11. API:提供丰富的 API,方便自动化和集成。

  12. 可扩展性:可以通过安装额外的插件和集成来扩展 GitLab 的功能。

常用的版本控制工具:

github

gitlab

subversion

官网:https://about.gitlab.com/

国内镜像:https://mirrors.tuna.tsinghua.edu.cn/gitlab-ce/yum/

开始上线:

1、开发代码(开发人员)

2、测试(测试人员)

3、发布(运维人员)

4、测试(测试人员)

5、发邮件申请发布(开发人员)

邮件发给开发的领导、抄送给运维团队

6、填写变更单,为了避免背锅

7、开发领导审批

8、评估影响范围(运维人员)

9、向运维领导汇报(运维人员)

10、与开发领导协商(运维领导)

11、发布(运维人员)----生产环境

12、测试(测试人员)---如果出问题就回滚(运维人员)

GitLab中各种命令的含义:

命令                                含义

gitlab-ctl start                  启动全部服务

gitlab-ctl restart               重启全部服务

gitlab-ctl stop                  停止全部服务

gitlab-ctl restart nginx     重启单个服务,如重启nginx

gitlab-ctl status               查看服务状态

gitlab-ctl reconfigure       使配置文件生效

gitlab-ctl show-config      验证配置文件

gitlab-ctl uninstall            删除gitlab(保留数据)

gitlab-ctl cleanse             删除所有数据,从新开始

gitlab-ctl tail                     查看服务的日志

gitlab-ctl tail nginx           如查看gitlab下nginx日志

gitlab-rails console          进入控制台

二、GitLab部署

注意!!!在部署之前要确保环境为纯洁环境,内存尽量给多一些

需要满足 cpu:2核 内存:8g (最低配置)

安装需要用的包文件:
[root@node1 ~]# yum -y install tar chrony lrzsz wget net-tools
# 安装需要的依赖包
[root@node1 ~]#  yum -y install curl openssh-server openssh-clients postfix cronie  perl
开始部署:
# 启动postfix服务并设置开机自启
[root@node1 ~]# systemctl restart postfix
[root@node1 ~]# systemctl enable postfix
 
# 下载gitlab的rpm包
[root@node1 ~]# cd /usr/src/
[root@node1 src]# ls
debug  kernels
[root@node1 src]# wget https://mirrors.tuna.tsinghua.edu.cn/gitlab-ce/yum/el7/gitlab-ce-15.3.3-ce.0.el7.x86_64.rpm
 
# 安装
[root@node1 src]# rpm -ivh gitlab-ce-16.0.0-ce.0.el9.x86_64.rpm 
warning: gitlab-ce-16.0.0-ce.0.el9.x86_64.rpm: Header V4 RSA/SHA256 Signature, key ID f27eab47: NOKEY
error: Failed dependencies:
	policycoreutils-python-utils is needed by gitlab-ce-16.0.0-ce.0.el9.x86_64
 
# 此时报错了,需要安装一个依赖包
 
[root@node1 src]# yum -y install policycoreutils-python-utils
 
# 安装这个依赖包后继续进行安装
 
[root@node1 src]# rpm -ivh gitlab-ce-16.0.0-ce.0.el9.x86_64.rpm 
warning: gitlab-ce-16.0.0-ce.0.el9.x86_64.rpm: Header V4 RSA/SHA256 Signature, key ID f27eab47: NOKEY
Verifying...                          ################################# [100%]
Preparing...                          ################################# [100%]
Updating / installing...
   1:gitlab-ce-16.0.0-ce.0.el9        ################################# [100%]
It looks like GitLab has not been configured yet; skipping the upgrade script.
 
# 修改配置文件
[root@node1 ~]# vim /etc/gitlab/gitlab.rb
......  # 此处为省略内容
external_url 'http://192.168.100.10'     # 将此处设为gitlab的服务器ip地址亦或域名
......  # 此处为省略内容
 
# 重载配置文件并重启gitlab
[root@node1 ~]# gitlab-ctl reconfigure
# 重启服务
[root@node1 ~]# gitlab-ctl restart
 
 
# 查看当前gitlab版本
[root@node1 src]# head -1 /opt/gitlab/version-manifest.txt 
gitlab-ce 16.0.0
 
 
# 破解管理员密码
[root@node1 src]# gitlab-rails console -e production
--------------------------------------------------------------------------------
 Ruby:         ruby 3.0.6p216 (2023-03-30 revision 23a532679b) [x86_64-linux]
 GitLab:       16.0.0 (917d3f7ad12) FOSS
 GitLab Shell: 14.20.0
 PostgreSQL:   13.8
------------------------------------------------------------[ booted in 26.08s ]
Loading production environment (Rails 6.1.7.2)
irb(main):001:0>  user = User.where(id:1).first            # id为1的是超级管理员
=> #<User id:1 @root>
irb(main):002:0> user.password = 'redhat123!'                # 密码必须至少八个字符
=> "redhat123!"
irb(main):003:0> user.password_confirmation = 'redhat123!'
=> "redhat123!"
irb(main):004:0> user.save!                    # 保存修改,若无疑问讲返回true
=> true
irb(main):005:0> exit                            # 退出
[root@node1 src]#

三、gitlab管理

登录:

在浏览器中使用gitlab服务器的ip访问,192.168.100.10

用户名为root   默认管理员为root,密码为刚刚设置的密码(我的是 redhat123! )

汉化:

关闭注册功能:

由于我们gitlab是私有仓库,一般用户都是由管理员创建和分派的,所以我们需要关闭注册
管理员--设置--通用--注册限制--把已启用注册功能的勾去掉--保存更改

gitlab常用管理操作:

项目管理(通常只是创建新项目)
创建成员组(针对某个项目创建一个成员组)
用户管理(此用户乃gitlab用户而非系统用户)
例:来了新员工,为其添加gitlab用户
员工离职,将其gitlab用户禁用或者删除

四、添加ssh密钥

添加SSH密钥之前,不能通过SSH来拉取或推送仓库

查看自己的密钥:
[root@node1 src]# 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:
SHA256:Bt1Nhk55XCH64r2mVGuJtLIaMcibezNmLYsA+Tzbu70 root@node1.example.com
The key's randomart image is:
+---[RSA 3072]----+
|           ++.o. |
|       . .+=o.   |
|      . .oo..    |
| . . . .  ..     |
|o   o o S o o    |
| +   o + o * o   |
|  = o ... = =    |
|   = +B..+ ...   |
|  . **EB. .o.    |
+----[SHA256]-----+
[root@node1 src]# cd
[root@node1 ~]# cd .ssh/    # 这是个隐藏文件
[root@node1 .ssh]# cat id_rsa.pub     # 查看密钥
# 此时会显示出自己主机的密钥,我们复制一下一会要用
将密钥添加进去:

添加完成:
测试验证:

1、创建项目
2、在Linux中使用git clone http://192.168.100.10/it/linux.git克隆到本地
3、切换到项目中  cd   linux/
4、配置邮件账户和账户
git config --global user.email "root@example.com"
git config --global user.name "root"

需要安装一个git的包:

[root@node1 ~]# yum -y install git

[root@node1 ~]# cd linux/
[root@node1 linux]# ls
README.md
[root@node1 linux]# git clone http://192.168.100.10/it/linux.git
Cloning into 'linux'...
Username for 'http://192.168.100.10': root
Password for 'http://root@192.168.100.10': 
remote: Enumerating objects: 6, done.
remote: Counting objects: 100% (6/6), done.
remote: Compressing objects: 100% (5/5), done.
remote: Total 6 (delta 0), reused 0 (delta 0), pack-reused 0
Receiving objects: 100% (6/6), 18.07 KiB | 3.61 MiB/s, done.
[root@node1 linux]# ls
linux  README.md
[root@node1 linux]# cd linux/
[root@node1 linux]# ls
Linux.png  README.md
[root@node1 linux]# 
 测试验证:
[root@node1 linux]# touch file1
[root@node1 linux]# git add file1                # 添加file1文件,但是没有上传    
[root@node1 linux]# git commit -m "add file1"    # 提交一下,-m后是添加标签
[main 88626f8] add file1
 Committer: root <root@node1.example.com>
Your name and email address were configured automatically based
on your username and hostname. Please check that they are accurate.
You can suppress this message by setting them explicitly. Run the
following command and follow the instructions in your editor to edit
your configuration file:
 
    git config --global --edit
 
After doing this, you may fix the identity used for this commit with:
 
    git commit --amend --reset-author
 
 1 file changed, 0 insertions(+), 0 deletions(-)
 create mode 100644 file1
[root@node1 linux]# git push                        # 上传
Username for 'http://192.168.100.10': root
Password for 'http://root@192.168.100.10': 
Enumerating objects: 4, done.
Counting objects: 100% (4/4), done.
Compressing objects: 100% (2/2), done.
Writing objects: 100% (3/3), 297 bytes | 297.00 KiB/s, done.
Total 3 (delta 0), reused 0 (delta 0), pack-reused 0
To http://192.168.100.10/it/linux.git
   1ae337b..88626f8  main -> main
[root@node1 linux]#

此时查看web端,已经上传上来了

再以上为例上传一个file123文件,此时会发现已上传的文件不会再次上传到仓库

五、创建分支

创建分支:
[root@node1 linux]# git branch cc                 # 创建分支
[root@node1 linux]# git push origin cc            # 将分支提交到线上
Username for 'http://192.168.100.10': root       
Password for 'http://root@192.168.100.10': 
Total 0 (delta 0), reused 0 (delta 0), pack-reused 0
remote: 
remote: To create a merge request for cc, visit:
remote:   http://192.168.100.10/it/linux/-/merge_requests/new?merge_request%5Bsource_branch%5D=cc
remote: 
To http://192.168.100.10/it/linux.git
 * [new branch]      cc -> cc
[root@node1 linux]# git checkout cc                # 切换到cc分支
Switched to branch 'cc'
[root@node1 linux]# touch file666
[root@node1 linux]# git add file666 
[root@node1 linux]# git commit -m "add file666"
[cc 1dc37b3] add file666
 Committer: root <root@node1.example.com>
Your name and email address were configured automatically based
on your username and hostname. Please check that they are accurate.
You can suppress this message by setting them explicitly. Run the
following command and follow the instructions in your editor to edit
your configuration file:
 
    git config --global --edit
 
After doing this, you may fix the identity used for this commit with:
 
    git commit --amend --reset-author
 
 1 file changed, 0 insertions(+), 0 deletions(-)
 create mode 100644 file666
[root@node1 linux]# git push origin cc             # 同步到内容到cc
Username for 'http://192.168.100.10': root
Password for 'http://root@192.168.100.10': 
Enumerating objects: 3, done.
Counting objects: 100% (3/3), done.
Compressing objects: 100% (2/2), done.
Writing objects: 100% (2/2), 231 bytes | 231.00 KiB/s, done.
Total 2 (delta 1), reused 0 (delta 0), pack-reused 0
remote: 
remote: To create a merge request for cc, visit:
remote:   http://192.168.100.10/it/linux/-/merge_requests/new?merge_request%5Bsource_branch%5D=cc
remote: 
To http://192.168.100.10/it/linux.git
   6fb0b9c..1dc37b3  cc -> cc
[root@node1 linux]# 
查看web端:

分支创建完成 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值