7.2 CI/CD 持续集成/持续交付_GitLab代码仓库

7.1 CI/CD 持续集成/持续交付_Git分布式版本控制系统

7.2 CI/CD 持续集成/持续交付_GitLab代码仓库

7.3 CI/CD 持续集成/持续交付_Jenkins整合Git 容器镜像
7.4 CI/CD 持续集成/持续交付_Jenkins部署远程仓库和企业级仓库 Jenkins实现参数化构建

2. GitLab代码仓库

2.1 GitLab安装

(官方推荐至少4G内存)
在这里插入图片描述

GitLab 官网

  1. 安装依赖性(注意这是企业7的版本)
[root@server51 demo]# yum install -y curl policycoreutils-python openssh-server	

在这里插入图片描述

  1. 安装gitlab
[root@server51 ~]# rpm -ivh gitlab-ce-13.2.2-ce.0.el7.x86_64.rpm
warning: gitlab-ce-13.2.2-ce.0.el7.x86_64.rpm: Header V4 RSA/SHA1 Signature, key ID f27eab47: NOKEY
Preparing...                          ################################# [100%]
Updating / installing...
   1:gitlab-ce-13.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

在这里插入图片描述

  1. 修改配置文件/etc/gitlab/gitlab.rb中默认的clone链接。
    更改之后,不会立即生效,需要重载服务
[root@server51 ~]# cd /etc/gitlab/
[root@server51 gitlab]# vim gitlab.rb 
external_url 'http://172.25.21.51'

在这里插入图片描述

[root@server51 gitlab]# gitlab-ctl reconfigure	

在这里插入图片描述

  1. 查看当前gitlab各组件的状态
常用命令说明
gitlab-ctl start启动所有 gitlab 组件
gitlab-ctl stop停止所有 gitlab 组件
gitlab-ctl restart重启所有 gitlab 组件
gitlab-ctl status查看服务状态
gitlab-ctl reconfigure重载服务
gitlab-ctl tail查看日志
[root@server51 gitlab]# gitlab-ctl status
run: alertmanager: (pid 5370) 27s; run: log: (pid 5150) 92s
run: gitaly: (pid 5300) 29s; run: log: (pid 4561) 224s
run: gitlab-exporter: (pid 5293) 29s; run: log: (pid 5006) 110s
run: gitlab-workhorse: (pid 5270) 30s; run: log: (pid 4901) 138s
run: grafana: (pid 5425) 26s; run: log: (pid 5239) 47s
run: logrotate: (pid 4935) 129s; run: log: (pid 4946) 125s
run: nginx: (pid 4908) 135s; run: log: (pid 4924) 132s
run: node-exporter: (pid 5280) 30s; run: log: (pid 4977) 115s
run: postgres-exporter: (pid 5418) 26s; run: log: (pid 5179) 84s
run: postgresql: (pid 4686) 214s; run: log: (pid 4697) 213s
run: prometheus: (pid 5311) 28s; run: log: (pid 5129) 98s
run: puma: (pid 4828) 153s; run: log: (pid 4840) 150s
run: redis: (pid 4515) 231s; run: log: (pid 4522) 230s
run: redis-exporter: (pid 5295) 29s; run: log: (pid 5054) 104s
run: sidekiq: (pid 4847) 147s; run: log: (pid 4861) 143s
  1. web测试
  • root用户第一次登陆GitLab需要强制更改密码(密码至少8个字符)
    在这里插入图片描述

2.2 GitLab使用

  1. 根据个人情况,修改偏好配置
  • 选择用户admin里的设置
    在这里插入图片描述
  • 选择左下方的偏好设置
    在这里插入图片描述
  • 选择中文社区
    在这里插入图片描述
  1. 新建项目
  • 先添加密钥,允许gitlab服务免密访问本地
