版本控制介绍
版本控制是指对软件开发过程中各种程序代码、配置文件及说明文档等文件变更的管理,是软件配置管理的核心思想之一。
版本控制最主要的功能就是追踪文件的变更。它将什么时候、什么人更改了文件的什么内容等信息忠实地了记录下来。每一次文件的改变,文件的版本号都将增加。除了记录版本变更外,版本控制的另一个重要功能是并行开发。软件开发往往是多人协同作业,版本控制可以有效地解决版本的同步以及不同开发者之间的开发通信问题,提高协同开发的效率。并行开发中最常见的不同版本软件的错误(Bug)修正问题也可以通过版本控制中分支与合并的方法有效地解决。
具体来说,在每一项开发任务中,都需要首先设定开发基线,确定各个配置项的开发初始版本,在开发过程中,开发人员基于开发基线的版本,开发出所需的目标版本。当发生需求变更时,通过对变更的评估,确定变更的影响范围,对被影响的配置项的版本进行修改,根据变更的性质使配置项的版本树继续延伸或产生新的分支,形成新的目标版本,而对于不受变更影响的配置项则不应发产生变动。同时,应能够将变更所产生的对版本的影响进行记录和跟踪。必要时还可以回退到以前的版本。例如当开发需求或需求变更被取消时,就需要有能力将版本回退到开发基线版本。在曾经出现过的季度升级包拆包和重新组包的过程中,其实就是将部分配置项的版本回退到开发基线,将对应不同需求的不同分支重新组合归并,形成新的升级包版本。
版本控制是软件配置管理的核心功能。所有置于配置库中的元素都应自动予以版本的标识,并保证版本命名的唯一性。版本在生成过程中,自动依照设定的使用模型自动分支、演进。除了系统自动记录的版本信息以外,为了配合软件开发流程的各个阶段。还需要定义、收集一些元数据来记录版本的辅助信息和规范开发流程,并为今后对软件过程的度量做好准备。当然如果选用的工具支持,这些辅助数据将能直接统计出过程数据,从而方便软件过程改进活动的进行。对于配置库中的各个基线控制项,应该根据其基线的位置和状态来设置相应的访问权限。一般来说,对于基线版本之前的各个版本都应处于被锁定的状态,如需要对它们进行变更,则应按照变更控制的流程来进行操作。
常用的版本控制工具:
- gitlab
- github
- gitee 码云
- subversion
上线流程
开发任务:
- master(经过测试的没问题的基础代码)
- 20210512(新功能1)
- 20210513(新功能2)
发布-->发版-->上线(分支)
回滚、回退(防止上线时出问题,保证服务正常进行相当于虚拟机快照)
环境部署:
- 开发环境
- 测试环境
- 预部署环境/准生产环境
- 生产环境(用户使用)
开始上线:
紧急变更,向CTO说明情况,由CTO来决定要不要发
- 开发代码(开发人员)
- 测试(测试人员)
- 发布(运维人员)
- 测试(测试人员)
- 发邮件申请发布(开发人员)
邮件发给开发Leader、抄送给运维团队
- 填写变更单,避免背锅
- 开发Leader审批
- 评估影响范围(运维人员)
- 向运维Leader汇报(运维人员)
- 与开发Leader协商(运维Leader)
- 发布(运维人员)---> 生产环境
- 测试(测试人员)---> 出问题就回滚(运维人员)
GitLab介绍
GitLab 是一个用于仓库管理系统的开源项目,使用Git作为代码管理工具,并在此基础上搭建起来的web服务;
GitLab由乌克兰程序员DmitriyZaporozhets和ValerySizov开发,它由Ruby写成。后来,一些部分用Go语言重写,现今并在国内外大中型互联网公司广泛使用。
GitLab拥有与Github类似的功能,能够浏览源代码,管理缺陷和注释;
可以管理团队对仓库的访问,它非常易于浏览提交过的版本并提供一个文件历史库;
它还提供一个代码片段收集功能可以轻松实现代码复用,便于日后有需要的时候进行查找。
常用的网站:
GitLab配置
GitLab 的默认配置文件为于:/etc/gitlab/gitlab.rb
,修改下图所示的 external_url
为本机 IP 地址或者一个可以访问到本机的域名;
修改完配置文件后,使用gitlab-ctl reconfigure重新配置gitlab。
GitLab基础目录
以下是gitlab常用的默认安装目录
gitlab组件日志路径: /var/log/gitlab
gitlab配置路径: /etc/gitlab/ 路径下有gitlab.rb配置文件
应用代码和组件依赖程序: /opt/gitlab
各个组件存储路径: /var/opt/gitlab/
仓库默认存储路径: /var/opt/gitlab/git-data/repositories
版本文件备份路径: /var/opt/gitlab/backups/
nginx安装路径: /var/opt/gitlab/nginx/
redis安装路径: /var/opt/gitlab/redis
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-ctl tail | 查看服务的日志 |
GitLab常用组件
GitLab 由主要由以下服务构成,他们共同承担了 Gitlab 的运作需要
nginx: 静态Web服务器
gitlab-shell: 用于处理Git命令和修改authorized keys列表,我们的gitlab是以Git做为最层的,你操作实际上最后就是调用gitlab-shell命令进行处理。
gitlab-workhorse: 轻量级的反向代理服务器
logrotate: 日志文件管理工具
postgresql: 数据库
redis: 缓存数据库
sidekiq: 用于在后台执行队列任务(异步执行)
unicorn: GitLab Rails应用是托管在这个服务器上面的
GitLab部署
注意!!!在部署之前要确保环境为纯洁环境,内存尽量给多一些
需要满足cpu:2核 内存:8g (最低配置)
配置yum源+安装依赖包+开启postfix邮箱服务
//配置源
curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-8.repo
sed -i -e '/mirrors.cloud.aliyuncs.com/d' -e '/mirrors.aliyuncs.com/d' /etc/yum.repos.d/CentOS-Base.repo
sed -i 's|$releasever|8|' /etc/yum.repos.d/CentOS-Base.repo
yum install -y https://mirrors.aliyun.com/epel/epel-release-latest-8.noarch.rpm
sed -i 's|^#baseurl=https://download.fedoraproject.org/pub|baseurl=https://mirrors.aliyun.com|' /etc/yum.repos.d/epel*
sed -i 's|^metalink|#metalink|' /etc/yum.repos.d/epel*
sed -i 's|$releasever|8|' /etc/yum.repos.d/epel*
//安装依赖包
[root@localhost ~]# yum -y install git curl openssh-server openssh-clients postfix cronie python3-policycoreutils policycoreutils-python-utils
//启动postfix服务并设置开机自启
[root@localhost ~]# systemctl restart postfix
[root@localhost ~]# systemctl enable --now postfix
安装gitlab
下载gitlab安装包
gitlab安装包网站(清华大学):Index of /gitlab-ce/yum/ | 清华大学开源软件镜像站
访问网站,本次使用的是epel8
选择你需要的版本下载到本机,本次使用的是最新的版本13.9.7
使用xftp传进来
开始安装
//查看传进来的包
[root@localhost ~]# ls
anaconda-ks.cfg gitlab-ce-13.9.7-ce.0.el8.x86_64.rpm
//安装gitlab
[root@localhost ~]# rpm -ivh gitlab-ce-13.9.7-ce.0.el8.x86_64.rpm
warning: gitlab-ce-13.9.7-ce.0.el8.x86_64.rpm: Header V4 RSA/SHA256 Signature, key ID f27eab47: NOKEY
Verifying... ################################# [100%]
Preparing... ################################# [100%]
Updating / installing...
1:gitlab-ce-13.9.7-ce.0.el8 ################################# [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=13-9
//修改配置文件
#搜索external_url
[root@localhost ~]# vim /etc/gitlab/gitlab.rb
##! https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/instancedata-data-retrieval.html
external_url 'http://192.168.110.14' //将此处设为gitlab的服务器ip地址亦或域名
//重载配置文件并重启github
#重载文件
[root@localhost ~]# gitlab-ctl reconfigure
It seems you haven't specified an initial root password while configuring the GitLab instance.
On your first visit to your GitLab instance, you will be presented with a screen to set a
password for the default admin account with username `root`.
gitlab Reconfigured!
#重启gitlab
[root@localhost ~]# gitlab-ctl restart
ok: run: alertmanager: (pid 19248) 0s
ok: run: gitaly: (pid 19256) 0s
ok: run: gitlab-exporter: (pid 19282) 0s
ok: run: gitlab-workhorse: (pid 19284) 0s
ok: run: grafana: (pid 19291) 1s
ok: run: logrotate: (pid 19300) 0s
ok: run: nginx: (pid 19306) 1s
ok: run: node-exporter: (pid 19311) 0s
ok: run: postgres-exporter: (pid 19315) 1s
ok: run: postgresql: (pid 19327) 0s
ok: run: prometheus: (pid 19336) 0s
ok: run: puma: (pid 19421) 0s
ok: run: redis: (pid 19426) 0s
ok: run: redis-exporter: (pid 19432) 1s
ok: run: sidekiq: (pid 19439) 0s
#查看端口
[root@localhost ~]# ss -antl
State Recv-Q Send-Q Local Address:Port Peer Address:Port
LISTEN 0 1024 127.0.0.1:3000 0.0.0.0:*
LISTEN 0 100 127.0.0.1:25 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 127.0.0.1:9100 0.0.0.0:*
LISTEN 0 1024 127.0.0.1:9229 0.0.0.0:*
LISTEN 0 128 127.0.0.1:9168 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:8082 0.0.0.0:*
LISTEN 0 128 127.0.0.1:9236 0.0.0.0:*
LISTEN 0 128 0.0.0.0:22 0.0.0.0:*
LISTEN 0 100 [::1]:25 [::]:*
LISTEN 0 1024 *:9094 *:*
LISTEN 0 128 [::1]:9168 [::]:*
LISTEN 0 128 [::]:22 [::]:*
#查看当前gitlab版本
[root@localhost ~]# head -1 /opt/gitlab/version-manifest.txt
gitlab-ce 13.9.7
安装完成,可以访问GitLab网页
注意:在访问之前需要关闭防火墙
[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 ~]# sed -ri 's/^(SELINUX=).*/\1disabled/g' /etc/sysconfig/selinux
[root@localhost ~]# setenforce 0
访问网页192.168.110.14
第一次访问,需要输入新密码(例:12345678)
输入用户名(默认是root)和密码登录(用户名:root 密码:12345678)
gitlab界面如下
汉化页面
建议使用英文界面,这里是为了方便演示
点击右上角个人头像 ---> Preferences ---> 下滑 ---> 选择需要的语言 ---> 点击Save changes
Gitlab关闭注册功能
由于我们Gitlab系统是私有仓库,一般用户都是由管理员创建和分派的,所以我们需要关闭注册
如图所示
退回到系统的登录页面,发现已经没有用户注册功能
破解密码
当前的密码是12345678,现在我们需要破解密码然后设置一个新密码(876543321)
破解管理员密码
[root@localhost ~]# gitlab-rails console -e production
--------------------------------------------------------------------------------
Ruby: ruby 2.7.2p137 (2020-10-01 revision 5445e04352) [x86_64-linux]
GitLab: 13.9.7 (05f9b5a73c8) FOSS
GitLab Shell: 13.17.0
PostgreSQL: 12.6
--------------------------------------------------------------------------------
Loading production environment (Rails 6.0.3.4)
irb(main):001:0> user = User.where(id: 1).first
=> #<User id:1 @root>
irb(main):002:0> user.password = '87654321'
=> "87654321"
irb(main):003:0> user.password_confirmation = '87654321'
=> "87654321"
irb(main):004:0> user.save!
Enqueued ActionMailer::MailDeliveryJob (Job ID: 9e90eb73-02cb-4b1f-a1a2-1a2d04682350) to Sidekiq(mailers) with arguments: "DeviseMailer", "password_change", "deliver_now", {:args=>[#<GlobalID:0x00007f7870557180 @uri=#<URI::GID gid://gitlab/User/1>>]}
=> true
irb(main):005:0> exit
使用新密码(87654321)登录
成功登录