版本控制 gitlab 安装部署流程及其常用管理操作

本文详细介绍了GitLab的简介、功能(包括代码仓库管理、项目管理、CI/CD集成和代码审查)、部署步骤,以及gitlab的管理操作,如创建项目和配置。重点涵盖了安装过程中的常见问题及其解决方案。
摘要由CSDN通过智能技术生成

gitlab 简介与功能说明

1.简介:

GitLab 是一个强大的开源版本控制工具,它提供了完整的代码管理平台,使团队能够轻松地协作开发和管理项目。无论是小型团队还是大型企业,GitLab 都可以为开发者和项目经理提供强大的工具和功能,提高团队的协作效率和项目的质量。

2.功能说明:

  1. 代码仓库管理:
    • GitLab 提供了易于使用的界面来管理 Git 代码仓库。团队成员可以方便地创建、克隆和推送代码,以及管理分支和合并请求。
  2. 项目管理:
    • GitLab 提供了完整的项目管理功能,包括任务追踪、需求管理和项目计划等。团队可以轻松地创建和分配任务,并跟踪任务的进度和状态。
  3. CI/CD 集成:
    • GitLab 集成了持续集成和持续交付的功能,使开发团队能够自动化构建、测试和部署应用程序。借助 GitLab 提供的 CI/CD 工具,团队可以更快地交付高质量的代码。
  4. 代码审查:
    • GitLab 提供了代码审查功能,团队可以轻松地进行代码审查,发现潜在的问题并改进代码质量。通过审查合并请求和提供反馈意见,团队成员可以共同改进代码。
  5. 社区和合作:
    • GitLab 是一个充满活力的开源项目,拥有庞大的社区支持和贡献。开发者可以通过 GitLab 平台与其他人协作,共同解决问题、改进代码和分享经验。

3.gitlab部署

//永久关闭防火墙和selinux
[root@note1 ~]# systemctl disable --now firewalld.service 
Removed /etc/systemd/system/multi-user.target.wants/firewalld.service.
Removed /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service.
[root@note1 ~]# setenforce 0
[root@note1 ~]# getenforce
Disabled

//配置yum源
[root@note1 ~]# cd /etc/yum.repos.d/
[root@note1 yum.repos.d]# curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-vault-8.5.2111.repo
[root@note1 yum.repos.d]# sed -i 's/\$releasever/8/g' /etc/yum.repos.d/CentOS-Base.repo
[root@note1 yum.repos.d]# sed -i 's/^enabled=.*/enabled=1/g' /etc/yum.repos.d/CentOS-Base.repo
[root@note1 yum.repos.d]# yum -y install epel-release
安装步骤略 . . .

//建立源数据
[root@note1 yum.repos.d]# yum makecache

//安装git
[root@note1 yum.repos.d]# yum -y install git

//安装依赖包
[root@note1 yum.repos.d]# yum -y install curl openssh-server openssh-clients postfix cronie policycoreutils-python perl
安装步骤略 . . .

//上述安装依赖包成功则不需要进行这一步,上述出现错误可查看排错报告
[root@note1 yum.repos.d]# rpm -ivh --nodeps policycoreutils-python-2.5-34.el7.x86_64.rpm 
warning: policycoreutils-python-2.5-34.el7.x86_64.rpm: Header V3 RSA/SHA256 Signature, key ID f4a80eb5: NOKEY
Verifying...                          ################################# [100%]
Preparing...                          ################################# [100%]
Updating / installing...
   1:policycoreutils-python-2.5-34.el7################################# [100%]
   
//启动postfix服务并设置开机自启
[root@note1 ~]# systemctl enable --now postfix.service 
Created symlink /etc/systemd/system/multi-user.target.wants/postfix.service → /usr/lib/systemd/system/postfix.service.
[root@note1 ~]# ss -antl      //查看25号端口是否开启
State             Recv-Q            Send-Q                       Local Address:Port                       Peer Address:Port           
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的rpm包

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

