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配置是否正常,確認無報錯。
注意事項: