Gitlab服务部署及应用

目录

Gitlab简介

Gitlab工作原理

Gitlab服务构成

Gitlab环境部署

安装依赖包

启动postfix,并设置开机自启

设置防火墙

[下载安装gitlab rpm包](#下载安装gitlab rpm包)

修改配置文件/etc/gitlab/gitlab.rb,生产环境下可以根据需求修改

重新加载配置文件

[浏览器登录Gitlab输入 http://服务器IP](#浏览器登录Gitlab输入 http://服务器IP)

打开另一台主机

设置发邮件功能


Gitlab简介

Gitlab 是一个基于Git实现的WEB代码仓库托管软件,你可以用Gitlab自己搭建一个类似于Github一样的代码仓库,一般使用gitlab搭建私有代码仓库主要是用在公司的内部代码管理。

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

Gitlab分为社区版(CE)和企业版(EE)。大多数的公司还是会选择社区版。部署Gitlab是对服务器有配置要求的建议是CPU两核,内存4G以上。

Gitlab工作原理

gitlab的原理其实就是git的工作原理,GitHub也是基于git实现的

Remote远程仓库:

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

Repository本地仓库:

这里面保存了被提交过的代码各个版本,比起工作区和暂存区的内容,它的内容会旧一些,git commit 后同步index的目录树到本地仓库,方便下一步通过git push同步本地仓库与远程仓库的同步。

index暂存区:

git目录下的index文件,暂存区会记录git add 添加文件的相关信息(文件名、大小),不保存文件实体,通过id指向每个文件的实体,可以使用git status查看暂存区的状态,暂存区标记了你当前工作区中哪些内容是被git管理的。当你完成某个需求或者功能后需要提交代码,那么第一步就是通过git add 先提交到暂存区。

workspace工作区:

程序员进行开发改动的地方,是你当前看到的,内容也是最新的。平常我们开发就是拷贝远程仓库中的分支,基于该分支进行开发,在开发的过程就是在工作区的操作。

总结:

  1. 任何对象都是在工作区中诞生和修改的;
  2. 任何修改都是从进入index区才开始被版本控制的;
  3. 只有把修改的代码提交到本地仓库,该修改才能在仓库中留下痕迹;
  4. 与协助者分享本地的修改,可以push到远程仓库来共享;

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环境部署

复制代码
[root@localhost ~]# hostname gitlab
[root@localhost ~]# bash
[root@gitlab ~]#

安装依赖包

复制代码
[root@gitlab ~]# yum -y install curl openssh-server openssh-clients postfix cronie policycoreutils-python

启动postfix,并设置开机自启

复制代码
[root@gitlab ~]# systemctl start postfix
[root@gitlab ~]# systemctl enable postfix

设置防火墙

复制代码
[root@gitlab ~]# systemctl stop firewalld
[root@gitlab ~]# iptables -F
[root@gitlab ~]# setenforce 0

下载安装gitlab rpm包

清华开源镜像站:​​​​​​清华大学开源软件镜像站 | Tsinghua Open Source Mirror

bash 复制代码
[root@gitlab ~]#  wget https://mirrors.tuna.tsinghua.edu.cn/gitlab-ce/yum/el7/gitlab-ce-11.11.3-ce.0.el7.x86_64.rpm
--2023-08-18 09:51:35--  https://mirrors.tuna.tsinghua.edu.cn/gitlab-ce/yum/el7/gitlab-ce-11.11.3-ce.0.el7.x86_64.rpm
正在解析主机 mirrors.tuna.tsinghua.edu.cn (mirrors.tuna.tsinghua.edu.cn)... 101.6.15.130, 2402:f000:1:400::2
正在连接 mirrors.tuna.tsinghua.edu.cn (mirrors.tuna.tsinghua.edu.cn)|101.6.15.130|:443... 已连接。
已发出 HTTP 请求,正在等待回应... 200 OK
长度:656975758 (627M) [application/x-redhat-package-manager]
正在保存至: "gitlab-ce-11.11.3-ce.0.el7.x86_64.rpm"

100%[===============================================================>] 656,975,758 3.97MB/s 用时 2m 43s 

2023-08-18 09:54:18 (3.85 MB/s) - 已保存 "gitlab-ce-11.11.3-ce.0.el7.x86_64.rpm" [656975758/656975758])

[root@gitlab ~]# rpm -ivh gitlab-ce-11.11.3-ce.0.el7.x86_64.rpm 
警告:gitlab-ce-11.11.3-ce.0.el7.x86_64.rpm: 头V4 RSA/SHA1 Signature, 密钥 ID f27eab47: NOKEY
准备中...                          ################################# [100%]
正在升级/安装...
   1:gitlab-ce-11.11.3-ce.0.el7       ################################# [100%]


       *.                  *.
      ***                 ***
     *****               *****
    .******             *******
    ********            ********
   ,,,,,,,,,***********,,,,,,,,,
  ,,,,,,,,,,,*********,,,,,,,,,,,
  .,,,,,,,,,,,*******,,,,,,,,,,,,
      ,,,,,,,,,*****,,,,,,,,,.
         ,,,,,,,****,,,,,,
            .,,,***,,,,
                ,*,.
  


     _______ __  __          __
    / ____(_) /_/ /   ____ _/ /_
   / / __/ / __/ /   / __ `/ __ \
  / /_/ / / /_/ /___/ /_/ / /_/ /
  \____/_/\__/_____/\__,_/_.___/
  

修改配置文件/etc/gitlab/gitlab.rb,生产环境下可以根据需求修改

bash 复制代码
[root@gitlab ~]# vim /etc/gitlab/gitlab.rb 
13 external_url 'http://192.168.147.142'

重新加载配置文件

bash 复制代码
[root@gitlab ~]# gitlab-ctl reconfigure
[root@gitlab ~]# gitlab-ctl restart
[root@gitlab ~]# netstat -lnpt | grep :80

tcp        0      0 0.0.0.0:80              0.0.0.0:*               LISTEN      11982/nginx: master 
  1. 启动:gitlib-ctl start
  2. 关闭:gitlab-ctl stop
  3. 重启:gitlab-ctl restart
  4. 重载配置:gitlab-ctl reconfigure
  5. 查看状态:gitlab-ctl status

查看gitlab版本

bash 复制代码
[root@gitlab ~]# head -1 /opt/gitlab/version-manifest.txt 
gitlab-ce 11.11.3

浏览器登录Gitlab输入 http://服务器IP

创建新的项目

打开另一台主机

bash 复制代码
[root@localhost ~]# hostname jenkins
[root@localhost ~]# bash

[root@jenkins ~]# git config --global user.name "jenkins"
[root@jenkins ~]# git config --global user.email "jenkins@test.com"
[root@jenkins ~]# git config --global color.ui true
[root@jenkins ~]# git config --list
user.name=jenkins
user.email=jenkins@test.com
color.ui=true
[root@jenkins ~]# git clone http://192.168.147.142/root/crushlinux.git
正克隆到 'crushlinux'...
remote: Enumerating objects: 3, done.
remote: Counting objects: 100% (3/3), done.
remote: Total 3 (delta 0), reused 0 (delta 0)
Unpacking objects: 100% (3/3), done.

设置发邮件功能

修改配置文件

bash 复制代码
[root@gitlab ~]# vim /etc/gitlab/gitlab.rb
517 gitlab_rails['smtp_enable'] = true
 518 gitlab_rails['smtp_address'] = "smtp.163.com"
 519 gitlab_rails['smtp_port'] = 25
 520 gitlab_rails['smtp_user_name'] = "crushlinux@163.com"
 521 gitlab_rails['smtp_password'] = "123456"
 522 gitlab_rails['smtp_domain'] = "163.com"
 523 gitlab_rails['smtp_authentication'] = "login"
 524 gitlab_rails['smtp_enable_starttls_auto'] = true
#修改gitlab配置的发信人
 53 gitlab_rails['gitlab_email_from'] = 'crushlinux@163.com'
677 user['git_user_email'] = "crushlinux@163.com"

重新加载配置并重新启动服务

bash 复制代码
[root@gitlab ~]# gitlab-ctl reconfigure
[root@gitlab ~]# gitlab-ctl restart
相关推荐
明月心95214 小时前
git remote add 用法
gitlab
only_Klein20 小时前
jenkins流水线报错:Connection reset by peer
ci/cd·kubernetes·gitlab·jenkins·ssl
梁萌2 天前
docker部署gitlab和gitlab runner
docker·eureka·gitlab
johnnyAndCode2 天前
Idea 设置GitLab时使用账密,而不是token的配置方法
gitlab·idea
天外飞雨2 天前
Gitlab使用
gitlab
BUTCHER53 天前
GitLab SSH 密钥配置
运维·ssh·gitlab
明月心9523 天前
GitLab使用
gitlab
明月心9524 天前
gitlab pull requets
gitlab
BUTCHER54 天前
GitLab基本设置
gitlab
张小凡vip4 天前
Kubernetes---gitlab的ci/cd发布基于k8s的项目示例参考
ci/cd·kubernetes·gitlab