[root@note1 ~]# wget https://mirrors.tuna.tsinghua.edu.cn/gitlab-ce/yum/el7/gitlab-ce-16.4.1-ce.0.el7.x86_64.rpm
--2023-10-07 14:50:24--  https://mirrors.tuna.tsinghua.edu.cn/gitlab-ce/yum/el7/gitlab-ce-16.4.1-ce.0.el7.x86_64.rpm
Resolving mirrors.tuna.tsinghua.edu.cn (mirrors.tuna.tsinghua.edu.cn)... 101.6.15.130, 2402:f000:1:400::2
Connecting to mirrors.tuna.tsinghua.edu.cn (mirrors.tuna.tsinghua.edu.cn)|101.6.15.130|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 1295805808 (1.2G) [application/x-redhat-package-manager]
Saving to: ‘gitlab-ce-16.4.1-ce.0.el7.x86_64.rpm’

gitlab-ce-16.4.1-ce.0.el7.x86_64. 100%[===========================================================>]   1.21G  20.3MB/s    in 81s     

2023-10-07 14:51:45 (15.2 MB/s) - ‘gitlab-ce-16.4.1-ce.0.el7.x86_64.rpm’ saved [1295805808/1295805808]

[root@note1 ~]# ls
anaconda-ks.cfg  gitlab-ce-16.4.1-ce.0.el7.x86_64.rpm
[root@note1 ~]# 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@note1 ~]# vim /etc/gitlab/gitlab.rb
[root@note1 ~]# grep '^external_url' /etc/gitlab/gitlab.rb
external_url 'http://192.168.195.133'    //将此处设为gitlab的服务器ip地址亦或域名
[root@note1 ~]# grep '8080' /etc/gitlab/gitlab.rb
 gitlab_workhorse['auth_backend'] = "http://localhost:8080"  //将两处8080端口的行取消注释
 puma['port'] = 8080 

//重载配置文件并重启gitlab
[root@note1 ~]# gitlab-ctl reconfigure
[root@note1 ~]# gitlab-ctl restart
ok: run: alertmanager: (pid 2767) 1s
ok: run: gitaly: (pid 2777) 0s
ok: run: gitlab-exporter: (pid 2793) 0s
ok: run: gitlab-kas: (pid 2806) 0s
ok: run: gitlab-workhorse: (pid 2816) 1s
ok: run: logrotate: (pid 2827) 0s
ok: run: nginx: (pid 2833) 0s
ok: run: node-exporter: (pid 2841) 1s
ok: run: postgres-exporter: (pid 2847) 0s
ok: run: postgresql: (pid 2857) 0s
ok: run: prometheus: (pid 2866) 0s
ok: run: puma: (pid 2882) 1s
ok: run: redis: (pid 2887) 0s
ok: run: redis-exporter: (pid 2895) 0s
ok: run: sidekiq: (pid 2908) 0s

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

访问gitlab的web页面
在这里插入图片描述

登录gitlab

方法一:
(仅适用于初次安装服务)
[root@note1 ~]# cd /etc/gitlab/
[root@note1 gitlab]# ls
gitlab.rb  gitlab-secrets.json  initial_root_password  trusted-certs
[root@note1 gitlab]# cat initial_root_password 
# WARNING: This value is valid only in the following conditions
#          1. If provided manually (either via `GITLAB_ROOT_PASSWORD` environment variable or via `gitlab_rails['initial_root_password']` setting in `gitlab.rb`, it was provided before database was seeded for the first time (usually, the first reconfigure run).
#          2. Password hasn't been changed manually, either via UI or via command line.
#
#          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: 0h2AiLpPTnvB921far8MtZYmL3blSz9bMms7E3xqnVs=   //此条长代码就是我们的临时密码

# NOTE: This file will be automatically deleted in the first reconfigure run after 24 hours.

在这里插入图片描述

登陆成功
在这里插入图片描述

方法二:
(没有受限范围,直接通过破解密码进行登录)
[root@note1 ~]# 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.58s ]
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 = 'redhat123'       //密码必须至少8个字符
=> "redhat123" 
irb(main):003:0> user.password_confirmation = 'redhat123'  //再次输入密码
=> "redhat123"
irb(main):004:0> user.save!  //保存修改,若无问题将返回true
=> true
irb(main):005:0> exit   //退出

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

配置完成

4.gitlab管理

4.1gitlab的常用管理操作

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

测试

//git全局配置
[root@note1 ~]# git config --global user.name "root"
[root@note1 ~]# git config --global user.email "123@456.com"

