gitlab部署配置

gitlab是一个功能非常强大的私有化git仓库

部署

  • yum安装
yum install -y curl policycoreutils-python openssh-server
systemctl enable sshd
systemctl start sshd
curl https://packages.gitlab.com/install/repositories/gitlab/gitlab-ee/script.rpm.sh | sudo bash
yum install -y gitlab-ce

备份

设置定时备份
  • crobjob设置定时备份
0 23 * * * /opt/gitlab/bin/gitlab-backup create SKIP=builds,artifacts,lfs,terraform_state
设置备份保留时间
  • 保留三天
gitlab_rails['backup_keep_time'] = 259200
备份到挂载在本地的存储
  • 修改配置文件,/mnt/nfs为nfs挂载点
gitlab_rails['backup_upload_connection'] = {
  :provider => 'Local',
  :local_root => '/mnt/nfs'
}

gitlab_rails['backup_upload_remote_directory'] = 'gitlab-backups'
  • 执行gitlab-ctl reconfigure生效

还原

sudo gitlab-ctl stop puma
sudo gitlab-ctl stop sidekiq
# Verify
sudo gitlab-ctl status

gitlab-backup restore BACKUP=1684312462_2023_05_17_14.9.5

升级

注意14版本以上增加了后台迁移任务,后台迁移任务未跑完成时升级会报错 https://docs.gitlab.com/ee/update/index.html#batched-background-migrations

  • 下载并安装
wget --content-disposition https://packages.gitlab.com/gitlab/gitlab-ce/packages/el/7/gitlab-ce-13.12.12-ce.0.el7.x86_64.rpm/download.rpm
yum -y install gitlab-ce-13.12.12-ce.0.el7.x86_64.rpm

runner

# apt
curl -L "https://packages.gitlab.com/install/repositories/runner/gitlab-runner/script.deb.sh" | sudo bash

# apt
curl -L "https://packages.gitlab.com/install/repositories/runner/gitlab-runner/script.rpm.sh" | sudo bash
  • 安装gitlab runner
# apt
sudo apt-get install gitlab-runner

# yum
sudo yum install gitlab-runner
  • 注册 管理区域->cicd->runenr添加一个,然后会出现类似gitlab-runner register --url http://gitlab.naturelr.cc --token glrt-94ZmmuqybyyGdPW_kbSJ

  • 启动,将注册的时候出现的命令执行一下,会询问你一些信息一步一步操作即可

gitalb-pages

  • 设置pages的地址,不要和gitlab的域名一致,dns是是泛域名解析到gitlab服务器
pages_external_url "http://pages.example.com/"
gitlab_pages['enable'] = true
实例
pages:
  stage: deploy
  script:
    - mkdir .public
    - cp -r * .public
    - mv .public public
  artifacts:
    paths:
      - public
  only:
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <h1>测试</h1>
</body>
</html>