版本控制gitlab

版本控制gitlab

目录

  1. 版本控制介绍
  2. giitlab部署
  3. gitlab管理

1. 版本控制介绍

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

版本控制最主要的功能就是追踪文件的变更。它将什么时候、什么人更改了文件的什么内容等信息忠实地了记录下来。每一次文件的改变,文件的版本号都将增加。除了记录版本变更外,版本控制的另一个重要功能是并行开发。软件开发往往是多人协同作业,版本控制可以有效地解决版本的同步以及不同开发者之间的开发通信问题,提高协同开发的效率。并行开发中最常见的不同版本软件的错误(Bug)修正问题也可以通过版本控制中分支与合并的方法有效地解决。
具体来说,在每一项开发任务中,都需要首先设定开发基线,确定各个配置项的开发初始版本,在开发过程中,开发人员基于开发基线的版本,开发出所需的目标版本。当发生需求变更时,通过对变更的评估,确定变更的影响范围,对被影响的配置项的版本进行修改,根据变更的性质使配置项的版本树继续延伸或产生新的分支,形成新的目标版本,而对于不受变更影响的配置项则不应发产生变动。同时,应能够将变更所产生的对版本的影响进行记录和跟踪。必要时还可以回退到以前的版本。例如当开发需求或需求变更被取消时,就需要有能力将版本回退到开发基线版本。在曾经出现过的季度升级包拆包和重新组包的过程中,其实就是将部分配置项的版本回退到开发基线,将对应不同需求的不同分支重新组合归并,形成新的升级包版本。
版本控制是软件配置管理的核心功能。所有置于配置库中的元素都应自动予以版本的标识,并保证版本命名的唯一性。版本在生成过程中,自动依照设定的使用模型自动分支、演进。除了系统自动记录的版本信息以外,为了配合软件开发流程的各个阶段。还需要定义、收集一些元数据来记录版本的辅助信息和规范开发流程,并为今后对软件过程的度量做好准备。当然如果选用的工具支持,这些辅助数据将能直接统计出过程数据,从而方便软件过程改进活动的进行。对于配置库中的各个基线控制项,应该根据其基线的位置和状态来设置相应的访问权限。一般来说,对于基线版本之前的各个版本都应处于被锁定的状态,如需要对它们进行变更,则应按照变更控制的流程来进行操作。

常用的版本控制工具:

  • gitlab
  • subversion

2. gitlab部署

主机ip系统
localhost.example.com192.168.10.130CentOS8

由于gitlab服务要用到缓存,所以要给运行gitlab服务的主机足够的内存一般是10G左右

部署gitlab服务的主机只能单独运行gitlab服务

[root@localhost ~]# ss -antl
State        Recv-Q        Send-Q               Local Address:Port               Peer Address:Port       Process       
LISTEN       0             128                        0.0.0.0:22                      0.0.0.0:*                        
LISTEN       0             128                           [::]:22                         [::]:*                        

关闭防火墙和selinux

[root@localhost ~]# systemctl disable --now firewalld
Removed /etc/systemd/system/multi-user.target.wants/firewalld.service.
Removed /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service.
[root@localhost ~]# setenforce 0
[root@localhost ~]# vi /etc/selinux/config 
SELINUX=disabled
[root@localhost ~]# reboot

配置yum源

# 这里我们配置阿里云的yum仓库地址
[root@localhost ~]# wget -O /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-vault-8.5.2111.repo
[root@localhost ~]# yum clean all
[root@localhost ~]# yum makecache
[root@localhost ~]# sed -i -e '/mirrors.cloud.aliyuncs.com/d' -e '/mirrors.aliyuncs.com/d' /etc/yum.repos.d/CentOS-Base.repo
 
# 下载epel源
[root@localhost ~]# yum install -y https://mirrors.aliyun.com/epel/epel-release-latest-8.noarch.rpm
[root@localhost ~]# sed -i 's|^#baseurl=https://download.example/pub|baseurl=https://mirrors.aliyun.com|' /etc/yum.repos.d/epel*
[root@localhost ~]# sed -i 's|^metalink|#metalink|' /etc/yum.repos.d/epel*
[root@localhost ~]# yum clean all
[root@localhost ~]# yum makecache

安装git工具

[root@localhost ~]# yum -y install epel-release git

安装依赖包

yum -y install curl openssh-server openssh-clients postfix cronie perl

启动postfix服务并设置开机自启

[root@localhost ~]# systemctl enable --now postfix
Created symlink /etc/systemd/system/multi-user.target.wants/postfix.service → /usr/lib/systemd/system/postfix.service.
[root@localhost ~]# 

下载policycoreutils-python依赖包

