• gitlab服务部署及使用


    一、什么是gitlib

      Gitlab 是一个基于Git实现的在线代码仓库托管软件,你可以用Gitlab自己搭建一个类似于Github一样的系统平台,一般搭建gitlab私服就是用在公司的内部

      Gitlab 功能就是能够对代码的提交审核和问题跟踪,这个对于软件工程质量的管理是至关重要的

      Gitlab分为社区版(CE) 和 企业版(EE) 我感觉大多数的公司还是会选择社区版,反正我们公司是要用社区版的

      部署Gitlab 是对服务器有配置要求的 建议是CPU两核,内存4G以上(其实这就是废话了,谁家公司还没这样配置的服务器呀,主要还是给虚拟机玩的朋友们提示一下)

    二、实现的原理

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

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

      其实上面的都是一些GIt的命令,先不管命令是做什么的,这里面有四个大块的东西,他们分别是

    1. Remote:远程仓库
    2. Repository:本地仓库
    3. index:暂存区
    4. workspace:工作区
    Remote远程仓库:
    
    远程仓库的内容可能被分布在多个地点的处于协作关系的本地仓库修改,因此它可能与本地仓库同步,也可能不同步,但是它的内容是最旧的
    Repository本地仓库: 这里面保存了对象被提交过的各个版本,比起工作区和暂存区的内容,它更旧一些 git commit 后同步index的目录树到本地仓库,方便下一步通过git push同步本地仓库与远程仓库的同步
    index暂存区: .git目录下的index文件,暂存区会记录git add 添加文件的相关信息(文件名、大小),不保存文件实体,通过id指向每个文件的实体,可以使用git status查看暂存区的状态,暂存区标记了你当前工作区中那些内容是被git管理的 当你完成某个需求或者功能后需要提交代码,那么第一步就是通过git add 先提交到暂存区,被git管理
    workspace工作区: 程序员进行开发改动的地方,是你当前看到的,内容也是最新的 平常我们开发就是拷贝远程仓库中的分支,基于该分支进行开发,在开发的过程就是在工作区的操作
    总结: 任何对象都是在工作区中诞生和修改的 任何修改都是从进入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的优点

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

    五、安装配置gitlab

    5.1. 安装依赖包

    [root@web1134 ~]# yum install -y curl openssh-server openssh-clients postfix cronie policycoreutils-python

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

    [root@web1134 ~]# systemctl start postfix
    [root@web1134 ~]# systemctl enable postfix

    5.3. 设置防火墙

    firewall-cmd --add-service=http --permanent
    firewall-cmd --reload
    
    或者
    关闭防火墙
    systemctl stop firewalld.service #停止firewall
    
    systemctl disable firewalld.service #禁止firewall开机启动

    5.4. 下载安装gitlab rpm包

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

    [root@web1134 ~]# wget https://mirrors.tuna.tsinghua.edu.cn/gitlab-ce/yum/el7/gitlab-ce-11.1.6-ce.0.el7.x86_64.rpm
    
    [root@web1134 ~]# rpm -i gitlab-ce-11.1.6-ce.0.el7.x86_64.rpm

    5.5. 修改配置文件gitlab.rb

    ## GitLab configuration settings
    ##! This file is generated during initial installation and **is not** modified
    ##! during upgrades.
    ##! Check out the latest version of this file to know about the different
    ##! settings that can be configured by this file, which may be found at:
    ##! https://gitlab.com/gitlab-org/omnibus-gitlab/raw/master/files/gitlab-config-template/gitlab.rb.template
    
    
    ## GitLab URL
    ##! URL on which GitLab will be reachable.
    ##! For more details on configuring external_url see:
    ##! https://docs.gitlab.com/omnibus/settings/configuration.html#configuring-the-external-url-for-gitlab
    #external_url 'http://gitlab.example.com'
    external_url 'http://192.168.73.134'        # 修改这个地方

    5.6. 重新加载配置文件

    [root@web1134 ~]# gitlab-ctl reconfigure
    [root@web1134 ~]# gitlab-ctl restart
    

    5.7. 查看gitlab版本

    [root@web1134 ~]# head -1 /opt/gitlab/version-manifest.txt
    

      

    六、汉化配置

    6.1.下载最新汉化包

    [root@web1134 ~]# git clone https://gitlab.com/xhang/gitlab.git
    

      这个时间下载的挺长的

    6.2. 停止服务

    [root@web1134 ~]# gitlab-ctl stop

    6.3. 切换到gitlab汉化包所在的目录

    [root@web1134 ~]#  cd /root/gitlab

    6.4. 比较汉化标签和原标签,导出 patch 用的 diff 文件到/root下 

    [root@web1134 gitlab]# git diff v11.1.6 v11.1.6-zh > ../11.1.6-zh.diff

    6.5. 将10.0.2-zh.diff作为补丁更新到gitlab中 

    [root@web1134 gitlab]# cd ~
    [root@web1134 ~]# yum install patch -y
    [root@web1134 ~]# patch -d /opt/gitlab/embedded/service/gitlab-rails -p1 < 11.1.6-zh.diff
    
    
    # 一路回车 覆盖文件

    6.6. 启动gitlab并重新配置gitlab 

    [root@web1134 ~]# gitlab-ctl start
    [root@web1134 ~]# gitlab-ctl reconfigure

    七、设置发邮件功能

    7.1. 修改配置文件

    [root@web1134 ~]# vim /etc/gitlab/gitlab.rb
    
    修改下面信息
    # 配置发送邮箱
    
    gitlab_rails['smtp_enable'] = true
    
    gitlab_rails['smtp_address'] = "smtp.163.com"
    
    gitlab_rails['smtp_port'] = 25 
    
    gitlab_rails['smtp_user_name'] = "smtp user@163.com"
    
    gitlab_rails['smtp_password'] = "password"
    
    gitlab_rails['smtp_domain'] = "163.com"
    
    gitlab_rails['smtp_authentication'] = "login"
    
    gitlab_rails['smtp_enable_starttls_auto'] = true
    
    # 修改gitlab配置的发信人
    
    gitlab_rails['gitlab_email_from'] = "smtp user@163.com"
    
    user["git_user_email"] = "smtp user@163.com"

    7.2. 重新加载配置并重启服务

    [root@web1134 ~]# gitlab-ctl reconfigure
    [root@web1134 ~]# gitlab-ctl restart

    八、测试使用

    登录地址就是服务器IP地址 http://192.168.73.134

    用户名是root

  • 相关阅读:
    .net URL加密和解密
    全面分析VB.NET文件传送
    如何美化你的.net 应用程序 (皮肤使用)
    获取机器的硬件信息(CPU ID序列号, 主板信息,硬盘序列号,系统信息)
    这是博客园的一个Bug吗?
    [转]深入理解JavaScript闭包(closure)
    【翻译】在ASP.NET中的DatePicker控件
    [翻译]ASP.NET MVC 2 Preview 1 发布了
    页面性能优化减少HTTP请求
    [翻译]C#闭包内幕(Looking Inside C# Closures)
  • 原文地址:https://www.cnblogs.com/zhujingzhi/p/9703457.html
Copyright © 2020-2023  润新知