GitLab

一、描述

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

gitlab安装:https://about.gitlab.com/install/#centos-7

二、实现的原理

其实gitlab的原理就是git的原理,GitHub不是也是基于Git的呀,所有简单说一下Git的原理吧

img

上面的就是整个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到远程仓库来共享

下面这张图很明确的表现了他们的关系

img

三、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的优点

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

五、安装配置gitlab

5.1. 安装依赖包

sudo yum install -y curl policycoreutils-python openssh-server perl

5.2. 启动postfix,并设置开机自启

systemctl start postfix ; systemctl enable postfix

5.3. 设置防火墙

firewall-cmd --add-service=http --permanent
firewall-cmd --reload
 
或者
关闭防火墙
systemctl stop firewalld.service 
systemctl disable firewalld.service 

5.4. 下载安装gitlab rpm包

清华开源镜像站 :https://mirrors.tuna.tsinghua.edu.cn/

wget https://mirrors.tuna.tsinghua.edu.cn/gitlab-ce/yum/el7/gitlab-ce-14.0.5-ce.0.el7.x86_64.rpm
yum -y install gitlab-ce-14.0.5-ce.0.el7.x86_64.rpm

5.5. 修改配置文件gitlab.rb

[root@gitlab ~]# cat /etc/hosts
127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6
192.168.31.150 git.gitlab.c

[root@gitlab ~]# vim /etc/gitlab/gitlab.rb
......
external_url 'http://git.gitlab.com'
......

5.6. 重新加载配置文件

gitlab-ctl reconfigure
gitlab-ctl restart

5.7. 查看gitlab版本

head -1 /opt/gitlab/version-manifest.txt

5.8. 测试

http://192.168.31.150/users/sign_in

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-DTqzshpZ-1627474472533)(C:\Users\罗小波\AppData\Roaming\Typora\typora-user-images\image-20210713205715531.png)]

5.9重置管理员的密码

由于 root 账户用的很少,所以我们容易忘记它的密码,但不代表它不重要,类似 linux 的 root 账户;一旦我们忘记了 root 账号的密码,我们需要知道重置的方法,方法如下

1、进入 GitLab 控制台

[root@gitlab ~]# cd /opt/gitlab/bin/

[root@gitlab bin]# sudo gitlab-rails console -e production 

GitLab 版本不同,命令会有所不同(网上说的而基本都是gitlab-rails console production ),推荐大家直接上 GitLab 官网去找对应版本的命令
我测是使用gitlab-rails console production是进不去GitLab 控制台的

[root@gitlab bin]# sudo gitlab-rails console production
Traceback (most recent call last):
        8: from bin/rails:4:in `<main>'
        7: from bin/rails:4:in `require'
        6: from /opt/gitlab/embedded/lib/ruby/gems/2.7.0/gems/railties-6.1.3.2/lib/rails/commands.rb:18:in `<top (required)>'
        5: from /opt/gitlab/embedded/lib/ruby/gems/2.7.0/gems/railties-6.1.3.2/lib/rails/command.rb:50:in `invoke'
        4: from /opt/gitlab/embedded/lib/ruby/gems/2.7.0/gems/railties-6.1.3.2/lib/rails/command/base.rb:69:in `perform'
        3: from /opt/gitlab/embedded/lib/ruby/gems/2.7.0/gems/thor-1.1.0/lib/thor.rb:392:in `dispatch'
        2: from /opt/gitlab/embedded/lib/ruby/gems/2.7.0/gems/thor-1.1.0/lib/thor/invocation.rb:127:in `invoke_command'
        1: from /opt/gitlab/embedded/lib/ruby/gems/2.7.0/gems/thor-1.1.0/lib/thor/command.rb:27:in `run'