wget http://mirror.centos.org/centos/7/os/x86_64/Packages/policycoreutils-python-2.5-34.el7.x86_64.rpm

解压

[root@localhost opt]# rpm -ivh --force --nodeps policycoreutils-python-2.5-34.el7.x86_64.rpm 
# --nodeps 选项 过滤依赖,只装它本身
# --force 选项 强制安装,因为policycoreutils在安装postfix的时候已经安装了,如果不加这个参数安装不了
warning: policycoreutils-python-2.5-34.el7.x86_64.rpm: Header V3 RSA/SHA256 Signature, key ID f4a80eb5: NOKEY
Verifying...                          ################################# [100%]
Preparing...                          ################################# [100%]
Updating / installing...
   1:policycoreutils-python-2.5-34.el7################################# [100%]
[root@localhost opt]# 

安装清华大学gitlab软件包

[root@localhost opt]# wget https://mirrors.tuna.tsinghua.edu.cn/gitlab-ce/yum/el7/gitlab-ce-16.4.1-ce.0.el7.x86_64.rpm

解压

[root@localhost opt]# rpm -ivh gitlab-ce-16.4.1-ce.0.el7.x86_64.rpm

出现这个狐狸头则是成功了

[root@localhost opt]# rpm -ivh gitlab-ce-16.4.1-ce.0.el7.x86_64.rpm
warning: gitlab-ce-16.4.1-ce.0.el7.x86_64.rpm: Header V4 RSA/SHA1 Signature, key ID f27eab47: NOKEY
Verifying...                          ################################# [100%]
Preparing...                          ################################# [100%]
Updating / installing...
   1:gitlab-ce-16.4.1-ce.0.el7        ################################# [100%]
It looks like GitLab has not been configured yet; skipping the upgrade script.

       *.                  *.
      ***                 ***
     *****               *****
    .******             *******
    ********            ********
   ,,,,,,,,,***********,,,,,,,,,
  ,,,,,,,,,,,*********,,,,,,,,,,,
  .,,,,,,,,,,,*******,,,,,,,,,,,,
      ,,,,,,,,,*****,,,,,,,,,.
         ,,,,,,,****,,,,,,
            .,,,***,,,,
                ,*,.
  


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

Thank you for installing GitLab!

配置gitlab配置文件

修改配置文件

[root@localhost ~]# vim /etc/gitlab/gitlab.rb
......
#通过/external_url查找到下面这一行,httpd://后面加这台主机的ip地址
external_url 'http://192.169.10.130'
通过8080找到一下这两行
/8080
# puma['port'] = 8080    #去掉注释

# gitlab_workhorse['auth_backend'] = "http://localhost:8080"  #去掉注释

编辑完配置文件后需要重载配置文件并重启gitlab

[root@localhost ~]# gitlab-ctl reconfigure
[root@localhost ~]# gitlab-ctl restart

使用ip访问gitlab界面

用户名root,密码在/etc/gitlab/initial_root_password文件里面

[root@localhost ~]# cat /etc/gitlab/initial_root_password
# WARNING: This value is valid only in the following conditions
#          1. If provided manually (either via `GITLAB_ROOT_PASSWORD` environment variable or via `gitlab_rails['initial_root_password']` setting in `gitlab.rb`, it was provided before database was seeded for the first time (usually, the first reconfigure run).
#          2. Password hasn't been changed manually, either via UI or via command line.
#
#          If the password shown here doesn't work, you must reset the admin password following https://docs.gitlab.com/ee/security/reset_user_password.html#reset-your-root-password.

Password: TgH0QvS3wUKxUUjfDiVr4B5ART2At2UnsutyJL9wP9g=  #这里是密码

# NOTE: This file will be automatically deleted in the first reconfigure run after 24 hours.
                                    #这里提示此文件将在第一次重新配置运行24小时后自动删除,所以登录后记得修改密码

在这里插入图片描述

登录后的界面

在这里插入图片描述

修改密码

在这里插入图片描述

在这里插入图片描述

在这里插入图片描述

在这里插入图片描述

保存后会自动退出到登录界面,输入新的密码登录

在这里插入图片描述

登录成功

在这里插入图片描述

当你忘记密码或者登录后忘记设置密码,那么可以破解密码

[root@localhost ~]# gitlab-rails console -e production    #破解密码
--------------------------------------------------------------------------------
 Ruby:         ruby 3.0.6p216 (2023-03-30 revision 23a532679b) [x86_64-linux]
 GitLab:       16.4.1 (e6801ed8d44) FOSS
 GitLab Shell: 14.28.0
 PostgreSQL:   13.11