[root@server51 gitlab]# cd
[root@server51 ~]# ssh-keygen 
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa): 
Created directory '/root/.ssh'.
Enter passphrase (empty for no passphrase): 
Enter same passphrase again: 
Your identification has been saved in /root/.ssh/id_rsa.
Your public key has been saved in /root/.ssh/id_rsa.pub.
The key fingerprint is:
SHA256:11ywMo4P1+jC6eCEUsfWEuOiuXFJmuJm5a8uIxjZcVI root@server51
The key's randomart image is:
+---[RSA 2048]----+
|            .    |
|    E        o   |
|   .  o   o . .  |
|  o .o + o B .   |
| o ++ * S = +    |
|o .O * o B       |
|o.X + o + o      |
|+* * o o .       |
|+.=oo.. .        |
+----[SHA256]-----+
[root@server51 ~]# cd .ssh/
[root@server51 .ssh]# cat id_rsa.pub 
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDpZnweu0tpEN8iJfNnE4CYaGJ8RK5R+Dfzp+jIYAW+4Ir3Pkn1EIK8p3GXYH1EtKkNnaHuEPMKoTAWkWCtWEf58LuyUEs2qCtSv39sDZOzw80vQgpByjkGD3PJrZsRIj9SFGhS+vh8xhDgAQfos1jquCLenbqz59eae/LIbd0BzrLWwGzS8TXC5q8SI6dy1dbasAeqaIpcLoV2r5s0inOHmohZIVNO+5Yy3ess4ILJdcyJ44VQiXrQu2gS2Is6DFpNIfRv4HJ+uujIKXDd/k3poaBygi5GPRu4pZx/7uD/SkHrXeBXVadyHwnFnr3VxjEzWeAqB0YLOfbNqrU5UuVP root@server51

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

  • 新建项目,同步代码库到gitlab
    在这里插入图片描述在这里插入图片描述在这里插入图片描述
  1. 项目测试
  • 删除本地demo,之后在git克隆
[root@server51 ~]# rm -fr demo/
  • 克隆远端仓库的代码到本地(注意,记得修改本地解析文件,否则,克隆会很慢)
[root@server51 ~]# vim /etc/hosts

在这里插入图片描述

[root@server51 ~]# git clone git@172.25.21.51:root/demo.git
Cloning into 'demo'...
remote: Enumerating objects: 3, done.
remote: Counting objects: 100% (3/3), done.
remote: Total 3 (delta 0), reused 0 (delta 0), pack-reused 0
Receiving objects: 100% (3/3), done.
[root@server51 ~]# cd demo/
[root@server51 demo]# ls
README.md
  • 远程信息被记录
[root@server51 demo]# git remote -v
origin	git@172.25.21.51:root/demo.git (fetch)
origin	git@172.25.21.51:root/demo.git (push)
  1. 本地数据如何向远端同步?
  • 建立一个测试文件
[root@server51 demo]# touch index.html
[root@server51 demo]# echo www.westos.org > index.html
  • 添加测试文件到暂存区,提交测试文件到代码库
[root@server51 demo]# git status -s
?? index.html
[root@server51 demo]# git add index.html
[root@server51 demo]# git commit -m "add index.html"
[master d20f0e0] add index.html
 1 file changed, 1 insertion(+)
 create mode 100644 index.html
[root@server51 demo]# git status
# On branch master
# Your branch is ahead of 'origin/master' by 1 commit.
#   (use "git push" to publish your local commits)
#
nothing to commit, working directory clean
[root@server51 demo]# git status -s
  • 上传push测试文件到gitlab
[root@server51 demo]# git push -u origin master
Counting objects: 4, done.
Delta compression using up to 2 threads.
Compressing objects: 100% (2/2), done.
Writing objects: 100% (3/3), 283 bytes | 0 bytes/s, done.
Total 3 (delta 0), reused 0 (delta 0)
To git@172.25.21.51:root/demo.git
   9e00006..d20f0e0  master -> master
Branch master set up to track remote branch master from origin.
  • web界面检验结果
    在这里插入图片描述在这里插入图片描述

在web界面可以远端图形化编辑,同步到本地

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值