准备工作

GitLab社区版不支持直接跨版本升级,需按照官方指南一步步向上升级,若版本越旧,需要跨的版本就越多
官方建议的升级路线:
9.1.1 -> 9.5.10 -> 10.8.7 -> 11.11.x -> 12.5.x

  1. 准备RPM包

    ls -l /opt/install
    -rw-r--r-- 1 root root 420274392 Jun  7  2018 gitlab-ce-10.8.4-ce.0.el7.x86_64.rpm
    -rw-r--r-- 1 root root 664112883 Aug 13 04:15 gitlab-ce-11.11.8-ce.0.el7.x86_64.rpm
    -rw-r--r-- 1 root root 436290955 Oct  6  2018 gitlab-ce-11.3.4-ce.0.el7.x86_64.rpm
    -rw-r--r-- 1 root root 720287583 Nov 28 05:13 gitlab-ce-12.5.2-ce.0.el7.x86_64.rpm
    -rw-r--r-- 1 root root 299974191 Nov 28 13:40 gitlab-ce-9.1.1-ce.0.el7.x86_64.rpm
    -rw-r--r-- 1 root root 399200697 Nov  9  2017 gitlab-ce-9.5.10-ce.0.el7.x86_64.rpm
  2. 升级前备份

    /opt/gitlab/bin/gitlab-rake gitlab:backup:create
    
    ls /data/gitlab_back/
    
    /data/gitlab_back/1574881724_2019_11_28_gitlab_backup.tar

异机恢复演练

  1. 备份机器环境准备
    安装gitlab 9.1.1 备份目录配置好,部署方式略
    gitlab-ctl status
    
    run: gitaly: (pid 1013) 3053s; run: log: (pid 1012) 3053s
    run: gitlab-monitor: (pid 1030) 3053s; run: log: (pid 1029) 3053s
    run: gitlab-workhorse: (pid 1023) 3053s; run: log: (pid 1022) 3053s
    run: logrotate: (pid 1011) 3053s; run: log: (pid 1010) 3053s
    run: nginx: (pid 1025) 3053s; run: log: (pid 1024) 3053s
    run: node-exporter: (pid 1017) 3053s; run: log: (pid 1016) 3053s
    run: postgres-exporter: (pid 1033) 3053s; run: log: (pid 1032) 3053s
    run: postgresql: (pid 991) 3053s; run: log: (pid 990) 3053s
    run: prometheus: (pid 1020) 3053s; run: log: (pid 1018) 3053s
    run: redis: (pid 1004) 3053s; run: log: (pid 1003) 3053s
    run: redis-exporter: (pid 1043) 3053s; run: log: (pid 1042) 3053s
    run: sidekiq: (pid 1015) 3053s; run: log: (pid 1014) 3053s
    run: unicorn: (pid 1028) 3053s; run: log: (pid 1019) 3053s
    全部run 就OK了
  1. 拷贝备份到测试机的备份目录
    将备份文件权限修改为777,不然可能恢复的时候会出现权限不够,不能解压的问题

    chmod 777 /data/gitlab_back/1574881724_2019_11_28_gitlab_backup.tar
  2. 关停相关数据连接服务

    gitlab-ctl stop unicorn
    gitlab-ctl stop sidekiq
  3. 执行命令从备份文件中恢复Gitlab

    gitlab-rake gitlab:backup:restore BACKUP=备份文件编号
    
    # 例如我们的备份文件的编号是1574881724_2019_11_28,因此执行下面的命令即可恢复gitlab
    
    gitlab-rake gitlab:backup:restore BACKUP=1574881724_2019_11_28
    
    Unpacking backup ... done
    Before restoring the database we recommend removing all existing
    tables to avoid future upgrade problems. Be aware that if you have
    custom tables in the GitLab database these tables and all data will be
    removed.
    
    Do you want to continue (yes/no)? 
    
    # 选 yes 继续
    
    ....
    
     * datamgt/hiveUdf ... [DONE]
     * jmgj_flutter/credit_react ... [DONE]
     * kylin/kylin-baymax ... [DONE]
     * linzhenhua/ChannelManager-client ... [DONE]
     * mengyan/eagle ... [DONE]
     * kylin/kylin-reward ... [DONE]
     * huangyibin/p-test-docs ... [DONE]
     * kylin/kylin-ppcode ... [DONE]
     * jmgj-cube/register ... [DONE]
     * front-cube/register ... [DONE]
     * front-cube/pos-react ... [DONE]
     * pokeball/zhaocaiwa/frog-activity ... [DONE]
     * ironman/ironman-template/webpack ... [DONE]
     * eam/devops-tools-platform ... [DONE]
     * kylin/kylin-common-activity ... [DONE]
     * kylin/kylin-user-feature ... [DONE]
     * kidney/pocket-pfriend-vote ... [DONE]
    Put GitLab hooks in repositories dirs [DONE]
    done
    Restoring uploads ... 
    done
    Restoring builds ... 
    done
    Restoring artifacts ... 
    done
    Restoring pages ... 
    done
    Restoring lfs objects ... 
    done
    This will rebuild an authorized_keys file.
    You will lose any data stored in authorized_keys file.
    Do you want to continue (yes/no)? 
    
    # 选择 yes 继续
    
    ....................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................
    Deleting tmp directories ... done
    done
    done
    done
    done
    done
    done
    done
    
  4. 启动gitlab

    gitlab-ctl start
    
    ok: run: gitaly: (pid 1013) 7961s
    ok: run: gitlab-monitor: (pid 1030) 7961s
    ok: run: gitlab-workhorse: (pid 1023) 7961s
    ok: run: logrotate: (pid 18020) 760s
    ok: run: nginx: (pid 1025) 7961s
    ok: run: node-exporter: (pid 1017) 7961s
    ok: run: postgres-exporter: (pid 1033) 7961s
    ok: run: postgresql: (pid 991) 7961s
    ok: run: prometheus: (pid 1020) 7961s
    ok: run: redis: (pid 1004) 7961s
    ok: run: redis-exporter: (pid 1043) 7961s
    ok: run: sidekiq: (pid 21648) 0s
    ok: run: unicorn: (pid 21651) 1s

    以IP方式打开页面,访问看到内容一致
    使用git cli git clone、fetch、push等等测试通过即可

