CentOS上迁移GitLab的核心步骤如下:
备份数据
使用GitLab备份工具生成备份文件,存储至/var/opt/gitlab/backups
目录:
sudo gitlab-rake gitlab:backup:create
(若需备份数据库,需额外执行pg_dump
命令导出PostgreSQL数据)。
准备新服务器
sudo yum install -y curl policycoreutils openssh-server postfix
sudo systemctl enable --now sshd postfix
安装GitLab
通过Omnibus包安装,指定外部URL(可选):
curl https://packages.gitlab.com/install/repositories/gitlab/gitlab-ce/script.rpm.sh | sudo bash
sudo yum install gitlab-ce
sudo vim /etc/gitlab/gitlab.rb # 设置 external_url(如 'http://新服务器IP')
sudo gitlab-ctl reconfigure
sudo gitlab-ctl restart
恢复数据
scp -r old-server:/var/opt/gitlab/backups /var/opt/gitlab/
sudo gitlab-ctl stop unicorn sidekiq
sudo gitlab-rake gitlab:backup:restore BACKUP=备份文件名(不含路径)
sudo gitlab-ctl start
验证迁移
访问新服务器的GitLab URL,检查用户、项目、CI/CD配置是否正常,确认无报错。
注意事项: