版本控制gitlab
1. 版本控制介绍
版本控制是指对软件开发过程中各种程序代码、配置文件及说明文档等文件变更的管理,是软件配置管理的核心思想之一。
版本控制最主要的功能就是追踪文件的变更。它将什么时候、什么人更改了文件的什么内容等信息忠实地了记录下来。每一次文件的改变,文件的版本号都将增加。除了记录版本变更外,版本控制的另一个重要功能是并行开发。软件开发往往是多人协同作业,版本控制可以有效地解决版本的同步以及不同开发者之间的开发通信问题,提高协同开发的效率。并行开发中最常见的不同版本软件的错误(Bug)修正问题也可以通过版本控制中分支与合并的方法有效地解决。
具体来说,在每一项开发任务中,都需要首先设定开发基线,确定各个配置项的开发初始版本,在开发过程中,开发人员基于开发基线的版本,开发出所需的目标版本。当发生需求变更时,通过对变更的评估,确定变更的影响范围,对被影响的配置项的版本进行修改,根据变更的性质使配置项的版本树继续延伸或产生新的分支,形成新的目标版本,而对于不受变更影响的配置项则不应发产生变动。同时,应能够将变更所产生的对版本的影响进行记录和跟踪。必要时还可以回退到以前的版本。例如当开发需求或需求变更被取消时,就需要有能力将版本回退到开发基线版本。在曾经出现过的季度升级包拆包和重新组包的过程中,其实就是将部分配置项的版本回退到开发基线,将对应不同需求的不同分支重新组合归并,形成新的升级包版本。
版本控制是软件配置管理的核心功能。所有置于配置库中的元素都应自动予以版本的标识,并保证版本命名的唯一性。版本在生成过程中,自动依照设定的使用模型自动分支、演进。除了系统自动记录的版本信息以外,为了配合软件开发流程的各个阶段。还需要定义、收集一些元数据来记录版本的辅助信息和规范开发流程,并为今后对软件过程的度量做好准备。当然如果选用的工具支持,这些辅助数据将能直接统计出过程数据,从而方便软件过程改进活动的进行。对于配置库中的各个基线控制项,应该根据其基线的位置和状态来设置相应的访问权限。一般来说,对于基线版本之前的各个版本都应处于被锁定的状态,如需要对它们进行变更,则应按照变更控制的流程来进行操作。
常用的版本控制工具:
- gitlab
- subversion
开发环境 :开发环境是程序猿们专门用于开发的服务器,配置可以比较随意, 为了开发调试方便,一般打开全部错误报告。(程序员接到需求后,开始写代码,开发,运行程序,看看程序有没有达到预期的功能
测试环境:一般是克隆一份生产环境的配置,一个程序在测试环境工作不正常,那么肯定不能把它发布到生产机上。(程序员开发完成后,交给测试部门全面的测试,看看所实现的功能有没有bug,测试人员会模拟各种操作情况
预部署环境:
生产环境
2. gitlab部署
# 配置yum源 [root@localhost ~]# cd /etc/yum.repos.d/ [root@localhost yum.repos.d]# ls CentOS-Stream-AppStream.repo CentOS-Stream-HighAvailability.repo CentOS-Stream-BaseOS.repo CentOS-Stream-Media.repo CentOS-Stream-Debuginfo.repo CentOS-Stream-PowerTools.repo CentOS-Stream-Extras.repo CentOS-Stream-RealTime.repo [root@localhost yum.repos.d]# rm -rf * [root@localhost yum.repos.d]# ls [root@localhost yum.repos.d]# [root@localhost yum.repos.d]# curl -o /etc/yum.repos.d/CentOS-Base.repohttps://mirrors.aliyun.com/repo/Centos-vault-8.5.2111.repo % Total % Received % Xferd Average Speed Time Time TimeCurrent Dload Upload Total Spent LeftSpeed 0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:--100 2495 100 2495 0 0 21144 0 --:--:-- --:--:-- --:--:-- 21144 [root@localhost yum.repos.d]# sed -i -e '/mirrors.cloud.aliyuncs.com/d'-e '/mirrors.aliyuncs.com/d' /etc/yum.repos.d/CentOS-Base.repo [root@localhost yum.repos.d]# yum install -y https://mirrors.aliyun.com/epel/epel-release-latest-8.noarch.rpm [root@localhost yum.repos.d]# sed -i 's|^#baseurl=https://download.example/pub|baseurl=https://mirrors.aliyun.com|' /etc/yum.repos.d/epel* [root@localhost yum.repos.d]# sed -i 's|^metalink|#metalink|' /etc/yum.repos.d/epel* [root@localhost yum.repos.d]# dnf clean all 37 文件已删除 [root@localhost yum.repos.d]# dnf makecache [root@localhost yum.repos.d]# ls CentOS-Base.repo epel.repo epel-testing.repo epel-modular.repo epel-testing-modular.repo
#关闭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
#安装git [root@localhost ~]# yum -y install git #安装依赖包 [root@localhost ~]# yum -y install curl openssh-server openssh-clients postfix cronie wget vim policycoreutils-python # 这个包需要到 pkgs去找,yum仓库没有 [root@localhost ~]# wget http://mirror.centos.org/centos/7/os/x86_64/Packages/policycoreutils-python-2.5-34.el7.x86_64.rpm [root@localhost ~]# ls anaconda-ks.cfg policycoreutils-python-2.5-34.el7.x86_64.rpm #卸载 policycoreutils 包,不删除会与policycoreutils-python冲突 [root@localhost ~]# dnf -y remove policycoreutils #安装 policycoreutils-python-2.5-34.el7.x86_64.rpm [root@localhost ~]# rpm -ivh --nodeps policycoreutils-python-2.5-34.el7.x86_64.rpm 警告:policycoreutils-python-2.5-34.el7.x86_64.rpm: 头V3 RSA/SHA256 Signature, 密钥 ID f4a80eb5: NOKEY Verifying... #################################[100%] 准备中... ################################# [100%] 正在升级/安装... 1:policycoreutils-python-2.5-34.el7#################################[100%] #启动postfix服务并设置开机自启 [root@localhost ~]# systemctl enable --now postfix Created symlink /etc/systemd/system/multi-user.target.wants/postfix.service → /usr/lib/systemd/system/postfix.service. #查看是否有25 号端口 [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 100 127.0.0.1:25 0.0.0.0:* LISTEN 0 128 [::]:22 [::]:* LISTEN 0 100 [::1]:25 [::]:* #下载gitlab的rpm包 [root@localhost ~]# cd /usr/src/ [root@localhost src]# ls debug kernels [root@localhost src]# wget https://mirror.tuna.tsinghua.edu.cn/gitlab-ce/yum/el7/gitlab-ce-15.2.2-ce.0.el7.x86_64.rpm [root@localhost src]# ls debug gitlab-ce-15.2.2-ce.0.el7.x86_64.rpm kernels
-
# 安装gitlab [root@localhost src]# rpm -ivh gitlab-ce-15.2.2-ce.0.el7.x86_64.rpm warning: gitlab-ce-15.2.2-ce.0.el7.x86_64.rpm: Header V4 RSA/SHA1 Signature, key ID f27eab47: NOKEY Verifying... ################################# [100%] Preparing... ################################# [100%] Updating / installing... 1:gitlab-ce-15.2.2-ce.0.el7 ################################# [100%] It looks like GitLab has not been configured yet; skipping the upgrade script. *. *. *** *** ***** ***** .****** ******* ******** ******** ,,,,,,,,,***********,,,,,,,,, ,,,,,,,,,,,*********,,,,,,,,,,, .,,,,,,,,,,,*******,,,,,,,,,,,, ,,,,,,,,,*****,,,,,,,,,. ,,,,,,,****,,,,,, .,,,***,,,, ,*,. _______ __ __ __ / ____(_) /_/ / ____ _/ /_ / / __/ / __/ / / __ `/ __ \ / /_/ / / /_/ /___/ /_/ / /_/ / \____/_/\__/_____/\__,_/_.___/ Thank you for installing GitLab! GitLab was unable to detect a valid hostname for your instance. Please configure a URL for your GitLab instance by setting `external_url` configuration in /etc/gitlab/gitlab.rb file. Then, you can start your GitLab instance by running the following command: sudo gitlab-ctl reconfigure For a comprehensive list of configuration options please see the Omnibus GitLab readme https://gitlab.com/gitlab-org/omnibus-gitlab/blob/master/README.md Help us improve the installation experience, let us know how we did with a 1 minute survey: https://gitlab.fra1.qualtrics.com/jfe/form/SV_6kVqZANThUQ1bZb?installation=omnibus&release=15-2 #修改配置文件 [root@localhost ~]# vim /etc/gitlab/gitlab.rb external_url 'http://192.168.6.137' #将此处设为gitlab的服务器ip地址亦或域名 #重载配置文件并重启gitlab [root@localhost ~]# gitlab-ctl reconfigure # 修改配置文件就需要执行这条命令,让其生效 [root@localhost ~]# gitlab-ctl restart ok: run: alertmanager: (pid 17080) 0s ok: run: gitaly: (pid 17088) 0s ok: run: gitlab-exporter: (pid 17101) 0s ok: run: gitlab-kas: (pid 17108) 1s ok: run: gitlab-workhorse: (pid 17116) 0s ok: run: grafana: (pid 17124) 1s ok: run: logrotate: (pid 17134) 0s ok: run: nginx: (pid 17140) 0s ok: run: node-exporter: (pid 17146) 1s ok: run: postgres-exporter: (pid 17151) 0s ok: run: postgresql: (pid 17167) 1s ok: run: prometheus: (pid 17176) 0s ok: run: puma: (pid 17188) 0s ok: run: redis: (pid 17193) 0s ok: run: redis-exporter: (pid 17195) 1s ok: run: sidekiq: (pid 17284) 1s [root@localhost ~]# ss -antl #查看端口号 State Recv-Q Send-Q Local Address:Port Peer Address:Port Process LISTEN 0 1024 127.0.0.1:9100 0.0.0.0:* LISTEN 0 1024 127.0.0.1:9229 0.0.0.0:* LISTEN 0 1024 127.0.0.1:8080 0.0.0.0:* LISTEN 0 511 0.0.0.0:80 0.0.0.0:* LISTEN 0 128 127.0.0.1:9168 0.0.0.0:* LISTEN 0 128 127.0.0.1:8082 0.0.0.0:* LISTEN 0 1024 127.0.0.1:9236 0.0.0.0:* LISTEN 0 1024 127.0.0.1:8150 0.0.0.0:* LISTEN 0 128 0.0.0.0:22 0.0.0.0:* LISTEN 0 1024 127.0.0.1:8151 0.0.0.0:* LISTEN 0 1024 127.0.0.1:3000 0.0.0.0:* LISTEN 0 1024 127.0.0.1:8153 0.0.0.0:* LISTEN 0 100 127.0.0.1:25 0.0.0.0:* LISTEN 0 1024 127.0.0.1:8154 0.0.0.0:* LISTEN 0 1024 127.0.0.1:8155 0.0.0.0:* LISTEN 0 128 127.0.0.1:8092 0.0.0.0:* LISTEN 0 511 0.0.0.0:8060 0.0.0.0:* LISTEN 0 1024 127.0.0.1:9121 0.0.0.0:* LISTEN 0 1024 127.0.0.1:9090 0.0.0.0:* LISTEN 0 1024 127.0.0.1:9187 0.0.0.0:* LISTEN 0 1024 127.0.0.1:9093 0.0.0.0:* LISTEN 0 1024 *:9094 *:* LISTEN 0 128 [::1]:9168 [::]:* LISTEN 0 128 [::]:22 [::]:* LISTEN 0 100 [::1]:25 [::]:*
# 查看版本号 [root@localhost ~]# head -1 /opt/gitlab/version-manifest.txt gitlab-ce 15.2.2 # 破解管理员密码
[root@localhost ~]# gitlab-rails console -e production -------------------------------------------------------------------------------- Ruby: ruby 2.7.5p203 (2021-11-24 revision f69aeb8314) [x86_64-linux] GitLab: 15.2.2 (4ecb014a935) FOSS GitLab Shell: 14.9.0 PostgreSQL: 13.6 ------------------------------------------------------------[ booted in 29.50s ] Loading production environment (Rails 6.1.4.7) irb(main):001:0> irb(main):002:0> irb(main):003:0> irb(main):004:0> irb(main):005:0> irb(main):006:0> irb(main):007:0> irb(main):008:0> user = User.where(id: 1).first #id为1的是超级管理员 => #<User id:1 @root> irb(main):010:0> user.password = '12345678' #密码必须至少8个字符 => "12345678" irb(main):011:0> user.password_confirmation = '12345678' #再次确认密码 => "12345678" irb(main):012:0> user.save! # 保存修改,若无问题将返回true => true irb(main):013:0> exit # 退出gitlab管理
在浏览器中使用gitlab服务器的ip访问,页面如下图所示
gitlab常用管理操作
- 项目管理(通常只是创建新项目)
- 创建成员组(针对某个项目创建一个成员组)
- 用户管理(此用户乃gitlab用户而非系统用户)
- 来了新员工,为其添加gitlab用户
- 员工离职,将其gitlab用户禁用或删除
点击创建项目
点击创建空项目
使用它提供的代码创建README文件 然后上传到仓库里
[root@localhost ~]# cd test/ [root@localhost test]# ls [root@localhost test]# git switch -c main Switched to a new branch 'main' [root@localhost test]# touch README.md [root@localhost test]# ls README.md [root@localhost test]# git add README.md # 创建 [root@localhost test]# ls README.md [root@localhost test]# git commit -m "add README" [main (root-commit) cf3eb0a] add README 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 README.md [root@localhost test]# git push -u origin main Username for 'http://192.168.6.137': root Password for 'http://root@192.168.6.137': Enumerating objects: 3, done. Counting objects: 100% (3/3), done. Writing objects: 100% (3/3), 203 bytes | 203.00 KiB/s, done. Total 3 (delta 0), reused 0 (delta 0), pack-reused 0 To http://192.168.6.137/gitlab-instance-5dbdd410/test.git * [new branch] main -> main Branch 'main' set up to track remote branch 'main' from 'origin'.
创建组
创建用户
把用户添加到组里,然后设置组权限,不然来一个用户你就需要设置一个权限,来一个设置一个,工作的效率就低了
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 全程不用写代码,我用AI程序员写了一个飞机大战
· DeepSeek 开源周回顾「GitHub 热点速览」
· 记一次.NET内存居高不下排查解决与启示
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· .NET10 - 预览版1新功能体验(一)