gitlab

版本控制介绍

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

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

每一次文件的改变,文件的版本号都将增加。除了记录版本变更外,版本控制的另一个重要功能是并行开发。
软件开发往往是多人协同作业,版本控制可以有效地解决版本的同步以及不同开发者之间的开发通信问题,提高协同开发的效率。
并行开发中最常见的不同版本软件的错误(Bug)修正问题也可以通过版本控制中分支与合并的方法有效地解决

具体来说,在每一项开发任务中,都需要首先设定开发基线,确定各个配置项的开发初始版本,在开发过程中,开发人员基于开发基线的版本,
开发出所需的目标版本。当发生需求变更时,通过对变更的评估,确定变更的影响范围,对被影响的配置项的版本进行修改,
根据变更的性质使配置项的版本树继续延伸或产生新的分支,形成新的目标版本,而对于不受变更影响的配置项则不应发产生变动。
同时,应能够将变更所产生的对版本的影响进行记录和跟踪。必要时还可以回退到以前的版本。例如当开发需求或需求变更被取消时,
就需要有能力将版本回退到开发基线版本。在曾经出现过的季度升级包拆包和重新组包的过程中,其实就是将部分配置项的版本回退到开发基线,
将对应不同需求的不同分支重新组合归并,形成新的升级包版本。
 

版本控制是软件配置管理的核心功能。所有置于配置库中的元素都应自动予以版本的标识,并保证版本命名的唯一性。版本在生成过程中,
自动依照设定的使用模型自动分支、演进。除了系统自动记录的版本信息以外,为了配合软件开发流程的各个阶段。
还需要定义、收集一些元数据来记录版本的辅助信息和规范开发流程,并为今后对软件过程的度量做好准备。
当然如果选用的工具支持,这些辅助数据将能直接统计出过程数据,从而方便软件过程改进活动的进行。
对于配置库中的各个基线控制项,应该根据其基线的位置和状态来设置相应的访问权限。一般来说,对于基线版本之前的各个版本都应处于被锁定的状态,
如需要对它们进行变更,则应按照变更控制的流程来进行操作。

常用的版本控制工具:
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、测试(测试人员)---如果出问题就回滚(运维人员)

hublab命令及其含义

 命令                              含义
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@rhel8 ~]# systemctl restart postfix
[root@rhel8 ~]# systemctl enable postfix

//下载gitlab的rpm包
[root@localhost ~]# cd /usr/src/
[root@localhost src]# ls
debug  kernels
[root@rhel8 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
密码为刚刚设置的密码

汉化 

 

关闭注册功能
由于我们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 
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABgQC8m6+q0sz5PmWFIHVTQenW7KZvwhHYbKP3IbowRidlYSuAOMmF4oQXeXYpymmSQkKq9YBJSBAwn89+LQ5GHAcHx8eFyyP5/zGZO1XZ9PAIAStUWk4q00zbvRF/2ce+mY08eGwhiX/3dm2fmP0bgqn7o5zuI6Pe9yRySAs5mk6GERVqZdkfyI9zEEOlS5C3mDfFyBllUpOO02KKR0qaP52P4BsqoYYhclPMQLpPVgCOFlGI4TB4kw6tqfXlzLsrOoR3MYOSD0PHJLcej8mv9BBermKdFYr9JIorIpRD63SCB4+ycEVvUfhzvBgT3AyVccbo3AVbXgkXLGYupOV3rZuJlFXodDahTCGUR5SwWhr31q4CoUQlARbhR8HIFeCwPwfbO6O5RtshreHj8tXvePq9er0h2FR/kJDjAUT7SDVLXybwX9PZpvqoL8iOpf3BHmIXS5aL7wGCLQgVTeTlvtU9WlXEXaMbU/ZyU/e79JIBRLIALQlt9890PQtHo6+VoLE= root@node1.example.com

将密钥添加进去

添加完成

 

测试验证
 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的包

yum -y install git

 

 

[root@node1 ~]# 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), 360.17 KiB | 25.73 MiB/s, done.
[root@node1 ~]# cd linux/
[root@node1 linux]# ls
mao.jpg  README.md

 

测试验证   
touch file1  
git add file1
git commit -m "add file"
git push                    //默认是上传到main分支中

 

[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端,已经上传上来了

 

 touch file2
git add .                           // . 代表所有文件
git commit -m "add file"
git push

 

[root@node1 linux]# touch file123
[root@node1 linux]# git add .                        // .代表所有文件
[root@node1 linux]# git commit -m "add file123"
[main 6fb0b9c] add file123
 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 file123
[root@node1 linux]# git push
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), 227 bytes | 227.00 KiB/s, done.
Total 2 (delta 1), reused 0 (delta 0), pack-reused 0
To http://192.168.100.10/it/linux.git
   88626f8..6fb0b9c  main -> main

查看web端,此时上传上来的只有file123这个文件,已经上传上来的就不会再次上传到仓库

 

创建分支 

git branch cc               //创建分支
git push origin cc      //将分支提交到线上
git checkout cc         //切换到分支cc
touch file5          
git add file5          
git commit -m "add file5"
git push origin cc     //同步分支内容到cc

[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

 查看web端

此时分支创建完成

 

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值