/opt/gitlab/embedded/lib/ruby/gems/2.7.0/gems/railties-6.1.3.2/lib/rails/commands/console/console_command.rb:95:in `perform': wrong number of arguments (given 1, expected 0) (ArgumentError)
        9: from bin/rails:4:in `<main>'
        8: from bin/rails:4:in `require'
        7: from /opt/gitlab/embedded/lib/ruby/gems/2.7.0/gems/railties-6.1.3.2/lib/rails/commands.rb:18:in `<top (required)>'
        6: from /opt/gitlab/embedded/lib/ruby/gems/2.7.0/gems/railties-6.1.3.2/lib/rails/command.rb:50:in `invoke'
        5: from /opt/gitlab/embedded/lib/ruby/gems/2.7.0/gems/railties-6.1.3.2/lib/rails/command/base.rb:69:in `perform'
        4: from /opt/gitlab/embedded/lib/ruby/gems/2.7.0/gems/thor-1.1.0/lib/thor.rb:392:in `dispatch'
        3: from /opt/gitlab/embedded/lib/ruby/gems/2.7.0/gems/thor-1.1.0/lib/thor/invocation.rb:127:in `invoke_command'
        2: from /opt/gitlab/embedded/lib/ruby/gems/2.7.0/gems/thor-1.1.0/lib/thor/command.rb:20:in `run'
        1: from /opt/gitlab/embedded/lib/ruby/gems/2.7.0/gems/thor-1.1.0/lib/thor/command.rb:34:in `rescue in run'
/opt/gitlab/embedded/lib/ruby/gems/2.7.0/gems/thor-1.1.0/lib/thor/base.rb:525:in `handle_argument_error': ERROR: "rails console" was called with arguments ["production"] (Thor::InvocationError)
Usage: "rails console [options]"

当出现如下信息表示我们成功登入控制台

[root@gitlab bin]# sudo gitlab-rails console -e production
--------------------------------------------------------------------------------
 Ruby:         ruby 2.7.2p137 (2020-10-01 revision 5445e04352) [x86_64-linux]
 GitLab:       14.0.5 (25fc1060aff) FOSS
 GitLab Shell: 13.19.0
 PostgreSQL:   12.6
--------------------------------------------------------------------------------
Loading production environment (Rails 6.1.3.2)
irb(main):001:0>

执行命令: user = User.where(id: 1).first,此 user 则表示 root 用户

3、修改密码

执行命令:user.password = 'secret_pass’修改密码, user.password_confirmation = ‘secret_pass’ 确认密码

4、保存密码

执行命令: user.save!

5、退出控制台

执行命令: exit

完整过程类似如下:

[root@gitlab bin]# sudo gitlab-rails console -e production
--------------------------------------------------------------------------------
 Ruby:         ruby 2.7.2p137 (2020-10-01 revision 5445e04352) [x86_64-linux]
 GitLab:       14.0.5 (25fc1060aff) FOSS
 GitLab Shell: 13.19.0
 PostgreSQL:   12.6
--------------------------------------------------------------------------------
Loading production environment (Rails 6.1.3.2)
irb(main):001:0>  user = User.where(id: 1).first
=> #<User id:1 @root>
irb(main):002:0> user.password = '12345678'
=> "12345678"
irb(main):003:0> user.password_confirmation = '12345678'
=> "12345678"
irb(main):004:0>  user.save!
Enqueued ActionMailer::MailDeliveryJob (Job ID: f541a39e-274e-4f1c-8c04-157a4e933b93) to Sidekiq(mailers) with arguments: "DeviseMailer", "password_change", "deliver_now", {:args=>[#<GlobalID:0x00007f8890503370 @uri=#<URI::GID gid://gitlab/User/1>>]}
=> true
irb(main):005:0> exit

重制其他用户密码:

#1.登陆控制台
root@gitlab:/# gitlab-rails console -e production
Loading production environment (Rails 4.2.10)

#2.通过邮箱找到用户
irb(main):003:0> user=User.where(email:'jenkins@domian.com').first
=> #<User id:12 @jenkins>
#3.重置密码并保存
irb(main):005:0> user.password=12345678
=> 12345678
irb(main):006:0> user.password_confirmation=12345678
=> 12345678
irb(main):007:0> user.save!
Enqueued ActionMailer::DeliveryJob (Job ID: 53d8c7ea-c523-43a1-a5e6-032c836f4870) to Sidekiq(mailers) with arguments: "DeviseMailer", "password_change", "deliver_now", gid://gitlab/User/22
=> true

完整过程类似如下:
在这里插入图片描述

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

这货有点懒!!

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

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

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

打赏作者

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

抵扣说明:

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

余额充值