Ubuntu环境下GitLab迁移完整指南
curl、openssh-server等基础依赖。/var/opt/gitlab/backups目录。sudo gitlab-rake gitlab:backup:create
gitlab.rb(主配置文件)和gitlab-secrets.json(敏感信息如数据库密码、SSH密钥),防止配置丢失。sudo cp /etc/gitlab/gitlab.rb /path/to/backup/
sudo cp /etc/gitlab/gitlab-secrets.json /path/to/backup/
sudo gitlab-ctl stop unicorn
sudo gitlab-ctl stop sidekiq
sudo gitlab-ctl stop nginx
curl https://packages.gitlab.com/install/repositories/gitlab/gitlab-ce/script.deb.sh | sudo bash
EXTERNAL_URL设置访问域名或IP:sudo apt-get install gitlab-ce
sudo EXTERNAL_URL="http://your-new-gitlab-ip" apt-get install gitlab-ce
/var/opt/gitlab/backups下的.tar文件)和配置文件复制到新服务器的对应目录:scp /var/opt/gitlab/backups/*.tar user@new-server:/var/opt/gitlab/backups/
scp /path/to/backup/gitlab.rb user@new-server:/etc/gitlab/
scp /path/to/backup/gitlab-secrets.json user@new-server:/etc/gitlab/
# 新服务器上创建数据库(名称需与原服务器一致,如gitlabhq_production)
sudo -u postgres createdb gitlabhq_production
# 导入备份的SQL文件
sudo -u postgres psql gitlabhq_production < /var/opt/gitlab/backups/gitlab-backup.sql
sudo chown git:git /var/opt/gitlab/backups/*.tar # 确保备份文件属主正确
sudo gitlab-rake gitlab:backup:restore BACKUP=2025-09-20-12-00-00 # 替换为实际备份文件名
sudo rsync -avz /var/opt/gitlab/repositories/ user@new-server:/var/opt/gitlab/
sudo rsync -avz /var/opt/gitlab/shared/ user@new-server:/var/opt/gitlab/
/etc/gitlab/gitlab.rb,根据新环境调整以下关键配置:external_url 'http://your-new-gitlab-ip' # 设置访问URL
gitlab_rails['gitlab_shell_ssh_port'] = 22 # SSH端口(若未修改则保持默认)
gitlab_rails['gitlab_shell_ssh_host'] = 'your-new-gitlab-ip' # SSH主机地址
reconfigure命令应用配置变更,生成新的服务配置文件:sudo gitlab-ctl reconfigure
sudo gitlab-ctl start
sudo gitlab-ctl enable
EXTERNAL_URL(如http://your-new-gitlab-ip),确认能正常登录。scp(加密传输)或rsync over SSH,避免数据泄露。通过以上步骤,可实现Ubuntu环境下GitLab实例的安全迁移,确保数据与配置的完整性。迁移过程中如遇问题,可参考GitLab官方文档或寻求专业技术支持。