gitlab迁移及版本升级
Posted 幽反丶叛冥
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了gitlab迁移及版本升级相关的知识,希望对你有一定的参考价值。
摘要:将原有的gitlab迁移到 vmware esxi虚拟机上。在迁移成功后,将gitlab版本升级到最新的14.2.3。以前系统为centos7.8,新的系统为centos7.9。建议通gitlab官方的文档来进行相应操作,文章中命令存在非官方推荐操作方式
相关文章
- CentOS7上安装gitlab
- gitlab使用163邮箱向用户发送邮件
- CentOS 7.8 密码重置
- centos7 centos-home 磁盘空间转移至centos-root下
- xftp5 连接 centos7.8
- gitlab备份库局域网中远程备份至另一台windows电脑
- gitlab迁移及版本升级
一、Gitlab安装
这里对环境安装不一样的地方进行罗列。此处不进行安装说明,安装可参见顶部“相关文章”部分。
01、升级内核和软件
yum -y update
02、查看系统版本
[root@master ~]# lsb_release -a
LSB Version: :core-4.1-amd64:core-4.1-noarch:cxx-4.1-amd64:cxx-4.1-noarch:desktop-4.1-amd64:desktop-4.1-noarch:languages-4.1-amd64:languages-4.1-noarch:printing-4.1-amd64:printing-4.1-noarch
Distributor ID: CentOS
Description: CentOS Linux release 7.9.2009 (Core)
Release: 7.9.2009
Codename: Core
03、查看磁盘大小
[root@master ~]# cd ..
[root@master /]# ls
bin boot dev etc home lib lib64 media mnt opt proc root run sbin srv sys tmp usr var
[root@master /]# df -h
文件系统 容量 已用 可用 已用% 挂载点
devtmpfs 3.9G 0 3.9G 0% /dev
tmpfs 3.9G 0 3.9G 0% /dev/shm
tmpfs 3.9G 9.8M 3.9G 1% /run
tmpfs 3.9G 0 3.9G 0% /sys/fs/cgroup
/dev/mapper/centos-root 50G 5.1G 45G 11% /
/dev/sda1 1014M 172M 843M 17% /boot
/dev/mapper/centos-home 146G 38M 146G 1% /home
tmpfs 799M 44K 799M 1% /run/user/0
/dev/sr0 4.4G 4.4G 0 100% /run/media/root/CentOS 7 x86_64
[root@master /]# df -h /home
文件系统 容量 已用 可用 已用% 挂载点
/dev/mapper/centos-home 146G 38M 146G 1% /home
[root@master /]# df -h /root
文件系统 容量 已用 可用 已用% 挂载点
/dev/mapper/centos-root 50G 5.1G 45G 11% /
注意:这里为什么要查看一下,磁盘的大小,因为在安装centos系统的时候默认root空间都是50G,其他空间都划分到home下。但是gitlba默认在root下。可在在安装的时候,磁盘进行分配好
04、gitlab安装
gitlab可以采用二种方式:rpm安装,也可以通过yum安装。自己这边采用的为通过yum安装。
查看之前服务器上gitlab版本
[root@localhost ~]# gitlab-rake gitlab:env:info
System information
System: CentOS 7.8.2003
Proxy: no
Current User: git
Using RVM: no
Ruby Version: 2.6.6p146
Gem Version: 2.7.10
Bundler Version:1.17.3
Rake Version: 12.3.3
Redis Version: 5.0.9
Git Version: 2.27.0
Sidekiq Version:5.2.7
Go Version: unknown
GitLab information
Version: 13.1.1-ee
Revision: a604fffd4ba
Directory: /opt/gitlab/embedded/service/gitlab-rails
DB Adapter: PostgreSQL
DB Version: 11.7
URL: http://10.131.19.166
HTTP Clone URL: http://10.131.19.166/some-group/some-project.git
SSH Clone URL: git@10.131.19.166:some-group/some-project.git
Elasticsearch: no
Geo: no
Using LDAP: no
Using Omniauth: yes
Omniauth Providers:
GitLab Shell
Version: 13.3.0
Repository storage paths:
- default: /var/opt/gitlab/git-data/repositories
GitLab Shell path: /opt/gitlab/embedded/service/gitlab-shell
Git: /opt/gitlab/embedded/bin/git
[root@localhost ~]# cat /opt/gitlab/embedded/service/gitlab-rails/VERSION
13.1.1-ee
方式一:通过rpm安装
通过 gitlab官网: gitlab-ee Packages 此链接可以下载对应文件
[root@master software]# rpm -ivh gitlab-ee-13.1.1-ee.0.el7.x86_64.rpm
警告:gitlab-ee-13.1.1-ee.0.el7.x86_64.rpm: 头V4 RSA/SHA1 Signature, 密钥 ID f27eab47: NOKEY
准备中... ################################# [100%]
正在升级/安装...
1:gitlab-ee-13.1.1-ee.0.el7 ################################# [100%]
It looks like GitLab has not been configured yet; skipping the upgrade script.
*. *.
*** ***
***** *****
.****** *******
******** ********
,,,,,,,,,***********,,,,,,,,,
,,,,,,,,,,,*********,,,,,,,,,,,
.,,,,,,,,,,,*******,,,,,,,,,,,,
,,,,,,,,,*****,,,,,,,,,.
,,,,,,,****,,,,,,
.,,,***,,,,
,*,.
_______ __ __ __
/ ____(_) /_/ / ____ _/ /_
/ / __/ / __/ / / __ `/ __ \\
/ /_/ / / /_/ /___/ /_/ / /_/ /
\\____/_/\\__/_____/\\__,_/_.___/
Thank you for installing GitLab!
GitLab was unable to detect a valid hostname for your instance.
Please configure a URL for your GitLab instance by setting `external_url`
configuration in /etc/gitlab/gitlab.rb file.
Then, you can start your GitLab instance by running the following command:
sudo gitlab-ctl reconfigure
For a comprehensive list of configuration options please see the Omnibus GitLab readme
https://gitlab.com/gitlab-org/omnibus-gitlab/blob/master/README.md
方式二:通过yun安装
sudo yum install -y curl policycoreutils-python openssh-server perl
sudo systemctl enable sshd
sudo systemctl start sshd
sudo firewall-cmd --permanent --add-service=http
sudo firewall-cmd --permanent --add-service=https
sudo systemctl reload firewalld
sudo yum install postfix
sudo systemctl enable postfix
sudo systemctl start postfix
curl https://packages.gitlab.com/install/repositories/gitlab/gitlab-ee/script.rpm.sh | sudo bash
sudo yum install gitlab-ee-13.1.1-ee.0.el7.x86_64
注:就是安装这一步同以往不一致,记得之前的时候默认就会安装最新版本,但是这次居然可以指定安装版本
二、gitlab备份迁移
01、备份原gitlab数据
停止部分 Gitlab 服务
[root@localhost ~]# gitlab-ctl stop unicorn
[root@localhost ~]# gitlab-ctl stop sidekiq
ok: down: sidekiq: 0s, normally up
[root@localhost ~]# gitlab-ctl stop nginx
ok: down: nginx: 1s, normally up
进行备份
[root@localhost ~]# gitlab-rake gitlab:backup:create
2021-09-14 12:15:29 +0800 -- Dumping database ...
Dumping PostgreSQL database gitlabhq_production ... [DONE]
2021-09-14 12:15:32 +0800 -- done
2021-09-14 12:15:32 +0800 -- Dumping repositories ...
* company/gitfilecompany (@hashed/d4/73/d4735e3a265e16eee03f59718b9b5d03019c07d8b6c51f90da3a666eec13ab35) ... [SKIPPED]
[SKIPPED] Wiki
* dylyy/myselfsystem (@hashed/4e/07/4e07408562bedb8b60ce05c1decfe3ad16b72230967de01f640b7e4729b49fce) ... [DONE]
[SKIPPED] Wiki
* zzshkj/queue_system_zzcar (@hashed/4b/22/4b227777d4dd1fc61c6f884f48641d02b4d121d3fd328cb08b5531fcacdabf8a) ... [DONE]
[SKIPPED] Wiki
......
[SKIPPED] Wiki
* jjxhospz/jiajiangxiantcmwindow (@hashed/d6/06/d6061bbee6cf13bd73765faaea7cdd0af1323e4b125342ac346047f7c4bda1fc) ... [DONE]
[SKIPPED] Wiki
2021-09-14 12:20:05 +0800 -- done
2021-09-14 12:20:05 +0800 -- Dumping uploads ...
2021-09-14 12:20:06 +0800 -- done
2021-09-14 12:20:06 +0800 -- Dumping builds ...
2021-09-14 12:20:06 +0800 -- done
2021-09-14 12:20:06 +0800 -- Dumping artifacts ...
2021-09-14 12:20:06 +0800 -- done
2021-09-14 12:20:06 +0800 -- Dumping pages ...
2021-09-14 12:20:06 +0800 -- done
2021-09-14 12:20:06 +0800 -- Dumping lfs objects ...
2021-09-14 12:20:06 +0800 -- done
2021-09-14 12:20:06 +0800 -- Dumping container registry images ...
2021-09-14 12:20:06 +0800 -- [DISABLED]
Creating backup archive: 1631593206_2021_09_14_13.1.1-ee_gitlab_backup.tar ... done
Uploading backup archive to remote storage ... skipped
Deleting tmp directories ... done
done
done
done
done
done
done
done
Deleting old backups ... done. (0 removed)
Warning: Your gitlab.rb and gitlab-secrets.json files contain sensitive data
and are not included in this backup. You will need these files to restore a backup.
Please back them up manually.
Backup task is done.
其中,/etc/gitlab/gitlab-secrets.json 和 /etc/gitlab/gitlab.rb 这两个文件需要自行手动备份一下
02、拷贝数据到新服务器Gitlab上
使用scp命令从本地旧服务器复制文件到新服务器
scp /var/opt/gitlab/backups/1631588454_2021_09_14_13.1.1-ee_gitlab_backup.tar root@172.16.1.166:/var/opt/gitlab/backups/
根据提示输入自己新服务器的密码:xxxxxx
传送过程中遇到速度较慢、中途断网(无断电续传)问题,其中发现出现问题情况也可以完成传输,但是其文件大小不对
03、恢复备份
将备份文件权限修改为777,避免出现权限不够的问题
[root@localhost ~]# cd /var/opt/gitlab/backups
[root@localhost backups]# ls
1631588454_2021_09_14_13.1.1-ee_gitlab_backup.tar
[root@localhost backups]# chmod 777 1631593206_2021_09_14_13.1.1-ee_gitlab_backup.tar
[root@localhost backups]#
停止部分 Gitlab 服务
[root@localhost ~]# gitlab-ctl stop unicorn
[root@localhost ~]# gitlab-ctl stop sidekiq
ok: down: sidekiq: 0s, normally up
[root@localhost ~]# gitlab-ctl stop nginx
ok: down: nginx: 1s, normally up
恢复数据,中途会有提示确认操作
gitlab-rake gitlab:backup:restore BACKUP=1631593206_2021_09_14_13.1.1-ee
BACKUP后面表示备份文件版本号,如自己备份文件为 1631593206_2021_09_14_13.1.1-ee_gitlab_backup.tar
,那么1631593206_2021_09_14_13.1.1-ee
就是对应版本号
提示一:删除原有数据库
[root@localhost backups]# gitlab-rake gitlab:backup:restore BACKUP=1631593206_2021_09_14_13.1.1-ee
Unpacking backup ... done
Before restoring the database, we will remove all existing
tables to avoid future upgrade problems. Be aware that if you have
custom tables in the GitLab database these tables and all data will be
removed.
Do you want to continue (yes/no)? yes
自己为新装,选择yes,进行删除
提示二:重构密码文件
This task will now rebuild the authorized_keys file.
You will lose any data stored in the authorized_keys file.
Do you want to continue (yes/no)?
自身为新装,全部都拷贝过来,选择的yes
安装完成
Warning: Your gitlab.rb and gitlab-secrets.json files contain sensitive data
and are not included in this backup. You will need to restore these files manually.
Restore task is done.
手动拷贝: gitlab.rb and gitlab-secrets.json到新的服务器
三、gitlab升级
如果只是升级,一定要做好备份工作,避免升级失败导致数据丢失。
01、查询版本
yum search gitlab --showduplicates
查询gitlab所有版本(展示适合当前系统)
升级有两种方式,第一种就是停止gitlab进行,连续升级。第二种就是安装推荐版本以此升级。第一种方式自己没有成功,以下为第二方式。
02、版本升级
升级的版本路径,可以参见官网的文件。gitlab官网: Upgrade paths,比如自己初始版本为13.1.1,升级到14.2.3版本,共升级了5个版本 13.1.1 ——> 13.1.11 ——> 13.8.8 ——> 13.12.11 ——> 14.0.10 ——> 14.2.3
停止部分 Gitlab 服务
[root@localhost ~]# gitlab-ctl stop unicorn
[root@localhost ~]# gitlab-ctl stop sidekiq
ok: down: sidekiq: 0s, normally up
[root@localhost ~]# gitlab-ctl stop nginx
ok: down: nginx: 1s, normally up
安装升级版本
yum -y install gitlab-ee-13.1.11-ee.0.el7.x86_64
重启gitlab及查看版本信息
gitlab-ctl restart
cat /opt/gitlab/embedded/service/gitlab-rails/VERSION
重复上面,停止部分 Gitlab 服务 ——> 安装升级版本 ——> 重启gitlab及查看版本信息。直到安装完成一下版本
yum -y install gitlab-ee-13.1.11-ee.0.el7.x86_64
yum -y install gitlab-ee-13.8.8-ee.0.el7.x86_64
yum -y install gitlab-ee-13.12.11-ee.0.el7.x86_64
yum -y install gitlab-ee-14.0.10-ee.0.el7.x86_64
yum -y install gitlab-ee-14.2.3-ee.0.el7.x86_64
四、问题相关
01、No such file or directory @ rb_sysopen - backup_information.yml
[root@localhost backups]# gitlab-rake gitlab:backup:restore BACKUP=1631588454_2021_09_14_13.1.1-ee
Unpacking backup ... done
rake aborted!
Errno::ENOENT: No such file or directory @ rb_sysopen - backup_information.yml
/opt/gitlab/embedded/service/gitlab-rails/lib/backup/manager.rb:243:in `settings'
/opt/gitlab/embedded/service/gitlab-rails/lib/backup/manager.rb:113:in `block in verify_backup_version'
/opt/gitlab/embedded/service/gitlab-rails/lib/backup/manager.rb:111:in `chdir'
/opt/gitlab/embedded/service/gitlab-rails/lib/backup/manager.rb:111:in `verify_backup_version'
/opt/gitlab/embedded/service/gitlab-rails/lib/tasks/gitlab/backup.rake:44:in `block (3 levels) in <top (required)>'
/opt/gitlab/embedded/bin/bundle:23:in `load'
/opt/gitlab/embedded/bin/bundle:23:in `<main>'
Tasks: TOP => gitlab:backup:restore
(See full trace by running task with --trace)
[root@localhost backups]#
在恢复文件的时候,提示以上出错。原因为在手动备份的时候,没有调用gitlab-ctl stop unicorn、gitlab-ctl stop sidekiq、gitlab-ctl stop nginx。按道理应该是没有问题的,不然之前的定时备份岂不是无用?
02、Error: %pre(gitlab-ee-13.1.11-ee.0.el7.x86_64) scriptlet failed
[root@localhost ~]# gitlab-ctl stop
ok: down: alertmanager: 0s, normally up
ok: down: gitaly: 0s, normally up
ok: down: gitlab-exporter: 0s, normally up
ok: down: gitlab-workhorse: 1s, normally up
ok: down: grafana: 0s, normally up
ok: down: logrotate: 1s, normally up
ok: down: nginx: 0s, normally up
ok: down: node-exporter: 0s, normally up
ok: down: postgres-exporter: 1s, normally up
ok: down: postgresql: 0s, normally up
ok: down: prometheus: 1s, normally up
ok: down: puma: 0s, normally up
ok: down: redis: 1s, normally up
ok: down: redis-exporter: 0s, normally up
ok: down: sidekiq: 0s, normally up
[root@localhost ~]# yum -y install gitlab-ee-13.1.11-ee.0.el7.x86_64
已加载插件:fastestmirror, langpacks
Loading mirror speeds from cached hostfile
* base: mirrors.aliyun.com
* epel: mirrors.ustc.edu.cn
* extras: mirrors.cn99.com
* updates: mirrors.cn99.com
gitlab_gitlab-ee/x86_64/signature | 862 B 00:00:00
gitlab_gitlab-ee/x86_64/signature | 1.0 kB 00:00:00 !!!
gitlab_gitlab-ee-source/signature | 862 B 00:00:00
gitlab_gitlab-ee-source/signature | 951 B 00:00:00 !!!
正在解决依赖关系
--> 正在检查事务
---> 软件包 gitlab-ee.x86_64.0.13.1.1-ee.0.el7 将被 升级
---> 软件包 gitlab-ee.x86_64.0.13.1.11-ee.0.el7 将被 更新
--> 解决依赖关系完成
依赖关系解决
==============================================================================================
Package 架构 版本 源 大小
==============================================================================================
正在更新:
gitlab-ee x86_64 13.1.11-ee.0.el7 gitlab_gitlab-ee 772 M
事务概要
==============================================================================================
升级 1 软件包
总下载量:772 M
Downloading packages:
No Presto metadata available for gitlab_gitlab-ee
gitlab-ee-13.1.11-ee.0.el7.x86_64.rpm | 772 MB 00:00:59
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
gitlab preinstall:
gitlab preinstall: This node does not appear to be running a database
gitlab preinstall: Skipping version check, if you think this is an error exit now
gitlab preinstall:
gitlab preinstall: Automatically backing up only the GitLab SQL database (excluding everything else!)
2021-09-14 21:57:26 +0800 -- Dumping database ...
Dumping PostgreSQL database gitlabhq_production ... pg_dump: [archiver (db)] connection to database "gitlabhq_production" failed: could not connect to server: 没有那个文件或目录
Is the server running locally and accepting
connections on Unix domain socket "/var/opt/gitlab/postgresql/.s.PGSQL.5432"?
rake aborted!
Backup::Error: Backup failed
/opt/gitlab/embedded/service/gitlab-rails/lib/backup/database.rb:45:in `dump'
/opt/gitlab/embedded/service/gitlab-rails/lib/tasks/gitlab/backup.rake:118:in `block (4 levels) in <top (required)>'
/opt/gitlab/embedded/service/gitlab-rails/lib/tasks/gitlab/backup.rake:10:in `block (3 levels) in <top (required)>'
/opt/gitlab/embedded/bin/bundle:23:in `load'
/opt/gitlab/embedded/bin/bundle:23:in `<main>'
Tasks: TOP => gitlab:backup:db:create
(See full trace by running task with --trace)
[FAILED]
gitlab preinstall:
gitlab preinstall: Database backup failed! If you want to skip this backup, run the following command and try again:
gitlab preinstall:
gitlab preinstall: sudo touch /etc/gitlab/skip-auto-backup
gitlab preinstall:
error: %pre(gitlab-ee-13.1.11-ee.0.el7.x86_64) scriptlet failed, exit status 1
Error in PREIN scriptlet in rpm package gitlab-ee-13.1.11-ee.0.el7.x86_64
gitlab-ee-13.1.1-ee.0.el7.x86_64 was supposed to be removed but is not!
验证中 : gitlab-ee-13.1.1-ee.0.el7.x86_64 1/2
验证中 : gitlab-ee-13.1.11-ee.0.el7.x86_64 2/2
失败:
gitlab-ee.x86_64 0:13.1.1-ee.0.el7 gitlab-ee.x86_64 0:13.1.11-ee.0.el7
完毕!
在通过gitlab-ctl stop 计划连续升级的时候,出现以上错误。后续采用逐次升级,升级成功。
五、参考链接
gitlab官网: Back up and restore GitLab
GitLab从旧服务器迁移到新服务器
gitlab-ee Packages
centos7 RPM命令安装.rpm文件操作
linux命令 ll信息详解
GitLab 14.0发布,改善了DevOps,全面启用哈希存储
gitlab官网: Upgrade paths
Gitlab版本升级
以上是关于gitlab迁移及版本升级的主要内容,如果未能解决你的问题,请参考以下文章