Skip to content

Latest commit

 

History

History
172 lines (123 loc) · 5.19 KB

gitlab-ce-simple-usage.md

File metadata and controls

172 lines (123 loc) · 5.19 KB

更多具体可参看系列文章:Git/Gitlab 进阶(2020 年版)

Omnibus package installation

  1. Install and configure the necessary dependencies sudo apt-get install -y curl openssh-server ca-certificates (如果之后自己配置邮件服务器,忽略即可):sudo apt-get install -y postfix
  2. Add the GitLab package repository and install the package curl -sS https://packages.gitlab.com/install/repositories/gitlab/gitlab-ce/script.deb.sh | sudo bash sudo EXTERNAL_URL="192.168.21.116" apt-get install gitlab-ce
  3. Browse to the hostname and login

基础命令

  • 查看运行状态: sudo gitlab-ctl status
  • Start all GitLab components: sudo gitlab-ctl start
  • Stop all GitLab components: sudo gitlab-ctl stop
  • Restart all GitLab components: sudo gitlab-ctl restart
  • 查看 gitlab 版本:cat /opt/gitlab/embedded/service/gitlab-rails/VERSION
  • 重新应用配置: sudo gitlab-ctl reconfigure

备份

  1. Creating a backup of the GitLab system

Use this command if you've installed GitLab with the Omnibus package: sudo gitlab-rake gitlab:backup:create

  1. 每周 3 晚上十点备份
sudo su -
crontab -e
# 在文本建立以下规则然后报错
0 22 * * 3 /opt/gitlab/bin/gitlab-rake gitlab:backup:create CRON=1
  1. 恢复 Omnibus 安装

此过程假定:

已经安装了与创建备份的 GitLab Omnibus 完全相同的版本和类型(CE / EE)。
sudo gitlab-ctl reconfigure至少跑了一次。
GitLab 正在运行。如果没有,请使用它sudo gitlab-ctl start

  • 停止连接到数据库的进程,剩下部分继续 running (Leave the rest of GitLab running):
sudo gitlab-ctl stop unicorn
sudo gitlab-ctl stop sidekiq
# Verify
sudo gitlab-ctl status
  • 查看目前已有备份文件(如果还在默认备份的位置)
ls /var/opt/gitlab/backups/
ls /mnt/backups/
1555980161_2019_04_23_11.8.1_gitlab_backup.tar
  • 选择对应的版本还原
sudo gitlab-rake gitlab:backup:restore BACKUP=1569398057_2019_09_25_12.3.0
sudo gitlab-rake gitlab:backup:restore BACKUP=1628152778_2021_08_05_12.3.0
#有必要的话,还原其他文件Next, restore /etc/gitlab/gitlab-secrets.json if necessary as mentioned above.
  • 重启 gitlab 并检查 Restart and check GitLab:
sudo gitlab-ctl restart
sudo gitlab-rake gitlab:check SANITIZE=true

移除超过 30 天的 gitlab 备份脚本: rmOver30day.sh

#!/bin/sh
find /mnt/backup/gitlab -type f -ctime +30 | xargs rm -rf

测试 gitlab smtp 配置是否成功

终端机输入:

sudo gitlab-rails console

出现命令窗口时,输入一下进行测试

Notify.test_email('[email protected]', '測試gitlab-ce SMTP配置', '如果收到此信息,smtp配置成功!').deliver_now

升级 gitlab

sudo apt-get update &&
sudo apt-get install gitlab-ce

卸載 gitlab

The recommended process to uninstall it was:

  1. Remove services
sudo gitlab-ctl uninstall
  1. Clean any data generated by usage of the package
sudo gitlab-ctl cleanse
  1. You may also want to remove any accounts you configured. To do so
sudo gitlab-ctl remove-accounts
  1. Then remove the package using
sudo dpkg -P gitlab-ce
  1. Furthermore, gitlab-ce uses these directories (as described here) 刪除以下 gitlab 相關文件夾,使用 rm 是 ok 的
/opt/gitlab holds application code for GitLab and its dependencies.
/var/opt/gitlab holds application data and configuration files that gitlab-ctl reconfigure writes to.
/etc/gitlab holds configuration files for omnibus-gitlab. These are the only files that you should ever have to edit manually.
/var/log/gitlab contains all log data generated by components of omnibus-gitlab.

再执行 sudo gitlab-ctl reconfigure 可能出现带 90-omnibus-gitlab。。。什么的错误, 可能是因为缺少以下文件,执行即可:

sudo touch /opt/gitlab/embedded/etc/90-omnibus-gitlab-kernel.sem.conf
sudo touch /opt/gitlab/embedded/etc/90-omnibus-gitlab-kernel.shmall.conf
sudo touch /opt/gitlab/embedded/etc/90-omnibus-gitlab-net.core.somaxconn.conf

安裝指定版本

查看 gitlab-ce 指定版本:https://packages.gitlab.com/gitlab/gitlab-ce

curl -s https://packages.gitlab.com/install/repositories/gitlab/gitlab-ce/script.deb.sh | sudo bash
sudo apt-get install gitlab-ce=12.9.3-ce.0
sudo EXTERNAL_URL="127.0.0.1" apt-get install gitlab-ce=12.9.3-ce.0