gitlab服务器迁移

以下操作在ubuntu 20.04上进⾏:

⼀、下载GitLab软件包

如果要做数据迁移,需要安装相同版本的GitLab。

查看GitLab版本:  cat /opt/gitlab/embedded/service/gitlab-rails/VERSION

下载地址:  https://packages.gitlab.com/gitlab/gitlab-ce

这⾥选择和原始服务器上相同版本,  gitlab-ce_14.8.2-ce.0_amd64.deb

wget --content-disposition https://packages.gitlab.com/gitlab/gitlab-ce/packages/debian/bullseye/gitlab-ce_14.8.2-ce.0_amd64.deb/download.deb

⼆、安装GitLab

dpkg -i gitlab-ce_14.8.2-ce.0_amd64.deb

三、配置GitLab

配置访问IP和端⼝

配置文件在/etc/gitlab/gitlab.rb

external_url 'http://127.0.0.1:8099'

   配置⽣效

gitlab-ctl stop     //停⽌服务

gitlab-ctl reconfigure //重新加载配置

   修改root密码

#通过命令⾏进入gitlab控制台

gitlab-rails console

#查找⽤户,如果有则会返回其id,并将对象赋值给u

u = User.where(username: 'root').first

#修改密码

u.password = 'xxxxx'

u.password_confirmation = 'xxxxx'

#保存密码修改 ,返回true则说明修改成功,再输入exit退出控制台

u.save!

#退出控制

exit

四、数据迁移

   导出数据

在原gitlab服务器上执⾏

cd /var/opt/gitlab/backups

gitlab-rake gitlab:backup:create

   导入数据

在新服务器上执⾏

cd /var/opt/gitlab/backups

scp -r root@原服务器ip:/var/opt/gitlab/backups/1658368484_2022_07_21_14.8.2_gitlab_ backup.tar .

#增加执⾏权限

chmod 777 1658368484_2022_07_21_14.8.2_gitlab_backup.tar

#停⽌相关数据连接服务

gitlab-ctl stop unicorn

gitlab-ctl stop sidekiq

#导入数据

gitlab-rake gitlab:backup:restore BACKUP=1658368484_2022_07_21_14.8.2 #启动相关数据连接服务

gitlab-ctl start

五、数据验证

登录http://新服务器ip:8099/查看数据是否迁移成功

⽤户、密码同原服务器;

本地代码⽬录⾥修改 .git/config,把ip改为新服务器ip

测试代码拉取、提交

额外Gitlab 迁移后删除 修改项目500报错解决

#使用下面命令动态打印日志,删除project,看看会报啥错

gitlab-ctl tail

报错如下:

lib/gitlab/crypto_helper.rb:28:in `aes256_gcm_decrypt'

app/models/concerns/token_authenticatable_strategies/encryption_helper.rb:18:in `decrypt_token'

解决:

进入cmd控制台用这个即可: gitlab-psql -d gitlabhq_production  (或者sudo gitlab-rails dbconsole --database main 也能进但要点时间)

清除掉token即可。

## Clear project tokens

UPDATE projects SET runners_token = null, runners_token_encrypted = null;

## Clear group tokens

UPDATE namespaces SET runners_token = null, runners_token_encrypted = null;

## Clear instance tokens

UPDATE application_settings SET runners_registration_token_encrypted = null;

## Clear key used for JWT authentication

## This may break the $CI_JWT_TOKEN job variable:

## https://gitlab.com/gitlab-org/gitlab/-/issues/325965

UPDATE application_settings SET encrypted_ci_jwt_signing_key = null;

## Clear runner tokens

UPDATE ci_runners SET token = null, token_encrypted = null;

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

李庆政370

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值