how to migrate Gitlab to a new server

2017-12-13 15:05:49

gitlab安装有三种方法: docker、yum 、源码,本文环境是yum安装方式
1.确认旧gitlab版本信息

1
sudo gitlab-rake gitlab:env:info

注意: 新服务版本要求保持一致,否则无法导入,如果版本比较旧,需要升级旧版本服务器或新服务版本降级后在升级
旧服务器升级也比较简单

1
2
3
4
5
6
7
8
#stop some service
sudo gitlab-ctl stop unicorn
sudo gitlab-ctl stop sidekiq
sudo gitlab-ctl stop nginx
#update
sudo yum update gitlab-ce
sudo gitlab-ctl reconfigure
sudo gitlab-ctl restart

2.备份配置文件和数据
将 /etc/gitlab/gitlab.rb 和 gitlab-secrets.json 拷贝到新服务对应目录
注意,我旧环境是用了自带的nginx,新环境用了机器上已经存在的nginx

1
2
3
4
5
6
7
8
9
10
11
#disable nginx service
vi /etc/gitlab/gitlab.rb...#设置nginx为false,关闭自带Nginxnginx[‘enable‘] = false...

#check nginx config,migrate to new nginx
/var/opt/gitlab/nginx/conf/nginx.conf
/var/opt/gitlab/nginx/conf/gitlab-http.conf
/var/opt/gitlab/nginx/conf/nginx-status.conf

#restart service
sudo gitlab-ctl reconfigure
sudo service nginx restart

备份旧机器git数据,同时拷贝到新服务上

1
2
#backup gitlab to  /var/opt/gitlab/backups
gitlab-rake gitlab:backup:create

在新机器上恢复数据

1
gitlab-rake gitlab:backup:restore RAILS_ENV=production   BACKUP=1513135372_2017_12_13

如果新机器数据不全,可以把/var/opt/gitlab/git-data拷贝过去

3.迁移遇到的问题

  • 在新机器执行gitlab-ctl reconfigure,查看进程ps -ef|grep nginx

    1
    2
    3
    4
    5
    6
    7
    root 11485 0.0 0.0 1836 608 ? Ss Mar18 0:02 runsvdir -P /opt/gitlab/service log: 
    …..runsv nginx: warning: unable to open supervise/stat.new:
    file does not exist runsv nginx: warning: unable to open supervise/stat.new:
    file does not exist runsv nginx: warning: unable to open supervise/pid.new:
    file does not exist runsv nginx: warning: unable to open log/supervise/pid.new:
    file does not exist runsv nginx: warning: unable to open log/supervise/pid.new:
    file does not exist

    解决方法: 重启系统解决

  • 查看nginx日志报错

    1
    2017/12/13 13:19:00 [crit] 2436#0: *2 connect() to unix:/var/opt/gitlab/gitlab-workhorse/socket failed (13: Permission denied) while connecting to upstream, client: 119.6.3.75, server: gitlab.weishao.com.cn, request: "GET /index.html HTTP/1.1", upstream: "http://unix:/var/opt/gitlab/gitlab-workhorse/socket:/index.html", host: "59.110.114.10"

    解决方法: 由于旧服务nginx使用git启动nginx,新服务器用nobody用户运行nginx,我们通过修改 /etc/gitlab/gitlab.rb文件解决

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    ##! When bundled nginx is disabled we need to add the external webserver user to
    ##! the GitLab webserver group.
    web_server['external_users'] = ['nobody']
    web_server['username'] = 'nobody'
    web_server['group'] = 'nobody'
    web_server['uid'] = 99
    web_server['gid'] = 99
    web_server['shell'] = '/bin/false'
    web_server['home'] = '/var/opt/gitlab/nginx'

    sudo gitlab-ctl reconfigure

    也可以将nginx运行账号添加到gitlab-www组中

    1
    2
    sudo usermod -a -G gitlab-www nobody
    sudo service nginx restart

    但是执行sudo gitlab-ctl reconfigure后需要重新执行

ref
Gitlab安装配置及使用