------------------------------------------------------------[ booted in 23.55s ]
Loading production environment (Rails 7.0.6)
irb(main):001:0> user = User.where(id: 1).first   #设置user变量,变量等于id为1的用户,也就是root用户
=> #<User id:1 @root>
irb(main):002:0> user.password = "Hte666666"      #设置user的密码
=> "Hte666666"
irb(main):003:0> user.password_confirmation = "Hte666666"  #确认密码
=> "Hte666666"
irb(main):004:0> user.save!    #保存修改,若无问题则提示true
=> true   #没有问题
irb(main):005:0> exit          #退出
[root@localhost ~]# 

返回到网页,刷新后重新输入密码

在这里插入图片描述

登录成功

在这里插入图片描述

3.gitlab管理

gitlab常用管理操作

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

创建项目

新建项目

在这里插入图片描述

在这里插入图片描述

在这里插入图片描述

保存完后可以看到这个界面

在这里插入图片描述

全局设置

要知道的是,设置之类的东西一般交由开发人员操作,运维人员只负责创建项目但还是要了解

设置用户和邮箱

[root@localhost ~]# git config --global user.name "root"
[root@localhost ~]# git config --global user.email "xxx@xxx.com"   #一般情况下用不上邮件服务,所以这里是随便设置的

创建一个存储库

[root@localhost ~]# git clone http://192.168.10.130/root/hhh.git
Cloning into 'hhh'...
Username for 'http://192.168.10.130': root   #输入用户
Password for 'http://root@192.168.10.130':    #密码
remote: Enumerating objects: 3, done.
remote: Counting objects: 100% (3/3), done.
remote: Compressing objects: 100% (2/2), done.
remote: Total 3 (delta 0), reused 0 (delta 0), pack-reused 0
Unpacking objects: 100% (3/3), 2.78 KiB | 1.39 MiB/s, done.
[root@localhost ~]# ls
anaconda-ks.cfg  hhh     #出现了一个空目录
[root@localhost ~]# 

创建分支

[root@localhost hhh]# git switch --create maincd    #创建主分支
Switched to a new branch 'main'

创建文件并提交

[root@localhost hhh]# touch lanbo        #创建文件
[root@localhost hhh]# git add lanbo      #添加lanbo文件
[root@localhost hhh]# git commit -m "add lanbo"   #提交,添加描述信息
[main 0cb8d71] add lanbo
 1 file changed, 0 insertions(+), 0 deletions(-)
 create mode 100644 lanbo

上传

[root@localhost hhh]# git push --set-upstream origin main
Username for 'http://192.168.10.130': root
Password for 'http://root@192.168.10.130': 
Enumerating objects: 4, done.
Counting objects: 100% (4/4), done.
Delta compression using up to 8 threads
Compressing objects: 100% (2/2), done.
Writing objects: 100% (3/3), 257 bytes | 257.00 KiB/s, done.
Total 3 (delta 0), reused 0 (delta 0), pack-reused 0
To http://192.168.10.130/root/hhh.git
   6c6a908..0cb8d71  main -> main
Branch 'main' set up to track remote branch 'main' from 'origin'.   #上传成功
[root@localhost hhh]# 

可以在项目上看到刚上传的lanbo

在这里插入图片描述

创建组与用户

在这里插入图片描述

在这里插入图片描述

在这里插入图片描述

在组的主界面就可以看到新建的组了

在这里插入图片描述

创建用户,并将它添加进huayu组

在这里插入图片描述

在这里插入图片描述

在这里插入图片描述

然后就可以看到这个用户的基本信息

在这里插入图片描述

右上角点击修改,在里面设置密码

在这里插入图片描述

密码要具有复杂性,所以我设置为ABCD123456!

在这里插入图片描述

将该用户加入到组

在这里插入图片描述

在这里插入图片描述

在这里插入图片描述

邀请组加入项目

在这里插入图片描述

在这里插入图片描述

在这里插入图片描述

在这里插入图片描述

设置完成后登出

在这里插入图片描述

登录huang用户查看项目

在这里插入图片描述

登录后提示更改密码
在这里插入图片描述

然后重新登录即可

在这里插入图片描述

在这里可以看到这个用户所加入的项目

在这里插入图片描述

向项目添加文件

在这里插入图片描述

设置完成后登出

在这里插入图片描述

登录huang用户查看项目

[外链图片转存中…(img-cE2lcbC9-1696907548046)]

登录成功,但是需要改密码[外链图片转存中…(img-cUw3r57g-1696907548046)]

然后重新登录即可

[外链图片转存中…(img-QLXTYnJT-1696907548046)]

在这里可以看到这个用户所加入的项目

[外链图片转存中…(img-JHFP4yP0-1696907548047)]

向项目添加文件

在这里插入图片描述

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值