1 起因
原机器到期需要迁移到新机器上,为了节省机器先把gitlab和禅道放在一台机器上
原机器是centos7.6 新机器是centos6.9
2 迁移
1> 查看gitlab版本
需要同版本迁移,如果想升级到最高版,可以先升级,再备份
查看版本
cat /opt/gitlab/embedded/service/gitlab-rails/VERSION
2>old机器备份
gitlab-rake gitlab:backup:create
默认将会在 /var/opt/gitlab/backups/ 目录下生成备份文件
3>new机器还原
old机器版本为12.0.4 我没有升级直接在新机器上安装的12.0.4版本
安装-具体安装可参考之前文档
yum -y install gitlab-ce-12.4.0 --nogpgcheck
将备份的数据1587448920_2020_04_21_12.4.0_gitlab_backup.tar拷贝到新机器上
执行还原
gitlab-rake gitlab:backup:restore BACKUP=备份文件编号
#gitlab-rake gitlab:backup:restore BACKUP=1587448920_2020_04_21_12.4.0
重新启动gitlab-ctl start即可
备份
vim /etc/gitlab/gitlab.rb
修改备份目录和时间
gitlab_rails['backup_path'] = "/data/gitlab_bak/backups"
gitlab_rails['backup_keep_time'] = 2592000
设置备份过期时间//2592000 秒为单位,代表30天
定时任务
0 2 * * * /opt/gitlab/bin/gitlab-rake gitlab:backup:create > /dev/null 2>&1 &
4>遇到问题
注意1:一定要同版本迁移
注意2:安装时遇到redis无法正常启动问题,注意查看log并根据log提示进行处理,如log位置
/var/log/gitlab/redis/current
注意3:避免端口冲突注意修改端口,因为这台机器之前有nginx,所以将gitlab的nginx端口修改为8999,然后再在原有nginx上配置80跳8999访问
注意4:
迁移后之前的项目(迁移之前创建的项目)修改项目描述报错【新创建的项目不影响】
image.png
打开日志gitlab-ctl tail
image.png
修改gitlab配置报错500
image.png
日志报错
image.png
后查看得知这是gitlab迁移的bug
需要修改数据库
-bash-4.1# gitlab-rails dbconsole
psql (10.9)
Type "help" for help.
gitlabhq_production=> UPDATE projects SET runners_token = null, runners_token_encrypted = null;
UPDATE 21
gitlabhq_production=> UPDATE namespaces SET runners_token = null, runners_token_encrypted = null;
UPDATE 20
gitlabhq_production=> UPDATE application_settings SET runners_registration_token_encrypted = null;
UPDATE 1
gitlabhq_production=> UPDATE application_settings SET encrypted_ci_jwt_signing_key = null;
ERROR: column "encrypted_ci_jwt_signing_key" of relation "application_settings" does not exist
LINE 1: UPDATE application_settings SET encrypted_ci_jwt_signing_key...
^
gitlabhq_production=> UPDATE ci_runners SET token = null, token_encrypted = null;
UPDATE 0
gitlabhq_production=>
重启gitlab后生效,当然要跟你你的报错来修改数据库,我这边是 Reset runner registration tokens 重置了这块好的
具体参考
https://docs.gitlab.com/ee/raketasks/backup_restore.html#when-the-secrets-file-is-lost
gitlab升级
有漏洞需要升级,没有直接升级到大版本,而是小版本小版本升级
参考:
https://docs.gitlab.com/ee/update/index.html#upgrade-paths
yum -y install gitlab-ce-13.0.14 --nogpgcheck
yum -y install gitlab-ce-13.1.11 --nogpgcheck
yum -y install gitlab-ce-13.6.7 --nogpgcheck
升级完一个版本后进行测试,没问题再进行下一个版本
注意:
centos6的官网最高到gitlab-ce-13.6.7,centos7的可以到14版本
官网源地址:
https://packages.gitlab.com/app/gitlab/gitlab-ce/search?dist=ol%2F6&page=13
卸载
gitlab-ctl stop
rpm -e gitlab-ce
ps aux | grep gitlab
find / -name gitlab | xargs rm -rf
/opt/gitlab /etc/gitlab /var/opt/gitlab /var/log/gitlab
安装
yum -y install gitlab-ce-13.6.7 --nogpgcheck
启动
cd /etc/gitlab/
mv gitlab.rb /root
cp /backup/gitlab_bak/gitlab.rb.20220331 gitlab.rb
cat gitlab.rb |grep -v "#"|grep -v "^$"
gitlab-ctl reconfigure
登录修改密码
数据备份
gitlab-ctl stop unicorn
gitlab-ctl stop sidekiq
gitlab-rake gitlab:backup:create
ll /var/opt/gitlab/backups/
gitlab-ctl start
登录
恢复数据
gitlab-ctl stop unicorn
gitlab-ctl stop sidekiq
cd /var/opt/gitlab/backups/
cp -r /backup/gitlab_bak/backups/1648558919_2022_03_29_13.6.7_gitlab_backup.tar .
gitlab-rake gitlab:backup:restore BACKUP=1648558919_2022_03_29_13.6.7
gitlab-ctl start
postgresql数据恢复时报错
Restoring PostgreSQL database gitlabhq_production ... ERROR: must be owner of extension pg_trgm
ERROR: must be owner of extension btree_gist
ERROR: must be owner of extension btree_gist
ERROR: must be owner of extension pg_trgm
处理
$ vim /var/opt/gitlab/postgresql/data/postgresql.conf
listen_addresses = '*'
# 最下面新增两行
$ vim /var/opt/gitlab/postgresql/data/pg_hba.conf
local all all trust
host all all 127.0.0.1/32 trust
gitlab-ctl restart
$ su - gitlab-psql
$ /opt/gitlab/embedded/bin/psql -h 127.0.0.1 gitlabhq_production
psql (9.2.8)
Type "help" for help.
gitlabhq_production=# ALTER USER gitlab WITH SUPERUSER;
ALTER ROLE
gitlabhq_production=# \q
恢复数据参考
问题记录:刚开始500,后来502,gitlabctl reconfigure后报错如下,实在没找到原因重建恢复数据
报错信息
storage_directory[/var/opt/gitlab/.ssh](gitlab::gitlab-shell line 38)had an error:Mixlib::shellout::shellcommandfailed:
ruby_block[directory resource: /var/opt/gitlab/.ssh](/opt/gitlab/embedded/cookbooks/cache/cookbooks/package/resources/storage_directory.rb line 33) had an error:Mixlib::shellout::shellcommandfailed:Expected process to exit with [0] ,but received ‘1’
-------- begin output of stat --printf=’%U’ $(readlink -f /var/opt/gitlab/.ssh)------
stout:
stderr: stat:missing oprand
try stat --help
------- end output of stat --printf =’%U’ $(readlink -f /var/opt/gitlab/.ssh)-----
ran stat --print=’%U’ $(readlink -f /var/opt/gitlab/.ssh) returned 1
刚开始搜索全都是/var/opt/gitlab目录权限问题但是后来发现并不是而是当时我对/etc/passwd r权限锁紧导致
原因是系统切换时报错
/usr/bin/id: cannot find name for user ID 491
后来发现是/etc/passwd /etc/group没有r权限导致
一个小小的错误导致git无法访问了,记录一下
https://www.jianshu.com/p/09a2b0c25ecd
网友评论