安装gitlab
下载安装GitLab
1.安装最新版
添加镜像地址
添加镜像地址的目的是为了提高国内用户软件下载的速 度,编辑(新建)文件gitlab-ce.repo
,指令:
vim /etc/yum.repos.d/gitlab-ce.repo
输入:
[gitlab-ce]
name=gitlab-ce
# 清华大学的镜像源
baseurl=http://mirrors.tuna.tsinghua.edu.cn/gitlab-ce/yum/el7
repo_gpgcheck=0
gpgcheck=0
enabled=1
gpgkey=https://packages.gitlab.com/gpg.key
保存修改:按下ESC
键,再输入:wq
,然后回车
依赖
# 安装和配置openssh
sudo yum install curl policycoreutils-python openssh-server openssh-clients
sudo systemctl enable sshd
sudo systemctl start sshd
# 安装和配置邮件服务
sudo yum install postfix
sudo systemctl enable postfix
sudo systemctl start postfix
执行以下指令安装最新版的GitLab
yum install gitlab-ce
2.安装指定版
GitLab10.0.0下载:
curl -LJO https://mirrors.tuna.tsinghua.edu.cn/gitlab-ce/yum/el7/gitlab-ce-10.0.0-ce.0.el7.x86_64.rpm
安装:
rpm -i gitlab-ce-10.0.0-ce.0.el7.x86_64.rpm
修改GitLab配置:
vim /etc/gitlab/gitlab.rb
unicorn是ruby的http server
# 可以通过http://localhost:8080端口访问,nginx只是unicorn的反向代理
# vim的查找支持正规则, 所以`[`和`]`需要进行转义
/unicorn\['port'\]
自定义备份路径
gitlab_rails['backup_path'] = "/data/gitBackup"
输入以下命令进行重启配置:
gitlab-ctl reconfigure
再输入以下指令进行GitLab的重启:
gitlab-ctl restart
# 常用信息
/etc/gitlab/gitlab.rb # 主配置文件
/var/log/gitlab/ # 日志目录
/var/opt/gitlab/ # 各个服务的主目录
/var/opt/gitlab/git-data/repositories # Git仓库数据目录
查看版本
cat /opt/gitlab/embedded/service/gitlab-rails/VERSION
GitLab不能跨版本升级,需一个一个大版本升级。例如:10.8.7是10的最后一个版本,11.11.0是11的最后一 个版本,则从 10.3.3 升级到 12.0.1,需要经过 10.3.3 -> 10.8.7 -> 11.11.0 -> 12.0.1三次版本升级。
所以,要先在旧服务器上执行以下版本升级命令:
[root@old-host ~]# yum install -y gitlab-ce-10.8.7-ce.0.el7
[root@old-host ~]# yum install -y gitlab-ce-11.11.0-ce.0.el7
[root@old-host ~]# yum install -y gitlab-ce-12.0.1-ce.0.el7
创建备份
GitLab 12.2 或更高版本:
sudo gitlab-backup create
GitLab 12.1 及更早版本:
gitlab-rake gitlab:backup:create
要恢复备份,您必须恢复`/etc/gitlab/gitlab-secrets.json` (对于 Omnibus 包)或`/home/git/gitlab/.secret`(对于从源安装)。此文件包含数据库加密密钥、 [CI/CD 变量](https://docs.gitlab.com/ee/ci/variables/index.html)和用于[双重身份验证的](https://docs.gitlab.com/ee/user/profile/account/two_factor_authentication.html)变量。如果您未能将此加密密钥文件与应用程序数据备份一起还原,则启用了双因素身份验证且 GitLab Runner 的用户将失去对您的 GitLab 服务器的访问权限。
您可能还想恢复您以前的`/etc/gitlab/gitlab.rb`(对于 Omnibus 包)或`/home/git/gitlab/config/gitlab.yml`(对于从源安装)以及任何 TLS 密钥、证书 ( `/etc/gitlab/ssl`、`/etc/gitlab/trusted-certs`) 或 [SSH 主机密钥](https://superuser.com/questions/532040/copy-ssh-keys-from-one-server-to-another-server/532079#532079)。
- 您已安装与创建备份**完全相同的 GitLab Omnibus 版本和类型 (CE/EE) 。**
- 你`sudo gitlab-ctl reconfigure`至少跑过一次。
- GitLab 正在运行。如果没有,请使用`sudo gitlab-ctl start`.
首先确保您的备份 tar 文件位于 `gitlab.rb`配置中描述的备份目录中`gitlab_rails['backup_path']`。默认值为 `/var/opt/gitlab/backups`. 备份文件需要归`git`用户所有。
sudo cp 11493107454_2018_04_25_10.6.4-ce_gitlab_backup.tar /var/opt/gitlab/backups/
sudo chown git:git /var/opt/gitlab/backups/11493107454_2018_04_25_10.6.4-ce_gitlab_backup.tar
停止连接到数据库的进程。让 GitLab 的其余部分继续运行:
sudo gitlab-ctl stop puma
sudo gitlab-ctl stop sidekiq
# Verify
sudo gitlab-ctl status
接下来,恢复备份,指定要恢复的备份的时间戳:
# This command will overwrite the contents of your GitLab database!
sudo gitlab-backup restore BACKUP=11493107454_2018_04_25_10.6.4-ce
GitLab 12.1 及更早版本的用户应改用该命令`gitlab-rake gitlab:backup:restore`
接下来,[如前所述](https://docs.gitlab.com/ee/raketasks/backup_restore.html#restore-prerequisites)`/etc/gitlab/gitlab-secrets.json`,如有必要进行 恢复。[](https://docs.gitlab.com/ee/raketasks/backup_restore.html#restore-prerequisites)
重新配置、重启并[检查](https://docs.gitlab.com/ee/administration/raketasks/maintenance.html#check-gitlab-configuration)GitLab:
sudo gitlab-ctl reconfigure
sudo gitlab-ctl restart
sudo gitlab-rake gitlab:check SANITIZE=true
在 GitLab 13.1 及更高版本中,检查[数据库值可以被解密](https://docs.gitlab.com/ee/administration/raketasks/check.html#verify-database-values-can-be-decrypted-using-the-current-secrets), 特别是如果`/etc/gitlab/gitlab-secrets.json`已恢复,或者如果不同的服务器是恢复的目标。
sudo gitlab-rake gitlab:doctor:secrets
为了增加保证,您可以[对上传的文件执行完整性检查](https://docs.gitlab.com/ee/administration/raketasks/check.html#uploaded-files-integrity):
sudo gitlab-rake gitlab:artifacts:check
sudo gitlab-rake gitlab:lfs:check
sudo gitlab-rake gitlab:uploads:check