CI/CD——Gitlab构建分布式版本控制系统

版本控制概念

记录开发文件的时间机器,为了更好的开发,挽回代码错误带来的损失

GitLab部署

本实验GitLb服务器版本基于 gitlab-ce-9.1.0

实验流程参考官方文档:https://about.gitlab.com/install/#centos-7 部分略有改动

环境准备

两台CentOS7虚拟机 内存均为4G
192.168.100.10/24
CentOS Linux release 7.5.1804 (Core)  #版本为7.5.1804

安装并配置依赖环境

GitLab所依赖的环境

#因为涉及软件较多我安装了epel扩展源
[root@localhost ~]# yum install https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
...
repolist: 26,344
[root@localhost ~]# yum -y install curl policycoreutils openssh-server open-clients  #安装和配置必要的依赖关系
[root@localhost ~]# systemctl enable sshd --now                                      #开机自启动ssh程序并立即启动
[root@localhost ~]# yum -y install postfix                                           #安装邮箱程序
#关于安装邮箱程序的解释:Git在记录用户信息时,使用的是邮箱地址
[root@localhost ~]# systemctl enable  postfix --now

注:使用postfix邮箱服务器时,主机名必须使用 localhost 本地主机名,否则会发生报错

构建Git服务器YUM仓库

wget https://mirrors.tuna.tsinghua.edu.cn/gitlab-ce/yum/el7/gitlab-ce-9.1.0-ce.0.el7.x86_64.rpm

[root@localhost ~]# yum -y install gitlab-ce-9.1.0-ce.0.el7.x86_64.rpm

在这里插入图片描述

配置GitLab

[root@localhost ~]# gitlab-ctl reconfigure                        #reconfigure:重新配置 
#配置过程GitLab程序会自己部署环境,供用户访问,并加载前端页面,及后台数据库

浏览主机名和登录名

GitLab占用80端口,访问时直接访问IP就可

http://192.168.100.10/

第一次访问会让你确认root账户登录密码
在这里插入图片描述登录
在这里插入图片描述

欢迎界面
在这里插入图片描述

为GitLab创建项目

在这里插入图片描述
因为实验的关系设置为所有人可访问
在这里插入图片描述

推送SSH秘钥

根据秘钥提示创建免密
在这里插入图片描述

生成秘钥

[root@localhost ~]# ssh-keygen

上传秘钥

用户 > 设置 > SSH Keys

[root@localhost ~]# cat .ssh/id_rsa.pub

在这里插入图片描述
在这里插入图片描述

使用GitLab

图形操作

上传文件到GitLab

左上角projects > + > New file
在这里插入图片描述
编辑新文档
在这里插入图片描述
在这里插入图片描述
下载文件
在这里插入图片描述

命令行操作

复制HTTP地址及SSH地址
在这里插入图片描述

http://root@localhost/root/project1.git
git@localhost:root/project1.git

克隆服务器的文件

[root@localhost ~]# git config --global user.name "root"             #声明登录账号
[root@localhost ~]# git config --global user.email "root@localhost"  #声明邮箱地址
[root@localhost ~]# git clone git@localhost:root/project1.git        #克隆文件以SSH git为来宾账号

上传文件

[root@localhost project1]# pwd                                                   #与项目同名文件夹
/root/project1
[root@localhost project1]# echo 11111 > 333.sh
[root@localhost project1]# git init                                              #初始化
[root@localhost project1]# git remote add origin git@localhost:root/project1.git #远程添加服务器
[root@localhost project1]# git add .                                             #追加当前目录
[root@localhost project1]# git commit -m 'Pakho 2021-6-8'                        #提交上传说明
[root@localhost project1]# git push -u origin master                             #向服务器上传

在这里插入图片描述

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

611#

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值