版本控制gitlab
1. 版本控制介绍
版本控制是指对软件开发过程中各种程序代码、配置文件及说明文档等文件变更的管理,是软件配置管理的核心思想之一。
版本控制最主要的功能就是追踪文件的变更。它将什么时候、什么人更改了文件的什么内容等信息忠实地了记录下来。每一次文件的改变,文件的版本号都将增加。除了记录版本变更外,版本控制的另一个重要功能是并行开发。软件开发往往是多人协同作业,版本控制可以有效地解决版本的同步以及不同开发者之间的开发通信问题,提高协同开发的效率。并行开发中最常见的不同版本软件的错误(Bug)修正问题也可以通过版本控制中分支与合并的方法有效地解决。
具体来说,在每一项开发任务中,都需要首先设定开发基线,确定各个配置项的开发初始版本,在开发过程中,开发人员基于开发基线的版本,开发出所需的目标版本。当发生需求变更时,通过对变更的评估,确定变更的影响范围,对被影响的配置项的版本进行修改,根据变更的性质使配置项的版本树继续延伸或产生新的分支,形成新的目标版本,而对于不受变更影响的配置项则不应发产生变动。同时,应能够将变更所产生的对版本的影响进行记录和跟踪。必要时还可以回退到以前的版本。例如当开发需求或需求变更被取消时,就需要有能力将版本回退到开发基线版本。在曾经出现过的季度升级包拆包和重新组包的过程中,其实就是将部分配置项的版本回退到开发基线,将对应不同需求的不同分支重新组合归并,形成新的升级包版本。
版本控制是软件配置管理的核心功能。所有置于配置库中的元素都应自动予以版本的标识,并保证版本命名的唯一性。版本在生成过程中,自动依照设定的使用模型自动分支、演进。除了系统自动记录的版本信息以外,为了配合软件开发流程的各个阶段。还需要定义、收集一些元数据来记录版本的辅助信息和规范开发流程,并为今后对软件过程的度量做好准备。当然如果选用的工具支持,这些辅助数据将能直接统计出过程数据,从而方便软件过程改进活动的进行。对于配置库中的各个基线控制项,应该根据其基线的位置和状态来设置相应的访问权限。一般来说,对于基线版本之前的各个版本都应处于被锁定的状态,如需要对它们进行变更,则应按照变更控制的流程来进行操作。
常用的版本控制工具:
- gitlab
- subversion
2. gitlab部署
//配置yum源
[root@liuwei ~]# curl -o /etc/yum.repos.d/CentOS7-Base-163.repo http://mirrors.163.com/.help/CentOS7-Base-163.repo
[root@liuweit ~]# sed -i 's/\$releasever/7/g' /etc/yum.repos.d/CentOS7-Base-163.repo
[root@liuwei~]# sed -i 's/^enabled=.*/enabled=1/g' /etc/yum.repos.d/CentOS7-Base-163.repo
[root@liuwei ~]# yum -y install epel-release
//安装git
[root@liuwei ~]# yum -y install epel-release git
安装略
//安装依赖包
[root@liuwei ~]# yum -y install curl openssh-server openssh-clients postfix cronie policycoreutils-python
已加载插件:product-id, search-disabled-repos, subscription-manager
This system is not registered with an entitlement server. You can use subscription-manager to register.
软件包 2:postfix-2.10.1-7.0.1.el7.centos.x86_64 已安装并且是最新版本
正在解决依赖关系
--> 正在检查事务
---> 软件包 cronie.x86_64.0.1.4.11-17.el7 将被 升级
...
...
作为依赖被升级:
audit.x86_64 0:2.8.4-4.el7 audit-libs.x86_64 0:2.8.4-4.el7 cronie-anacron.x86_64 0:1.4.11-20.el7_6
libcurl.x86_64 0:7.29.0-51.el7 nspr.x86_64 0:4.19.0-1.el7_5 nss.x86_64 0:3.36.0-7.1.el7_6
nss-pem.x86_64 0:1.0.3-5.el7 nss-softokn.x86_64 0:3.36.0-5.el7_5 nss-softokn-freebl.x86_64 0:3.36.0-5.el7_5
nss-sysinit.x86_64 0:3.36.0-7.1.el7_6 nss-tools.x86_64 0:3.36.0-7.1.el7_6 nss-util.x86_64 0:3.36.0-1.1.el7_6
openssh.x86_64 0:7.4p1-16.el7
完毕!
//启动postfix服务并设置开机自启
[root@liuwei ~]# systemctl restart postfix
[root@liuwei ~]# systemctl enable postfix
//下载gitlab的rpm包
[root@localhost src]# wget https://mirrors.tuna.tsinghua.edu.cn/gitlab-ce/yum/el7/gitlab-ce-11.2.1-ce.0.el7.x86_64.rpm
[root@liuwei src]# ls
debug gitlab-ce-11.2.1-ce.0.el7.x86_64.rpm kernels mysql57-community-release-el7-10.noarch.rpm
//安装gitlab
[root@liuwei src]# rpm -ivh gitlab-ce-11.2.1-ce.0.el7.x86_64.rpm
警告:gitlab-ce-11.2.1-ce.0.el7.x86_64.rpm: 头V4 RSA/SHA1 Signature, 密钥 ID f27eab47: NOKEY
准备中... ################################# [100%]
正在升级/安装...
1:gitlab-ce-11.2.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
//修改配置文件
[root@liuwei src]# cat /etc/gitlab/gitlab.rb |grep external_url
external_url 'http://192.168.110.20' //将此处设为gitlab的服务器ip地址亦或域名
//重载配置文件并重启gitlab
[root@lw ~]# gitlab-ctl reconfigure
Running handlers:
Running handlers complete
Chef Client finished, 429/614 resources updated in 07 minutes 10 seconds
gitlab Reconfigured!
[root@lw ~]# gitlab-ctl restart
ok: run: alertmanager: (pid 4188) 0s
ok: run: gitaly: (pid 4197) 0s
ok: run: gitlab-monitor: (pid 4207) 0s
ok: run: gitlab-workhorse: (pid 4210) 0s
ok: run: logrotate: (pid 4219) 0s
ok: run: nginx: (pid 4225) 0s
ok: run: node-exporter: (pid 4231) 1s
ok: run: postgres-exporter: (pid 4236) 0s
ok: run: postgresql: (pid 4250) 0s
ok: run: prometheus: (pid 4259) 0s
ok: run: redis: (pid 4266) 1s
ok: run: redis-exporter: (pid 4292) 0s
ok: run: sidekiq: (pid 4324) 0s
ok: run: unicorn: (pid 4338) 1s
//查看当前的gitlab版本
[root@lw ~]# head -1 /opt/gitlab/version-manifest.txt
gitlab-ce 11.2.1
//设置管理员密码
[root@lw ~]# gitlab-rails console production
-------------------------------------------------------------------------------------
GitLab: 11.2.1 (2d6c1c6)
GitLab Shell: 8.1.1
postgresql: 9.6.8
-------------------------------------------------------------------------------------
Loading production environment (Rails 4.2.10)
irb(main):001:0> user = User.where(id: 1).first
=> #<User id:1 @root>
irb(main):005:0> user.password = 'liuwei1234'
=> "liuwei1234"
irb(main):006:0> user.save!
Enqueued ActionMailer::DeliveryJob (Job ID: 1a4a13b5-6b2f-44ac-8072-c5066c8739b4) to Sidekiq(mailers) with arguments: "DeviseMailer", "password_change", "deliver_now", gid://gitlab/User/1
=> true
[root@lw ~]# ss -anlt
State Recv-Q Send-Q Local Address:Port Peer Address:Port
LISTEN 0 128 127.0.0.1:9100 *:*
LISTEN 0 128 127.0.0.1:9229 *:*
LISTEN 0 128 *:111 *:*
LISTEN 0 128 127.0.0.1:8080 *:*
LISTEN 0 128 127.0.0.1:9168 *:*
LISTEN 0 128 *:80 *:*
LISTEN 0 128 127.0.0.1:8082 *:*
LISTEN 0 128 127.0.0.1:9236 *:*
LISTEN 0 128 *:22 *:*
LISTEN 0 100 127.0.0.1:25 *:*
LISTEN 0 128 *:8060 *:*
LISTEN 0 128 127.0.0.1:9121 *:*
LISTEN 0 128 127.0.0.1:9090 *:*
LISTEN 0 128 127.0.0.1:9187 *:*
LISTEN 0 128 127.0.0.1:9093 *:*
LISTEN 0 5 *:873 *:*
LISTEN 0 128 :::111 :::*
LISTEN 0 128 ::1:9168 :::*
LISTEN 0 32 :::21 :::*
LISTEN 0 128 :::22 :::*
LISTEN 0 100 ::1:25 :::*
LISTEN 0 128 :::9094 :::*
LISTEN 0 5 :::873 :::*
3. gitlab管理
在浏览器中使用gitlab服务器的ip访问
先设置一个新密码
使用新密码登录,用户名为root
添加项目
添加新用户:
在客户端中:
[root@liuwei ~]# git config --global user.name "liuwei"
[root@liuwei ~]# git config --global user.email "2250062483@qq.com"
[root@liuwei ~]# cd /opt/
[root@liuwei opt]# git clone http://192.168.110.21/root/runtime.git
正克隆到 'runtime'...
warning: 您似乎克隆了一个空版本库。
[root@liuwei opt]# cd runtime/
[root@liuwei runtime]# ls
[root@liuwei runtime]# touch README.md
[root@liuwei runtime]# ls
README.md
[root@liuwei runtime]# git add README.md
[root@liuwei runtime]# git commit -m '添加了README.md文件'
[master(根提交) 1ccc1cf] 添加了README.md文件
1 file changed, 0 insertions(+), 0 deletions(-)
create mode 100644 README.md
[root@liuwei runtime]# git push -u origin master
Username for 'http://192.168.110.21': liuwei
Password for 'http://liuwei@192.168.110.21':
fatal: unable to access 'http://192.168.110.21/root/runtime.git/': The requested URL returned error: 403
发现liuwei这个用户并没有访问权限
在这个项目中添加这个用户
[root@liuwei runtime]# git push -u origin master
Username for 'http://192.168.110.21': root
Password for 'http://root@192.168.110.21':
Counting objects: 3, done.
Writing objects: 100% (3/3), 232 bytes | 0 bytes/s, done.
Total 3 (delta 0), reused 0 (delta 0)
To http://192.168.110.21/root/runtime.git
* [new branch] master -> master
分支 master 设置为跟踪来自 origin 的远程分支 master。
已经添加完成
查看master
添加新分支
添加组
gitlab常用管理操作
- 项目管理(通常只是创建新项目)
- 创建成员组(针对某个项目创建一个成员组)
- 用户管理(此用户乃gitlab用户而非系统用户)
- 来了新员工,为其添加gitlab用户
- 员工离职,将其gitlab用户禁用或删除