版本控制gitlab

版本控制gitlab

git官网

gitlab官网:https://about.gitlab.com/

gitlab安装:https://gitlab.cn/install/

实现的原理

img

上面的就是整个Git的工作流程

gitlab的原理就是git的原理

git的工作流程

  1. Remote:远程仓库
  2. Repository:本地仓库
  3. index:暂存区
  4. workspace:工作区
Remote远程仓库:

远程仓库的内容可能被分布在多个地点的处于协作关系的本地仓库修改,因此它可能与本地仓库同步,也可能不同步,但是它的内容是最旧的<br>


Repository本地仓库:

这里面保存了对象被提交过的各个版本,比起工作区和暂存区的内容,它更旧一些

git commit 后同步index的目录树到本地仓库,方便下一步通过git push同步本地仓库与远程仓库的同步<br>


index暂存区:

.git目录下的index文件,暂存区会记录git add 添加文件的相关信息(文件名、大小),不保存文件实体,通过id指向每个文件的实体,可以使用git status查看暂存区的状态,暂存区标记了你当前工作区中那些内容是被git管理的

当你完成某个需求或者功能后需要提交代码,那么第一步就是通过git add 先提交到暂存区,被git管理<br>


workspace工作区:

程序员进行开发改动的地方,是你当前看到的,内容也是最新的

平常我们开发就是拷贝远程仓库中的分支,基于该分支进行开发,在开发的过程就是在工作区的操作<br>


总结:

任何对象都是在工作区中诞生和修改的

任何修改都是从进入index区才开始被版本控制的

只有把修改的代码提交到本地仓库,该修改才能在仓库中留下痕迹

与协助者分享本地的修改,可以push到远程仓库来共享


gitlab的服务构成

Gitlab有好多个东西一起构成的,分别是:

  1. Nginx:静态Web服务器
  2. gitlab-shell:用于处理Git命令和修改authorized keys列表
  3. gitlab-workhorse:轻量级的反向代理服务器(这个是个敏捷的反向代理,它会处理一些大的HTTP请求,比如文件的上传下载,其他的请求会反向代理给Gitlab Rails应用)
  4. logrotate:日志文件管理工具
  5. postgresql:数据库
  6. redis:缓存数据库
  7. sidekiq:用于在后台执行队列的任务
  8. unicorn:Gitlab Rails应用是托管在这个服务器上面的

gitlab的优点

  • git是分布式的,svn不是
    git分布式本地就可以用,可以随便保存各种历史痕迹,不用担心污染服务器,连不上服务器也能提交代码、查看log。
  • GIT分支和SVN的分支不同
    分支在SVN中实际上是版本库中的一份copy,而git一个仓库是一个快照,所以git 切换、合并分支等操作更快速。
  • git有一个强大的代码仓库管理系统 - gitlab
    可以很方便的管理权限、代码review,创建、管理project

代码管理、版本控制的软件

  • github
  • gitee
  • gitlab
  • subversion(svn)

本文使用的是gitlab,在清华大学镜像源里面找的安装包

gitlab的安装包:

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

gitlab部署

#安装git和依赖包
[root@localhost ~]# dnf -y install git curl openssh-server openssh-clients postfix cronie 
Failed to set locale, defaulting to C.UTF-8
Last metadata expiration check: 0:00:54 ago on Thu Sep 22 19:03:55 2022.
Package curl-7.61.1-22.el8.x86_64 is already installed.
Package openssh-server-8.0p1-12.el8.x86_64 is already installed.
Package openssh-clients-8.0p1-12.el8.x86_64 is already installed.
Package cronie-1.5.2-6.el8.x86_64 is already installed.
Dependencies resolved.
 perl-threads-shared-1.58-2.el8.x86_64                                                          
  postfix-2:3.5.8-3.el8.x86_64                                                                   

Complete!


#下载gitlab包
[root@localhost ~]# wget https://mirror.tuna.tsinghua.edu.cn/gitlab-ce/yum/el7/gitlab-ce-15.3.3-ce.0.el7.x86_64.rpm
--2022-09-22 19:07:08--  https://mirror.tuna.tsinghua.edu.cn/gitlab-ce/yum/el7/gitlab-ce-15.3.3-ce.0.el7.x86_64.rpm
gitlab-ce-15.3.3-ce.0.el 100%[===============================>]   1.03G  2.03MB/s    in 8m 17s  

