版本控制gitlab

本文详细介绍了GitLab的版本控制功能、特点,如问题追踪、持续集成/部署(CI/CD)、代码审查等。并展示了如何在RHEL8系统上部署和配置GitLab,包括安装、配置、权限设置以及基本的项目管理和用户管理操作。
摘要由CSDN通过智能技术生成

版本控制gitlab

1.gitlab介绍

GitLab是一个用于软件开发的基于Web的Git仓库管理工具,它提供了代码仓库管理、问题追踪、持续集成、代码审查等一系列功能。它类似于GitHub,但是是一个完整的解决方案,可以在本地托管,也可以作为SaaS服务使用。GitLab是一个功能强大、全面的软件开发平台,能够帮助开发团队高效地进行代码管理、问题解决、持续集成等工作,提高开发效率和代码质量。
以下是GitLab的主要特点功能

  • 版本控制(Git): GitLab是建立在Git版本控制系统之上的,这意味着它支持强大的分布式版本控制功能,包括代码的提交、分支、合并等。
  • 代码托管: GitLab提供了一个可以托管代码仓库的平台,可以轻松管理项目的源代码,包括代码的提交、分支、合并等操作。
  • 问题追踪系统: GitLab内置了一个问题追踪系统,可以帮助团队跟踪和解决项目中的问题、Bug和任务。用户可以创建、分配、评论问题并进行标记和归档。
  • 持续集成(CI/CD): GitLab集成了CI/CD(持续集成/持续部署)功能,可以通过配置管道来自动构建、测试和部署代码。它支持多种编程语言和环境。
  • 合并请求和代码审查: 开发者可以创建合并请求(Merge Request),其他团队成员可以对代码进行审查和评论,确保代码质量和安全性。
  • 权限和访问控制: GitLab允许管理员设置不同用户和团队的权限,以控制对仓库和功能的访问
  • 集成和插件: GitLab可以与许多其他工具和服务集成,例如Jenkins、Slack、Jira等,以扩展其功能和增强团队的工作流程。
  • 安全功能: GitLab包括一系列安全功能,包括自动化的安全检测、漏洞扫描、容器扫描、代码安全等,以帮助保护代码和系统的安全。
  • 多项目管理: GitLab允许在单个实例上管理多个项目,每个项目可以有自己的权限和配置。
  • 自动化部署和扩展: GitLab支持自动化部署,可以将应用程序快速部署到不同的环境。它也支持水平扩展,以应对不同规模的开发团队和项目需求。

2. gitlab部署

[root@RHEL8 ~]# cd /etc/yum.repos.d/
[root@RHEL8 yum.repos.d]# ls
redhat.repo  server.repo
[root@RHEL8 yum.repos.d]# rm -rf *

//配置阿里源
[root@RHEL8 yum.repos.d]# curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-vault-8.5.2111.repo
[root@RHEL8 yum.repos.d]# sed -i -e '/mirrors.cloud.aliyuncs.com/d' -e '/mirrors.aliyuncs.com/d' /etc/yum.repos.d/CentOS-Base.repo

//安装 epel 配置包
[root@RHEL8 ~]# yum install -y https://mirrors.aliyun.com/epel/epel-release-latest-8.noarch.rpm

//将 repo 配置中的地址替换为阿里云镜像站地址
[root@RHEL8 ~]# sed -i 's|^#baseurl=https://download.example/pub|baseurl=https://mirrors.aliyun.com|' /etc/yum.repos.d/epel*
[root@RHEL8 ~]# sed -i 's|^metalink|#metalink|' /etc/yum.repos.d/epel*

//安装依赖包
[root@RHEL8 ~]# yum -y install curl openssh-server openssh-clients postfix cronie git perl

//启动postfix服务并设置开机自启
[root@RHEL8 ~]# systemctl enable --now postfix
[root@RHEL8 ~]# ss -antl    //25端口已开启
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            [::]:*  

[root@RHEL8 ~]# wget https://mirrors.tuna.tsinghua.edu.cn/gitlab-ce/yum/el7/gitlab-ce-16.4.1-ce.0.el7.x86_64.rpm
[root@RHEL8 ~]# wget http://mirror.centos.org/centos/7/os/x86_64/Packages/policycoreutils-python-2.5-34.el7.x86_64.rpm
[root@RHEL8 ~]# ls
gitlab-ce-16.4.1-ce.0.el7.x86_64.rpm
policycoreutils-python-2.5-34.el7.x86_64.rpm
[root@RHEL8 ~]# rpm -ivh --nodeps policycoreutils-python-2.5-34.el7.x86_64.rpm 
[root@RHEL8 ~]# rpm -ivh gitlab-ce-16.4.1-ce.0.el7.x86_64.rpm
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@RHEL8 ~]# vim /etc/gitlab/gitlab.rb
......  //此处为省略内容
external_url 'http://192.168.198.131'     //将此处设为gitlab的服务器ip地址亦或域名
......  //此处为省略内容

