关于gitlab:史上最全Gitlab部署

10次阅读

共计 4201 个字符,预计需要花费 11 分钟才能阅读完成。

一、前言

1、本文次要内容

  • GitLab 社区版部署
  • GitLab 配置禁用创立组权限
  • GitLab 配置邮件(SMTP)
  • Gitlab 备份配置
  • GitLab 常用命令阐明

    2、GitLab 介绍

    GitLab 一个开源的 git 仓库治理平台,不便团队合作开发、治理。在 GitLab 上能够实现残缺的 CI(继续集成)、CD(继续公布)流程。而且还提供了收费应用的 Plan,以及收费的能够独立部署的社区版本(https://gitlab.com/gitlab-org/gitlab-ce)。官网:https://about.gitlab.com/

    二、筹备工作

    1、安准根底依赖(这一步根本都能够跳过,很多服务器默认装置)

    # 装置技术依赖
    sudo yum install -y curl policycoreutils-python openssh-server
    
    #启动 ssh 服务 & 设置为开机启动
    sudo systemctl enable sshd
    sudo systemctl start sshd

    2、装置 Postfix

    Postfix 是一个邮件服务器,GitLab 发送邮件须要用到

    # 装置 postfix
    sudo yum install -y postfix
    
    #启动 postfix 并设置为开机启动
    sudo systemctl enable postfix
    sudo systemctl start postfix

    3、凋谢 ssh 以及 http 服务

    依据理论状况执行,公司外部服务器初始时,防火墙就没关上

    # 凋谢 ssh、http 服务
    sudo firewall-cmd --add-service=ssh --permanent
    sudo firewall-cmd --add-service=http --permanent
    
    #重载防火墙规定
    sudo firewall-cmd --reload

    三、部署过程

    本次咱们部署的是社区版:gitlab-ce,如果要部署商业版能够把关键字替换为:gitlab-ee

    1、Yum 装置 GitLab

  • 增加 GitLab 社区版 Package

    curl https://packages.gitlab.com/install/repositories/gitlab/gitlab-ce/script.rpm.sh | sudo bash 
  • 装置 GitLab 社区版

    sudo yum install -y gitlab-ce 

    装置胜利后会看到 gitlab-ce 打印了以下图形

异样解决:

呈现“policycoreutils-python is needed by 问题”,应该是在装置 gitlab 时,gitlab 的版本是 centos7 的,如果你确定你的 centos 版本是 centos7

解决办法

sudo yum installpolicycoreutils-python

如果这个办法有效,你的 centos 版本肯定不是 centos7
如果你的 centos 版本是 centos8. 那么换一个 gitlab 版本,也就是从新下载一个,这里是最新地址

https://mirrors.tuna.tsinghua.edu.cn/gitlab-ce/yum/el8/

下载命令:

wget https://mirrors.tuna.tsinghua.edu.cn/gitlab-ce/yum/el8/gitlab-ce-12.10.1-ce.0.el8.x86_64.rpm

装置:

sudo rpm -i gitlab-ce-12.10.1-ce.0.el8.x86_64.rpm

若呈现谬误“policycoreutils-python-utils is needed by gitlab-ce-12.10.1-ce.0.el8.x86_64”
解决办法:

sudo yum install policycoreutils-python-utils

而后重新安装。

参考:https://blog.csdn.net/fu18838928050/article/details/107901895

2、配置 GitLab 站点 Url

GitLab 默认的配置文件门路是 /etc/gitlab/gitlab.rb
默认的站点 Url 配置项是:

external_url 'http://gitlab.example.com'

这里我将 GitLab 站点 Url 批改为 ”external_url ‘http://192.168.0.80:9000″
也能够用 IP 代替域名,这里依据本人需要来即可

# 批改配置文件
sudo vi /etc/gitlab/gitlab.rb

#配置首页地址(大概在第 15 行)external_url 'http://192.168.0.80:9000'

3、启动并拜访 GitLab

  • 启动 GitLab

    # 重新配置并启动
    sudo gitlab-ctl reconfigure
    
    #实现后将会看到如下输入
    Running handlers complete
    Chef Client finished, 432/613 resources updated in 03 minutes 43 seconds
    gitlab Reconfigured!
  • 拜访 GitLab

将设置的域名 DNS 解析到服务器 IP,或者批改本地 host 将域名指向服务器 IP。
拜访:http://192.168.0.80:9000

这时候会提醒为管理员账号设置明码。管理员账号默认 username 是 root。
设置实现之后即可应用 root 账号登录,登陆后会进入欢送界面。

四、GitLab 罕用配置

1、邮件配置

配置邮箱能够让 GitLab 在产生相应事件的时候进行邮件告诉
比方配置腾讯企业邮箱如下:

gitlab_rails['smtp_enable'] = true
gitlab_rails['smtp_address'] = "smtp.exmail.qq.com"
gitlab_rails['smtp_port'] = 465
gitlab_rails['smtp_user_name'] = "你的邮箱"
gitlab_rails['smtp_password'] = "你的邮箱明码"
gitlab_rails['smtp_domain'] = "exmail.qq.com"
gitlab_rails['smtp_authentication'] = "login"
gitlab_rails['smtp_enable_starttls_auto'] = true
gitlab_rails['smtp_tls'] = true
gitlab_rails['gitlab_email_from'] = '你的邮箱'

具体参考:
https://docs.gitlab.com/omnibus/settings/smtp.html

2、禁用创立组权限

GitLab 默认所有的注册用户都能够创立组。但对于团队来说,通常只会给 Leader 相干权限。
尽管能够在用户治理界面勾销权限,但毕竟不不便。咱们能够通过配置 GitLab 默认禁用创立组权限。

# 批改配置文件
sudo vi /etc/gitlab/gitlab.rb

#开启 gitlab_rails['gitlab_default_can_create_group'] 选项,并将值设置为 false
### GitLab user privileges
gitlab_rails['gitlab_default_can_create_group'] = false

#保留后,重新配置并启动 GitLab
sudo gitlab-ctl reconfigure

3. 配置代码地位

找到 git_data_dirs 选型,配置地址


git_data_dirs({
   "default" => {"path" => "/data/tools/gitlab/data"}
})

参考链接:https://docs.gitlab.com/omnibus/settings/configuration.html

4.gitlab 备份

1)批改配置文件