升级

  1. 关闭GitLab核心服务
    
    gitlab-ctl stop unicorn
    gitlab-ctl stop nginx
    gitlab-ctl stop sidekiq
    
    # 或者
    # for i in unicorn sidekiq nginx; do gitlab-ctl stop $i; done 
    

2.升级

rpm -Uvh gitlab-ce-9.5.10-ce.0.el7.x86_64.rpm

...
    - restart service service[gitaly]
Recipe: gitlab::gitlab-workhorse
  * service[gitlab-workhorse] action restart
    - restart service service[gitlab-workhorse]
Recipe: gitlab::gitlab-monitor
  * service[gitlab-monitor] action restart
    - restart service service[gitlab-monitor]
Recipe: gitlab::prometheus
  * service[prometheus] action restart
    - restart service service[prometheus]

Running handlers:
Running handlers complete
Chef Client finished, 65/477 resources updated in 01 minutes 03 seconds
gitlab Reconfigured!
Checking for an omnibus managed postgresql: OK
Checking if we already upgraded: OK
The latest version 9.6.3 is already running, nothing to do
Ensuring PostgreSQL is updated: OK
Restarting previously running GitLab services
ok: run: gitaly: (pid 4021) 3s
ok: run: gitlab-monitor: (pid 4055) 2s
ok: run: gitlab-workhorse: (pid 4042) 2s
ok: run: logrotate: (pid 4086) 0s
ok: run: node-exporter: (pid 4127) 1s
ok: run: postgres-exporter: (pid 4133) 0s
ok: run: postgresql: (pid 3382) 68s
ok: run: prometheus: (pid 4063) 2s
ok: run: redis: (pid 3390) 68s
ok: run: redis-exporter: (pid 4143) 0s

Upgrade complete! If your GitLab server is misbehaving try running

   sudo gitlab-ctl restart
...

## 升级成功,启动服务进行验证

gitlab-ctl restart
  1. 重复上述步骤,直至目标的12.5.x版本

可能的报错

部分CentOS版本较低未自带policycoreutils-python组件可能无法升级至10.x,需要手动

yum -y install policycoreutils-python

gitlab使用webhook向jenkins发送请求,报错 Requests to the local network are not allowed

官方给出解释
大致意思 gitlab 10.6 版本以后为了安全,不允许向本地网络发送webhook请求,如果想向本地网络发送webhook请求,则需要使用管理员帐号登录,默认管理员帐号是admin@example.com,密码就是你gitlab搭建好之后第一次输入的密码,登录之后, 点击Configure Gitlab ,如下图所示
image

即可进入Admin area,在Admin area中,在settings标签下面,找到OutBound Request,勾选上Allow requests to the local network from hooks and services ,保存更改即可解决问题
image


 目录