//将我们创建好了的仓库克隆一份
[root@note1 ~]# git clone http://192.168.195.133/root/redhat.git
Cloning into 'redhat'...
Username for 'http://192.168.195.133': root
Password for 'http://root@192.168.195.133': 
warning: You appear to have cloned an empty repository.   //此报文说我们克隆的是一个空库
[root@note1 ~]# ls
anaconda-ks.cfg  gitlab-ce-16.4.1-ce.0.el7.x86_64.rpm  redhat
[root@note1 ~]# cd redhat/
[root@note1 redhat]# git switch --create main    //创建一个主分支,并且进入该分支
Switched to a new branch 'main'
[root@note1 redhat]# echo "hello world" > test    //向库中写入内容
[root@note1 redhat]# git add test           //使用git add添加这个文件
[root@note1 redhat]# git commit -m "first commit"   //提交信息
[main (root-commit) 73291f9] first commit
 1 file changed, 1 insertion(+)
 create mode 100644 test
[root@note1 redhat]# git push --set-upstream origin main  //上传文件
Username for 'http://192.168.195.133': root
Password for 'http://root@192.168.195.133':            //此处为我们登录gitlab的密码redhat123
Enumerating objects: 3, done.
Counting objects: 100% (3/3), done.
Writing objects: 100% (3/3), 205 bytes | 205.00 KiB/s, done.
Total 3 (delta 0), reused 0 (delta 0), pack-reused 0
To http://192.168.195.133/root/redhat.git
 * [new branch]      main -> main
Branch 'main' set up to track remote branch 'main' from 'origin'.

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

上传文件
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

创建组
在这里插入图片描述
在这里插入图片描述

新建用户
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

将用户加入到组
在这里插入图片描述
在这里插入图片描述
将用户加入到项目里面去
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

登出root用户后以tom用户身份进入
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

错误排查报告

问题一

//出现一下问题,表示我们的源中没有policycoreutils-python这个软件包
[root@note1 yum.repos.d]# yum -y install curl openssh-server openssh-clients postfix cronie policycoreutils-python
Updating Subscription Management repositories.
Unable to read consumer identity
This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register.
Last metadata expiration check: 0:02:46 ago on Sat 07 Oct 2023 02:11:07 PM CST.
Package curl-7.61.1-12.el8.x86_64 is already installed.
Package openssh-server-8.0p1-4.el8_1.x86_64 is already installed.
Package openssh-clients-8.0p1-4.el8_1.x86_64 is already installed.
Package cronie-1.5.2-4.el8.x86_64 is already installed.
No match for argument: policycoreutils-python
Error: Unable to find a match: policycoreutils-python

解决方法:
在https://pkgs.org/这个网站中下载这个包
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

上传过去后使用rpm的方式安装即可:

[root@note1 yum.repos.d]# rpm -ivh --nodeps policycoreutils-python-2.5-34.el7.x86_64.rpm 
warning: policycoreutils-python-2.5-34.el7.x86_64.rpm: Header V3 RSA/SHA256 Signature, key ID f4a80eb5: NOKEY
Verifying...                          ################################# [100%]
Preparing...                          ################################# [100%]
Updating / installing...
   1:policycoreutils-python-2.5-34.el7################################# [100%]

问题二

//若出现下列错误,则表示文件/usr/share/man/ru/man8/semodule_package.8.gz从安装policycoretils -python-2.5-34.el7。X86_64与包policycoretils -2.9-9.el8. X86_64中的文件冲突

[root@note1 yum.repos.d]# rpm -ivh --nodeps policycoreutils-python-2.5-34.el7.x86_64.rpm 
warning: policycoreutils-python-2.5-34.el7.x86_64.rpm: Header V3 RSA/SHA256 Signature, key ID f4a80eb5: NOKEY
Verifying...                          ################################# [100%]
Preparing...                          ################################# [100%]
	file /usr/bin/semodule_package from install of policycoreutils-python-2.5-34.el7.x86_64 conflicts with file from package policycoreutils-2.9-9.el8.x86_64
	file /usr/share/man/ru/man8/semodule_package.8.gz from install of policycoreutils-python-2.5-34.el7.x86_64 conflicts with file from package policycoreutils-2.9-9.el8.x86_64
	
//解决方法
[root@note1 yum.repos.d]# rpm -e policycoreutils-2.9-9.el8.x86_64

总结:
GitLab 是一个功能强大的开源版本控制工具,提供了完整的代码管理平台和强大的协作功能。无论是个人开发者还是企业团队,都可以借助 GitLab 提高开发效率、改善代码质量和加强团队协作。

  • 5
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值