zoukankan      html  css  js  c++  java
  • 版本控制与Gitlab配置

    版本控制介绍

    版本控制是指对软件开发过程中各种程序代码、配置文件及说明文档等文件变更的管理,是软件配置管理的核心思想之一。

    版本控制最主要的功能就是追踪文件的变更。它将什么时候、什么人更改了文件的什么内容等信息忠实地了记录下来。每一次文件的改变,文件的版本号都将增加.

    版本控制系统分类

    本地版本控制

    记录文件每次的更新,可以对每个版本做一个快照,或是记录补丁文件,适合个人用。

    例如RCS控制系统

    集中式版本控制

    所有的版本数据都保存在服务器上,协同开发者从服务器上同步更新或上传自己的修改
    所有的版本数据都存在服务器上,用户的本地只有自己以前所同步的版本,如果不连网
    的话,用户就看不到历史版本,也无法切换版本验证问题,或在不同分支工作。而且,所有
    数据都保存在单一的服务器上,有很大的风险这个服务器会损坏,这样就会丢失所有的数据.

    例如SVN、CVS、VSS

    分布式版本控制

    所有版本信息仓库全部同步到本地的每个用户,这样就可以在本地查看所有版本历史,
    可以离线在本地提交,只需在连网时 push 到相应的服务器或其他用户那里。

    由于每个用户那里保存的都是所有的版本数据,只要有一个用户的设备没有问题就可以恢复所有的数据.

    例如:Git

    如对Git工作原理感兴趣的同学可移步到此链接学习

    https://www.liaoxuefeng.com/wiki/896043488029600

    Gitlab

    GitLab 是一个用于仓库管理系统的开源项目,使用Git作为代码管理工具,并在此基础上搭建起来的web服务。安装方法是参考GitLab在GitHub上的Wiki页面.

    Gitlab部署

    • 配置必备源和环境
    [root@localhost ~]# yum install -y epel-release
    ......
    Installed:
      epel-release-8-8.el8.noarch    
    
    [root@localhost ~]# yum install -y git
    ......
    Complete!
    
    [root@localhost ~]# yum -y install curl openssh-server openssh-clients postfix cronie policycoreutils-python-utils
    
    # 开启邮件服务
    [root@localhost ~]# systemctl enable --now  postfix
    [root@localhost ~]# ss -antl
    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
    [root@localhost ~]# rpm -ivh gitlab-ce-13.6.0-ce.0.el8.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
    
    • 配置Gitlab配置文件
    [root@localhost ~]# vim /etc/gitlab/gitlab.rb 
    
    ......
    ##! https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/instancedata-data-retrieval.html
    external_url 'http://192.168.197.147'  serverIP改为本机IP
    .......
    
    • 重读配置文件并启动Gitlab
    [root@localhost ~]# gitlab-ctl reconfigure
    ......
    gitlab Reconfigured!
    
    ## 重启Gitlab
    [root@localhost ~]# gitlab-ctl restart
    ok: run: alertmanager: (pid 5168) 1s
    ok: run: gitaly: (pid 5180) 0s
    ok: run: gitlab-exporter: (pid 5198) 0s
    ok: run: gitlab-workhorse: (pid 5202) 0s
    ok: run: grafana: (pid 5223) 1s
    ok: run: logrotate: (pid 5236) 0s
    ok: run: nginx: (pid 5242) 1s
    ok: run: node-exporter: (pid 5250) 0s
    ok: run: postgres-exporter: (pid 5333) 1s
    ok: run: postgresql: (pid 5348) 0s
    ok: run: prometheus: (pid 5357) 1s
    ok: run: puma: (pid 5373) 0s
    ok: run: redis: (pid 5378) 1s
    ok: run: redis-exporter: (pid 5383) 0s
    ok: run: sidekiq: (pid 5395) 0s
    
    • 重置ROOT的登录密码

    • 进入web管理页

    • root账户的密码破解

    [root@localhost ~]# gitlab-rails console -e production
    --------------------------------------------------------------------------------
     Ruby:         ruby 2.7.2p137 (2020-10-01 revision 5445e04352) [x86_64-linux]
     GitLab:       13.6.0 (6317794da29) FOSS
     GitLab Shell: 13.13.0
     PostgreSQL:   11.9
    ......
    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: 26559d1c-aa40-45f7-9e62-6b1e19082974) to Sidekiq(mailers) with arguments: "DeviseMailer", "password_change", "deliver_now", {:args=>[#<GlobalID:0x00007f963a265070 @uri=#<URI::GID gid://gitlab/User/1>>]}
    => true
    
    • Git创建本地代码仓库
    ## 准备版本仓库的目录
    [root@localhost /]# mkdir codebase
    [root@localhost /]# cd codebase/
    [root@localhost codebase]# pwd
    /codebase
    
    ## 初始化此目录。使其变为本地代码仓库
    [root@localhost codebase]# git init
    Initialized empty Git repository in /codebase/.git/
    ## 初始化完整后,git会自动新建.git文件,此目录为git仓库配置文件
    [root@localhost codebase]# ls -al
    total 0
    drwxr-xr-x   3 root root  18 Nov 25 16:18 .
    dr-xr-xr-x. 18 root root 260 Nov 25 16:16 ..
    drwxr-xr-x   7 root root 119 Nov 25 16:18 .git
    
    
    • 创建文件并发送到版本仓库中
    [root@localhost codebase]# echo 'hello world' > readme.txt
    [root@localhost codebase]# ls
    readme.txt
    
    # 添加readme.txt至仓库中
    [root@localhost codebase]# git add readme.txt
    
    
    # 提交到仓库
    [root@localhost codebase]# git commit -m 'touch a new file!!!'
    [master (root-commit) 6c364f1] touch a new file!!!
    1 file changed, 1 insertion(+)
     create mode 100644 readme.txt
    
    # 查看仓库中内容
    [root@localhost codebase]# git show
    commit 6c364f18650103c3adafc54b23133cbdc2a1e1cf (HEAD -> master)
    Author: root <root@localhost.localdomain>
    Date:   Wed Nov 25 16:23:54 2020 +0800
    
        touch a new file!!!
    
    diff --git a/readme.txt b/readme.txt
    new file mode 100644
    index 0000000..3b18e51
    --- /dev/null
    +++ b/readme.txt
    @@ -0,0 +1 @@
    +hello world
    
    
    • 创建远程仓库

    • SSH密钥传输

    • 将远程仓库与本地仓库关联
    [root@localhost ~]# git config --global user.name "root"
    [root@localhost ~]# git config --global user.email "root@localhost.localdomain"
    
    
    ## 将远程库与本地仓库关联
    [root@localhost /]# cd codebase/
    [root@localhost codebase]# git remote add origin git@192.168.197.147:root/my-test-project1.git
    
    
    
    ## 将本地库的内容同步到远程库中
    [root@localhost codebase]# git push -u origin --all
    The authenticity of host '192.168.197.147 (192.168.197.147)' can't be established.
    ECDSA key fingerprint is SHA256:E2vvTufwYUblb2ScJV7+0yP8isEX8t/lwqaOp8aOiOc.
    Are you sure you want to continue connecting (yes/no/[fingerprint])? ye
    Please type 'yes', 'no' or the fingerprint: yes
    Warning: Permanently added '192.168.197.147' (ECDSA) to the list of known hosts.
    Enumerating objects: 3, done.
    Counting objects: 100% (3/3), done.
    Writing objects: 100% (3/3), 230 bytes | 230.00 KiB/s, done.
    Total 3 (delta 0), reused 0 (delta 0)
    To 192.168.197.147:root/my-test-project1.git
     * [new branch]      master -> master
    Branch 'master' set up to track remote branch 'master' from 'origin'.
    
    • 添加用户


    • 为用户附加项目权限



  • 相关阅读:
    如何把项目上传到github
    springBoot整合Mybatis为什么可以省略mybatis-config.xml
    【Mybatis源码解析】-mybatis-spring原理解析
    没有名字 [整除分块优化dp]
    替身使者 [区间dp]
    P3158 [CQOI2011]放棋子 [动态规划]
    博士之时 [分类讨论, 计数]
    曾有两次 [最短路树]
    序列 [线段树]
    城镇 [树的直径, 启发式合并]
  • 原文地址:https://www.cnblogs.com/sawyer95/p/14039182.html
Copyright © 2011-2022 走看看