2022-09-22 19:15:25 (2.11 MB/s) - 'gitlab-ce-15.3.3-ce.0.el7.x86_64.rpm' saved [1101649012/1101649012]



[root@localhost ~]# rpm -qa|grep policy
policycoreutils-2.9-18.el8.x86_64
selinux-policy-3.14.3-89.el8.noarch
policycoreutils-python-utils-2.9-18.el8.noarch *
selinux-policy-targeted-3.14.3-89.el8.noarch
python3-policycoreutils-2.9-18.el8.noarch *
checkpolicy-2.9-1.el8.x86_64 *
带*的需要删掉,rpm -e 软件包名 删除不掉可以加 --nodeps


#安装policycoreutils-python这个包
[root@localhost ~]# 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/audit2allow from install of policycoreutils-python-2.5-34.el7.x86_64 con
        
        


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



#修改配置文件
[root@localhost ~]# vim /etc/gitlab/gitlab.rb 
 
external_url 'http://'192.168.17.133'   //修改此处为本机ip或域名
 
#重载配置文件并重启gitlab
[root@localhost ~]# gitlab-ctl reconfigure
…………
[root@localhost ~]# gitlab-ctl start
ok: run: alertmanager: (pid 250988) 1s
ok: run: gitaly: (pid 250998) 0s
ok: run: gitlab-exporter: (pid 251018) 1s
ok: run: gitlab-kas: (pid 251043) 0s
ok: run: gitlab-workhorse: (pid 251053) 0s
ok: run: logrotate: (pid 251088) 1s
ok: run: nginx: (pid 251126) 0s
ok: run: node-exporter: (pid 251160) 1s
ok: run: postgres-exporter: (pid 251168) 0s
ok: run: postgresql: (pid 251175) 1s
ok: run: prometheus: (pid 251208) 0s
ok: run: puma: (pid 251294) 0s
ok: run: redis: (pid 251323) 1s
ok: run: redis-exporter: (pid 251361) 0s
ok: run: sidekiq: (pid 251368) 1s
 
 
#查看当前的gitlab版本
[root@localhost ~]# head -1 /opt/gitlab/version-manifest.txt
gitlab-ce 15.3.3
 
#破解管理员密码
[root@localhost ~]# gitlab-rails console -e production
--------------------------------------------------------------------------------
 Ruby:         ruby 2.7.5p203 (2021-11-24 revision f69aeb8314) [x86_64-linux]
 GitLab:       15.3.3 (c629a47f87f) FOSS
 GitLab Shell: 14.10.0
 PostgreSQL:   13.6
------------------------------------------------------------[ booted in 17.09s ]
Loading production environment (Rails 6.1.6.1)
irb(main):001:0> user = User.where(id: 1).first		
=> #<User id:1 @root>
irb(main):002:0> user.password = 'yqz333333'		#密码必须至少8个字符
=> 'yqz333333'
irb(main):003:0> user.password_confirmation = 'yqz333333'
=> 'yqz333333'
irb(main):004:0> user.save! 				#保存修改,若无问题将返回true
=> true



#开机自启
[root@localhost ~]# which gitlab-ctl 
/usr/bin/gitlab-ctl
[root@localhost ~]# chmod +x /etc/rc.d/rc.local 
[root@localhost ~]# echo "/usr/bin/gitlab-ctl start " >> /etc/rc.d/rc.local 
[root@localhost ~]# cat /etc/rc.d/rc.local
#!/bin/bash
# THIS FILE IS ADDED FOR COMPATIBILITY PURPOSES
#
# It is highly advisable to create own systemd services or udev rules
# to run scripts during boot instead of using this file.
#
# In contrast to previous versions due to parallel execution during boot
# this script will NOT be run after all other services.
#
# Please note that you must run 'chmod +x /etc/rc.d/rc.local' to ensure
# that this script will be executed during boot.

/usr/bin/gitlab-ctl start 
touch /var/lock/subsys/local

访问页面

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

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值