//关闭selinux
[root@RHEL8 ~]# vim /etc/selinux/config
将SELINUX=enforcing 更改为 “disabled”

//关闭防火墙
[root@RHEL8 ~]# systemctl disable --now firewalld

//重载配置文件并重启gitlab
[root@RHEL8 ~]# gitlab-ctl reconfigure
[root@RHEL8 ~]# gitlab-ctl restart

//查看当前的gitlab版本
[root@RHEL8 ~]# head -1 /opt/gitlab/version-manifest.txt
gitlab-ce 16.4.1

[root@RHEL8 ~]# ss -antl
State  Recv-Q Send-Q Local Address:Port  Peer Address:Port Process 
LISTEN 0      128        127.0.0.1:8082       0.0.0.0:*            
LISTEN 0      1024       127.0.0.1:9236       0.0.0.0:*            
LISTEN 0      1024       127.0.0.1:8150       0.0.0.0:*            
LISTEN 0      128          0.0.0.0:22         0.0.0.0:*            
LISTEN 0      1024       127.0.0.1:8151       0.0.0.0:*            
LISTEN 0      1024       127.0.0.1:8153       0.0.0.0:*            
LISTEN 0      100        127.0.0.1:25         0.0.0.0:*            
LISTEN 0      1024       127.0.0.1:8154       0.0.0.0:*            
LISTEN 0      1024       127.0.0.1:8155       0.0.0.0:*            
LISTEN 0      128        127.0.0.1:8092       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      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:9168       0.0.0.0:*            
LISTEN 0      128             [::]:22            [::]:*            
LISTEN 0      100            [::1]:25            [::]:*            
LISTEN 0      1024               *:9094             *:*            
LISTEN 0      128            [::1]:9168          [::]:* 

已经可以进入gitlab首页(192.168.198.131)
在这里插入图片描述
密码位置

[root@RHEL8 ~]# cd /etc/gitlab/
[root@RHEL8 gitlab]# ls
gitlab.rb            initial_root_password
gitlab-secrets.json  trusted-certs
[root@RHEL8 gitlab]# vim initial_root_password 
WhSz+ZZrSn2IDlpZWZJ3t606loS4fOX1hQ/7n7SfGu0=
账号密码位置
root/etc/gitlab/initial_root_password

登陆成功

在这里插入图片描述

修改密码
在这里插入图片描述

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

如果不知道密码可以破解

//破解密码
[root@RHEL8 ~]# 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 34.66s ]
Loading production environment (Rails 7.0.6)
irb(main):001:0> user = User.where(id: 1).first
=> #<User id:1 @root>
irb(main):002:0> user.password = 'zhouwei123!'
=> "zhouwei123!"
irb(main):003:0> user.password_confirmation = 'zhouwei123!'
=> "zhouwei123!"
irb(main):004:0> user.save!
=> true
irb(main):005:0> exit

创建项目
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

[root@RHEL8 ~]# git config --global user.name "root"
[root@RHEL8 ~]# git config --global user.email "1@2.com"
[root@RHEL8 ~]# git clone http://192.168.198.131/root/xiaojing.git
Cloning into 'xiaojing'...
Username for 'http://192.168.198.131': root       
Password for 'http://root@192.168.198.131': (此处输入gitlab密码)
warning: You appear to have cloned an empty repository.
[root@RHEL8 ~]# ls
anaconda-ks.cfg
gitlab-ce-16.4.1-ce.0.el7.x86_64.rpm
policycoreutils-python-2.5-34.el7.x86_64.rpm
xiaojing
[root@RHEL8 ~]# cd xiaojing/
[root@RHEL8 xiaojing]# git switch --create main
Switched to a new branch 'main'
[root@RHEL8 xiaojing]# echo "hello world" > test
[root@RHEL8 xiaojing]# ls
test
[root@RHEL8 xiaojing]# git add test 
[root@RHEL8 xiaojing]# git commit -m "first commit"
[main (root-commit) f5ba6aa] first commit
 1 file changed, 1 insertion(+)
 create mode 100644 test
[root@RHEL8 xiaojing]# git push --set-upstream origin main
Username for 'http://192.168.198.131': root
Password for 'http://root@192.168.198.131': (此处输入gitlab密码)
Enumerating objects: 3, done.
Counting objects: 100% (3/3), done.
Writing objects: 100% (3/3), 202 bytes | 202.00 KiB/s, done.
Total 3 (delta 0), reused 0 (delta 0), pack-reused 0
To http://192.168.198.131/root/xiaojing.git
 * [new branch]      main -> main
Branch 'main' set up to track remote branch 'main' from 'origin'.

可以查看刚刚创建的文件
在这里插入图片描述
在这里插入图片描述
gitlab常用管理操作**

  • 项目管理(通常只是创建新项目)
  • 创建成员组(针对某个项目创建一个成员组)
  • 用户管理(此用户乃gitlab用户而非系统用户)
    • 来了新员工,为其添加gitlab用户
      branch ‘main’ from ‘origin’.
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

疑犯

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

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

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

打赏作者

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

抵扣说明:

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

余额充值