版本控制gitlab
版本控制介绍
版本控制是指对软件开发过程中各种程序代码、配置文件及说明文档等文件变更的管理,是软件配置管理的核心思想之一。
版本控制最主要的功能就是追踪文件的变更。
它将什么时候、什么人更改了文件的什么内容等信息忠实地了记录下来。每一次文件的改变,文件的版本号都将增加。除了记录版本变更外,版本控制的另一个重要功能是并行开发。软件开发往往是多人协同作业,版本控制可以有效地解决版本的同步以及不同开发者之间的开发通信问题,提高协同开发的效率。并行开发中最常见的不同版本软件的错误(Bug)修正问题也可以通过版本控制中分支与合并的方法有效地解决。
具体来说,在每一项开发任务中,都需要首先设定开发基线,确定各个配置项的开发初始版本,在开发过程中,开发人员基于开发基线的版本,开发出所需的目标版本。当发生需求变更时,通过对变更的评估,确定变更的影响范围,对被影响的配置项的版本进行修改,根据变更的性质使配置项的版本树继续延伸或产生新的分支,形成新的目标版本,而对于不受变更影响的配置项则不应发产生变动。同时,应能够将变更所产生的对版本的影响进行记录和跟踪。必要时还可以回退到以前的版本。例如当开发需求或需求变更被取消时,就需要有能力将版本回退到开发基线版本。在曾经出现过的季度升级包拆包和重新组包的过程中,其实就是将部分配置项的版本回退到开发基线,将对应不同需求的不同分支重新组合归并,形成新的升级包版本。
版本控制是软件配置管理的核心功能。所有置于配置库中的元素都应自动予以版本的标识,并保证版本命名的唯一性。版本在生成过程中,自动依照设定的使用模型自动分支、演进。除了系统自动记录的版本信息以外,为了配合软件开发流程的各个阶段。还需要定义、收集一些元数据来记录版本的辅助信息和规范开发流程,并为今后对软件过程的度量做好准备。当然如果选用的工具支持,这些辅助数据将能直接统计出过程数据,从而方便软件过程改进活动的进行。对于配置库中的各个基线控制项,应该根据其基线的位置和状态来设置相应的访问权限。一般来说,对于基线版本之前的各个版本都应处于被锁定的状态,如需要对它们进行变更,则应按照变更控制的流程来进行操作。
常用的版本控制工具:
- gitlab
- subversion(svn)
master分支(branch) :只放没有问题的代码
开发环境: 给开发使用的环境 给root权限
测试环境: 给测试用的环境 给root权限
预部署环境 :/准生产环境
生产环境 : 面向客户的环境 不能随便的发布/上线
gitlab部署
//首先准备一台虚拟机(初始化环境,内存给大点例如16g内存,给10g)
此处准备的虚拟机为centos
//首先关闭防火墙 selinux
[root@centos ~]# systemctl disable --now firewalld
Removed /etc/systemd/system/multi-user.target.wants/firewalld.service.
Removed /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service.
[root@centos ~]# setenforce 0
[root@centos ~]# vi /etc/selinux/config
# This file controls the state of SELinux on the system.
# SELINUX= can take one of these three values:
# enforcing - SELinux security policy is enforced.
# permissive - SELinux prints warnings instead of enforcing.
# disabled - No SELinux policy is loaded.
SELINUX=disabled //将此处改为关闭状态
# SELINUXTYPE= can take one of these three values:
# targeted - Targeted processes are protected,
# minimum - Modification of targeted policy. Only selected processes are protected.
# mls - Multi Level Security protection.
SELINUXTYPE=targeted
//重启一下
[root@centos ~]# reboot
//此处是为了确保selinux处于disable状态
//配置yum源(https://developer.aliyun.com/mirror/)
[root@centos ~]# curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-vault-8.5.2111.repo
[root@centos yum.repos.d]# sed -i -e '/mirrors.cloud.aliyuncs.com/d' -e '/mirrors.aliyuncs.com/d' /etc/yum.repos.d/CentOS-Base.repo //删除云相关的东西
//清缓存
[root@centos ~]# yum clean all
//建立缓存
[root@centos ~]# yum makecache
//配置epel源
[root@centos ~]# yum install -y https://mirrors.aliyun.com/epel/epel-release-latest-8.noarch.rpm
[root@centos ~]# sed -i 's|^#baseurl=https://download.example/pub|baseurl=https://mirrors.aliyun.com|' /etc/yum.repos.d/epel*
[root@centos ~]# sed -i 's|^metalink|#metalink|' /etc/yum.repos.d/epel*
//清缓存
[root@centos ~]# yum clean all
//建立缓存
[root@centos ~]# yum makecache
//先安装wget命令
[root@centos ~]# yum -y install wget vim
//在pkgs.org里面搜索policycoreutils-python
[root@centos ~]# wget http://mirror.centos.org/centos/7/os/x86_64/Packages/policycoreutils-python-2.5-34.el7.x86_64.rpm
[root@centos ~]# rpm -ivh --nodeps policycoreutils-python-2.5-34.el7.x86_64.rpm
//安装依赖包
[root@centos ~]# yum -y install git curl openssh-server openssh-clients postfix cronie perl
//启动postfix并设置开机自启
[root@centos ~]# systemctl enable --now postfix
[root@centos ~]# 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(https://mirror.tuna.tsinghua.edu.cn/ 搜索gitlab选择gitlab-ce>yum>el7>选择gitlab-ce-16.4.1-ce.0.el7.x86_64.rpm 1.2 GiB 2023-09-22 21:40这个包)
//先下载
[root@centos ~]# wget https://mirror.tuna.tsinghua.edu.cn/gitlab-ce/yum/el7/gitlab-ce-16.4.1-ce.0.el7.x86_64.rpm
//再安装
[root@centos ~]# 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 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=16-4
//根据系统提示
//更改文件内容
[root@centos ~]# vim /etc/gitlab/gitlab.rb
将:external_url 'http://192.168.134.155'
//在最新版本需要
将:gitlab_workhorse['auth_backend'] = "http://localhost:8080" //将注释取消掉
以及:puma['port'] = 8080 //将注释取消掉
//查看一下端口号
[root@centos ~]# ss -antl
//按要求执行命令
[root@centos ~]# sudo gitlab-ctl reconfigure
...
gitlab Reconfigured!
//完成
[root@centos ~]# gitlab-ctl restart
//查看版本
[root@centos ~]# head -1 /opt/gitlab/version-manifest.txt
gitlab-ce 16.4.1
用网址访问http://192.168.134.155
外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传
服务讲解
1、登录:
1>直接登录(知道密码)
//查看登录密码
[root@centos gitlab]# cd /etc/gitlab/
[root@centos gitlab]# ls
gitlab.rb gitlab-secrets.json initial_root_password trusted-certs
[root@centos gitlab]# cat initial_root_password
...
# 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: uywI+HqAkKQPdvSzH/A1vjRIZLx0fivNfjgFwB0nLis=
# NOTE: This file will be automatically deleted in the first reconfigure run after 24 hours.
//这里提示这个文件将在24小时之后自动删除,所以登录之后需要修改密码
更改密码
点击(password:Luchengyang111!)
然后重新用root账号登录
2>破解密码(不知道密码)
//破解密码
[root@centos ~]# 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 21.46s ]
Loading production environment (Rails 7.0.6)
irb(main):001:0> user = User.where(id: 1).first //id为1的是超级管理员
=> #<User id:1 @root> //表示定义变量为超级管理员
irb(main):002:0> user.password = 'Luchengyang111!' //设置密码
=> "Luchengyang111!"
irb(main):003:0> user.password_confirmation = 'Luchengyang111!' //再次输入
=> "Luchengyang111!"
irb(main):004:0> user.save //保存一下
=> true
irb(main):005:0> quit
//再次进入网页用新密码登录
2、简介
1》创建项目
创建空项目:
此处不选择初始化一个README文件会显示帮助文档告诉你该如何使用
举例:创建一个空项目lcy,向里面创建一个test文件并上传
//Git global setup:全局配置
[root@centos ~]# git config --global user.name "root" //配置用户名
[root@centos ~]# git config --global user.email "1@2.com" //配置邮箱
//Create a new repository:创建新仓库
//将其克隆到本地
[root@centos ~]# git clone http://192.168.134.155/root/lcy.git
Cloning into 'lcy'...
Username for 'http://192.168.134.155': root //用户名
Password for 'http://root@192.168.134.155': //密码(Luchengyang111!)
warning: You appear to have cloned an empty repository.
//此处显示克隆一个空文件
[root@centos ~]# cd lcy/
[root@centos lcy]# ls
//创建一个主分支
[root@centos lcy]# git switch --create main
Switched to a new branch 'main' //这里显示进入到新分支来了
//写一个文件
[root@centos lcy]# echo "hello world" > test
[root@centos lcy]# ls
test
[root@centos lcy]# git add test //添加test文件
[root@centos lcy]# git commit -m "first commit" //commit:提交 -m:后面接描述信息
[main (root-commit) 47c6613] first commit
1 file changed, 1 insertion(+)
create mode 100644 test
//上传
[root@centos lcy]# git push --set-upstream origin main
Username for 'http://192.168.134.155': root
Password for 'http://root@192.168.134.155':
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.134.155/root/lcy.git
* [new branch] main -> main
Branch 'main' set up to track remote branch 'main' from 'origin'.
//上传成功
检验:
在网页上直接操作:
选择编辑单个文件
在网页上直接创建:
创建组:
创建用户:
此时的密码统一设置为Abc123!(很简单的密码,因为开发登录的时候会重新设置密码,我此次设置的密码为Luchengyang111!)
在组里面添加用户:
点击:invite
给权限:
添加项目成员成功
登出极狐
重新登录
测试:
gitlab常用管理操作**
- 项目管理(通常只是创建新项目)
- 创建成员组(针对某个项目创建一个成员组)
- 用户管理(此用户乃gitlab用户而非系统用户)
- 来了新员工,为其添加gitlab用户
- 员工离职,将其gitlab用户禁用或删除
报错:
访问网页 发现无法访问
1、将系统重启
reboot //如果重启还是无法访问网页
2、
//启动一下
gitlab-ctl start
ss -antl(发现:没有8080端口)
//修改文件配置
vim /etc/gitlab/gitlab.rb
将:gitlab_workhorse['auth_backend'] = "http://localhost:8080"
以及:puma['port'] = 8080 //将注释取消掉
//重载配置文件
gitlab-ctl reconfigure
//查看端口号
ss -antl
发现8080端口,再次访问网页 访问成功