1、服务器环境信息
旧Gitlab:192.168.2.199
新Gitlab:192.168.2.200
2、在新服务器安装相同版本的Gitlab
注意:新服务器gitlab版本也需要和旧版本一致。
1)查看原Gitlab版本号
[root@localhost ~]# cat /opt/gitlab/embedded/service/gitlab-rails/VERSION
16.2.4
2)安装Gitlab 16.2.4
[root@node_192 ~]# wget https://mirrors.tuna.tsinghua.edu.cn/gitlab-ce/yum/el7/gitlab-ce-16.2.4-ce.0.el7.x86_64.rpm
[root@node_192 ~]# yum -y install gitlab-ce-16.2.4-ce.0.el7.x86_64.rpm
3、备份原Gitlab数据
1)备份配置文件gitlab.rb和gitlab-secrets.json
注意:/etc/gitlab/gitlab-secrets.json文件,此文件中包含数据库加密密钥,CI/CD变量以及双因子认证等变量信息,如果在GitLab中使用到此部分内容,必须进行此文件的手动恢复。
[root@localhost ~]# scp /etc/gitlab/gitlab.rb root@192.168.2.200:/etc/gitlab/
[root@node_192 ~]# gitlab-ctl reconfigure
2)数据备份
[root@localhost ~]# gitlab-rake gitlab:backup:create
3)传输备份到新服务器
[root@node_192 ~]# mkdir -p /var/opt/gitlab/backups
[root@localhost ~]# scp /var/opt/gitlab/backups/1725431200_2024_09_04_16.2.4_gitlab_backup.tar root@192.168.2.200:/var/opt/gitlab/backups/
[root@node_192 ~]# chmod 777 /var/opt/gitlab/backups/1725431200_2024_09_04_16.2.4_gitlab_backup.tar
4、还原Gitlab数据
1)停止unicorn和sidekiq服务,puma服务
[root@node_192 ~]# gitlab-ctl stop nginx
ok: down: nginx: 0s, normally up
[root@node_192 ~]# gitlab-ctl stop puma
ok: down: puma: 0s, normally up
[root@node_192 ~]# gitlab-ctl stop unicorn
[root@node_192 ~]# gitlab-ctl stop sidekiq
ok: down: sidekiq: 0s, normally up
2)恢复数据
[root@node_192 ~]# gitlab-rake gitlab:backup:restore BACKUP=1725431200_2024_09_04_16.2.4
3)替换gitlab-secrets.json文件
[root@localhost ~]# scp /etc/gitlab/gitlab-secrets.json root@192.168.2.200:/etc/gitlab/
4)重启Gitlab
[root@node_192 ~]# gitlab-ctl restart
ok: run: gitaly: (pid 18473) 0s
ok: run: gitlab-exporter: (pid 18514) 0s
ok: run: gitlab-kas: (pid 18535) 0s
ok: run: gitlab-workhorse: (pid 18542) 0s
ok: run: logrotate: (pid 18557) 1s
ok: run: nginx: (pid 18563) 0s
ok: run: postgresql: (pid 18582) 1s
ok: run: puma: (pid 18607) 0s
ok: run: redis: (pid 18636) 0s
ok: run: sidekiq: (pid 18643) 1s
5)访问Gitlab
# 浏览器输入http://192.168.2.200,如下图所示
至此,Gitlab恢复完成。
若文章图片、下载链接等信息出错,请在评论区留言反馈,博主将第一时间更新!如本文“对您有用”,欢迎随意打赏,谢谢!
评论