GitLab版本控制

GitLab版本控制

一、GitLab介绍

GitLab是一个基于Git的开源代码托管平台,它提供了团队协作、项目管理和持续集成/持续部署等功能。以下是GitLab版本控制的简介和优点:

  1. 分布式版本控制:GitLab使用分布式版本控制系统Git作为底层技术。与集中式版本控制系统相比,分布式系统具有更好的性能和灵活性。每个开发者都可以在本地拥有完整的代码仓库,可以在离线状态下进行代码修改和提交,更加方便地合并和管理代码。

  2. 代码托管和协作:GitLab允许开发者将代码托管在云端服务器上,团队成员可以很容易地共享和访问代码库。GitLab提供了强大的协作工具,包括代码审核、问题跟踪、Wiki文档、讨论论坛等,帮助团队成员更好地协同工作。

  3. 强大的分支管理:GitLab提供了灵活的分支管理功能,允许开发者创建和合并分支,轻松处理不同的特性和修复分支。分支管理功能使得团队可以并行开发不同的功能,无需担心互相影响。

  4. 持续集成/持续部署:GitLab内置了持续集成和持续部署功能,可以自动化构建、测试和部署代码。它支持多种编程语言和测试框架,可以根据代码提交自动执行各种测试和构建任务,提高开发效率和质量。

  5. 安全性和权限控制:GitLab提供了强大的安全性和权限控制功能,可以对代码库、分支和用户权限进行细粒度的管理。管理员可以设置访问权限、审核流程和安全策略,保护代码和敏感信息的安全。

总的来说,GitLab是一个功能全面且易于使用的版本控制平台,适用于个人开发者和大型团队。它具有分布式版本控制、协作工具、分支管理、持续集成/持续部署和安全性等优点,可以提高团队的开发效率和代码质量。

常用的版本控制工具:

  • gitlab
  • subversion

二、GitLab部署

环境
操作系统gitlab版本
centos-8.2gitlab-ce-16.4.1

前期准备
//永久关闭防火墙
[root@wanf ~]# systemctl stop firewalld.service 
[root@wanf ~]# systemctl disable firewalld.service 
Removed /etc/systemd/system/multi-user.target.wants/firewalld.service.
Removed /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service.

//永久关闭selinux
[root@wanf ~]# setenforce 0
[root@wanf ~]# vi /etc/selinux/config 
[root@wanf ~]# cat /etc/selinux/config 

# This file controls the state of SELinux on the system.
# SELINUX= can take one of these three values:
#     enforcing - SELinux security policy is enforced.
#     permissive - SELinux prints warnings instead of enforcing.
#     disabled - No SELinux policy is loaded.
SELINUX=disabled                 //改为disabled
# SELINUXTYPE= can take one of these three values:
#     targeted - Targeted processes are protected,
#     minimum - Modification of targeted policy. Only selected processes are protected. 
#     mls - Multi Level Security protection.
SELINUXTYPE=targeted
[root@wanf ~]# 

//重启主机
[root@wanf ~]# reboot 

1.配置yum源

准备阿里云的yum源和epel源

//清除自带源
[root@wanf ~]# rm -rf /etc/yum.repos.d/
[root@wanf ~]# yum clean all

//获取阿里云源
[root@wanf ~]# curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-vault-8.5.2111.repo

[root@wanf ~]# sed -i -e '/mirrors.cloud.aliyuncs.com/d' -e '/mirrors.aliyuncs.com/d' /etc/yum.repos.d/CentOS-Base.repo

//获取epel源
[root@wanf ~]# yum install -y https://mirrors.aliyun.com/epel/epel-release-latest-8.noarch.rpm

[root@wanf ~]# sed -i 's|^#baseurl=https://download.example/pub|baseurl=https://mirrors.aliyun.com|' /etc/yum.repos.d/epel*
[root@wanf ~]# sed -i 's|^metalink|#metalink|' /etc/yum.repos.d/epel*

//建立缓存
[root@wanf ~]# yum makecache 

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

//启动postfix并设置开机自启
[root@wanf ~]# systemctl start postfix
[root@wanf ~]# systemctl enable postfix
Created symlink /etc/systemd/system/multi-user.target.wants/postfix.service → /usr/lib/systemd/system/postfix.service.
[root@wanf ~]# 

//下载并安装policycoreutils-python
[root@wanf ~]# wget http://mirror.centos.org/centos/7/os/x86_64/Packages/policycoreutils-python-2.5-34.el7.x86_64.rpm

[root@wanf ~]# rpm -ivh --nodeps policycoreutils-python-2.5-34.el7.x86_64.rpm --force 


//下载gitlab软件包
[root@wanf ~]# wget https://mirrors.tuna.tsinghua.edu.cn/gitlab-ce/yum/el7/gitlab-ce-16.4.1-ce.0.el7.x86_64.rpm

[root@wanf ~]# 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!
(看见这个狐狸标志就代表安装成功)

3.修改配置文件
//修改 /etc/gitlab/gitlab.rb 的第32行、1011行、1115行
[root@wanf ~]# vim /etc/gitlab/gitlab.rb 
##! https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/instancedata-data-retrieval.html
external_url 'http://192.168.179.100'   //改成自己主机的域名或ip

## Roles for multi-instance GitLab
(省略)
# gitlab_workhorse['listen_addr'] = "/var/opt/gitlab/gitlab-workhorse/sockets/socket"
  gitlab_workhorse['auth_backend'] = "http://localhost:8080"   //取消注释