# 关上 gitlab 配置文件
vim /etc/gitlab/gitlab.rb

#设置备份文件的保留地位
gitlab_rails['backup_path'] = "/data/tools/gitlab/backup"

#设置备份文件的过期工夫,单位为秒,默认 7 天
gitlab_rails['backup_keep_time'] = 604800

执行 wq 保留后,刷新配置

gitlab-ctl reconfigure

2)执行备份命令验证

执行备份命令,去对应的文件门路查看是否曾经创立了备份文件

gitlab-rake gitlab:backup:create

执行打印如下:

红色字体形容为 gitlab.rb 和 gitlab-secrets.json 为敏感文件须要手动备份

3)通过 cron 定时备份

办法 1、在命令行输出: crontab -e 而后增加相应的工作,wq 存盘退出。

# 输出命令 crontab -e
crontab -e  
#输出相应的工作
0 2 * * * /opt/gitlab/bin/gitlab-rake gitlab:backup:create CRON=1  

办法 2、间接编辑 /etc/crontab 文件,即 vim /etc/crontab,而后增加相应的工作

# edited by ouyang 2017-8-11 增加定时工作,每天凌晨两点,执行 gitlab 备份
0  2    * * *   root    /opt/gitlab/bin/gitlab-rake gitlab:backup:create CRON=1

重启 cron 服务

systemctl restart crond.service

5.gitlab-ctl 常用命令介绍

命令 阐明
check-config 查看在 gitlab 中是否有任何配置。在指定版本中删除的 rb
deploy-page 装置部署页面
diff-config 将用户配置与包可用配置进行比拟
remove-accounts 删除所有用户和组
upgrade 降级
service-list 查看所有服务
once 如果 GitLab 服务进行了就启动服务,如果已启动就不做任何操作
restart 重启 GitLab 服务
start 如果 GitLab 服务进行了就启动服务,如果已启动就重启服务
stop 进行 GitLab 服务
status 查看 GitLab 服务状态
reconfigure reconfigure 重新配置 GitLab 并启动

参考链接:
https://ken.io/note/centos7-gitlab-install-tutorial

正文完
 0