##! Enable Redis keywatcher, if this setting is not present it defaults to true
(省略)
# puma['listen'] = '127.0.0.1'
  puma['port'] = 8080     //取消注释
# puma['socket'] = '/var/opt/gitlab/gitlab-rails/sockets/gitlab.socket'
(省略)


//重载配置文件
[root@wanf ~]# gitlab-ctl reconfigure
(过程省略)

//重启gitlab
[root@wanf ~]# gitlab-ctl restart
ok: run: alertmanager: (pid 21903) 0s
ok: run: gitaly: (pid 21913) 0s
ok: run: gitlab-exporter: (pid 21930) 1s
ok: run: gitlab-kas: (pid 21943) 0s
ok: run: gitlab-workhorse: (pid 21953) 0s
ok: run: logrotate: (pid 21971) 1s
ok: run: nginx: (pid 21977) 0s
ok: run: node-exporter: (pid 21985) 1s
ok: run: postgres-exporter: (pid 21991) 0s
ok: run: postgresql: (pid 22001) 0s
ok: run: prometheus: (pid 22010) 1s
ok: run: puma: (pid 22027) 0s
ok: run: redis: (pid 22032) 1s
ok: run: redis-exporter: (pid 22039) 0s
ok: run: sidekiq: (pid 22048) 1s
[root@wanf ~]# 


//查看各端口号
[root@wanf ~]# ss -anlt
State   Recv-Q  Send-Q    Local Address:Port     Peer Address:Port  Process  
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           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                  *:9094                *:*              
LISTEN  0       128               [::1]:9168             [::]:*              
LISTEN  0       128                [::]:22               [::]:*              
LISTEN  0       100               [::1]:25               [::]:*              
[root@wanf ~]# 

4.破解管理员密码

访问web页面时要输入管理员账号和密码

安装完gitlab后会生成一个文件,里面有一个初始密码,但是这个密码会在24小时后自动删除。万一你没有及时使用初始密码登录并修改密码,就只能使用破解密码的方式

//存放初始密码的文件
[root@wanf ~]# cd /etc/gitlab/
[root@wanf gitlab]# ls
gitlab.rb  gitlab-secrets.json  initial_root_password  trusted-certs
[root@wanf 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: u4pEzBsWT2fQmHDN0HO9wq7tPik1S/hslc5fyYbc7Ew=        //这是初始密码

# NOTE: This file will be automatically deleted in the first reconfigure run after 24 hours.
[root@wanf gitlab]# 
//破解密码过程
[root@wanf ~]# 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 18.81s ]
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 = 'lcwanf001'      //设置密码
=> "lcwanf001"
irb(main):003:0> user.password_confirmation = 'lcwanf001'   //确定密码
=> "lcwanf001"
irb(main):004:0> user.save!            //保存用户
=> true
irb(main):005:0> exit          //退出
[root@wanf ~]# 

5.访问web页面

通过在第3步配置文件里面的域名访问web页面

在这里插入图片描述

在这里插入图片描述

成功登入主页


6.GitLab管理
6.1 创建项目

在这里插入图片描述

在这里插入图片描述

在这里插入图片描述

在这里插入图片描述

在这里插入图片描述

创建完毕

在这里插入图片描述

这些是自动生成的用法教程,在Linux主机的命令行中使用的


6.2 创建组

在这里插入图片描述

在这里插入图片描述

在这里插入图片描述

在这里插入图片描述

成功创建一个组


6.3 创建用户

在这里插入图片描述

在这里插入图片描述

设置密码

在这里插入图片描述

在这里插入图片描述

将用户加入组

在这里插入图片描述

在这里插入图片描述

在这里插入图片描述

在这里插入图片描述

在这里插入图片描述

邀请进入组成功


6.4 上传文件
//全局设置
[root@wanf ~]# git config --global user.name "root"
[root@wanf ~]# git config --global user.email "12345678@qq.com"

//克隆项目到本机
[root@wanf ~]# git clone http://192.168.179.100/root/wanf.git
Cloning into 'wanf'...
Username for 'http://192.168.179.100': root    //输入用户名
Password for 'http://root@192.168.179.100':    //输入密码
warning: You appear to have cloned an empty repository.
[root@wanf ~]# ls
wanf

//进入项目目录
[root@wanf ~]# cd wanf/

//创建一个主分支
[root@wanf wanf]# git switch --create main
Switched to a new branch 'main'

//创建测试文件
[root@wanf wanf]# echo "123" > test
[root@wanf wanf]# ls
test

//添加文件
[root@wanf wanf]# git add test 

//提交文件
[root@wanf wanf]# git commit -m "this is a test"
[main (root-commit) 63aaa8b] this is a test
 1 file changed, 1 insertion(+)
 create mode 100644 test
[root@wanf wanf]# 

//上传文件
[root@wanf wanf]# git push --set-upstream origin main
Username for 'http://192.168.179.100': root   //输入用户名
Password for 'http://root@192.168.179.100':   //输入密码
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.179.100/root/wanf.git
 * [new branch]      main -> main
Branch 'main' set up to track remote branch 'main' from 'origin'.
[root@wanf wanf]# 

在这里插入图片描述

在这里插入图片描述

上传文件成功


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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

LcWanf

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

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

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

打赏作者

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

抵扣说明:

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

余额充值