• Gitlab服务器切换来版本升级,执行漏洞修复


    方案:
    1.背景
        由于GitLab13.5.5存在严重漏洞(CVE-2022-2884),现在需要升级到安全版本,但是现在服务器(正在使用的,以后都称老服务器)系统是redhat6,已不支持要升级到的版本,只能新建服务器重新安装GitLab,再按从小到大的版本依次升级。
        注意:高版本的Gitlab无法导入低版本备份的数据,因此需要在新服务器部署安装和老服务器一样版本的gitlab,部署好环境后开始备份和数据导入。
    2、提前完成的部分(需要在正式升级前,完成的,因为老服务器正在使用,不能随便停机,需要找个使用少的时间停机升级)
    2.1、在新服务器安装好GitLab:el7 13.5.5版本,下载安装包地址:https://mirrors.tuna.tsinghua.edu.cn/gitlab-ce/yum/el7/
        下载上传到linux服务器并执行如下命令开始安装:
        rpm -ivh gitlab-ce-13.5.5-ce.0.el7.x86_64.rpm
    2.1、确定要升级的版本
        根据官网给出的升级路径:
        8.11.Z-> 8.12.0-> 8.17.7-> 9.5.10-> 10.8.7-> 11.11.8-> 12.0.12-> 12.1.17-> 12.10.14-> 13.0.14-> 13.1.11-> 13.8.8-> 13.12.15-> 14.0.12-> 14.3.6-> 14.9.5-> 14.10.Z-> 15.0.Z->最新的15.Y.Z。
        结合我们当前的版本:13.5.5,可以得出如下升级路径:
        13.5.5-> 13.8.8-> 13.12.15-> 14.0.12-> 14.3.6-> 14.9.5-> 14.10.0-> 15.0.0->最新的15.3.1。一共需要升级8个版本
    2.2、将以上8个版本的安装包提前下载好并上传到新服务器的/home/目录下
    3、正式升级
       升级时间:本周周天(20220828)上午9点开始升级。
    3.1、将老服务器停掉
       sudo gitlab-ctl stop
    3.2、备份老服务器的GitLab数据
       备份前先停掉个别服务,如下:
       gitlab-ctl stop unicorn
       gitlab-ctl stop puma
       gitlab-ctl stop sidekiq
       执行命令,进行备份:gitlab-rake gitlab:backup:create 
       PS: 该命令可以备份gitlab仓库、数据库、用户、用户组、用户密钥、权限等信息,备份后的文件位于:/var/opt/gitlab/backups目录下。
    3.3、拷贝
       从老服务器上拷贝gitlab备份数据到新服务器上,在老服务器执行命令:
        scp /var/opt/gitlab/backups/1661328426_2022_08_24_13.5.5_gitlab_backup.tar root@新服务器ip:/var/opt/gitlab/backups
    3.4、将备份数据导入新安装的GitLab
       执行恢复操作前,需要先停止 unicorn 、 sidekiq、puma 服务
       gitlab-ctl stop unicorn
       gitlab-ctl stop puma
       gitlab-ctl stop sidekiq
       在新服务器执行如下命令,导入数据:
       cd /var/opt/gitlab/backups
       gitlab-rake gitlab:backup:restore BACKUP=1515132280_2018_01_05_9.5.6。
       PS:BACKUP的参数必须与原服务器备份后的文件名一致(其实是文件名的前缀,_gitlab_backup.tar不要)。
       如果没有权限需要先赋权:chmod 644 /var/opt/gitlab/backups/1661328426_2022_08_24_13.5.5_gitlab_backup.tar
    3.5、导入成功后,排查以下文件是否也被导入,未导入,手工复制新服务器对应目录下
       目路径下的/var/opt/gitlab/.ssh/authorized_keys 复制过去
       先备份新服务器上的文件,防止出问题,以便恢复,在新服务器执行:
       cp /var/opt/gitlab/.ssh/authorized_keys /var/opt/bak
       在老服务器执行:
       scp /var/opt/gitlab/.ssh/authorized_keys root@新服务器IP:/var/opt/gitlab/.ssh
       将如下两个文件也复制到新服务器,先备份,后覆盖即可,我是手工复制过去的,没有用命令    
       /etc/gitlab/gitlab-secrets.json 覆盖
       /etc/gitlab/gitlab.rb  覆盖
    3.6、登陆新地址确定数据完整性(以其中一个活多个工程,检查权限、代码、分支、提交记录是否完整)
    4、升级新服务器的GitLab版本
        update  dwat.app_svn_ser a set a.autoseal='h' where a.svnurl like '%.git' and a.autoseal='1'; 
    4.1、按计划好的版本依次升级,执行如下升级命令,每升级一个版本后,确认一下版本号是否为新升级的版本号:
       
       给公司人员发通知:现要修复GitLab bug(CVE-2022-2884),需要对GitLab版本升级,因此GitLab服务暂不可用。升级完成,会通知大家,请耐心等待。
       
       升级前同调部分服务器,防止有人使用,gitlab-ctl stop unicorn;gitlab-ctl stop puma;gitlab-ctl stop sidekiq
       
       进入安装包存放目录:
       cd /home
       查看GitLab版本号命令:
       cat /opt/gitlab/embedded/service/gitlab-rails/VERSION
       升级命令,一个个升级即可:
       升级后每个都要重启,登陆验证
       gitlab-ctl reconfigure;gitlab-ctl restart
       
       按以下顺序升级:
       1、wget https://mirrors.tuna.tsinghua.edu.cn/gitlab-ce/yum/el7/gitlab-ce-13.8.8-ce.0.el7.x86_64.rpm --no-check-certificate
       yum localinstall -y gitlab-ce-13.8.8-ce.0.el7.x86_64.rpm
       
       2、wget https://mirrors.tuna.tsinghua.edu.cn/gitlab-ce/yum/el7/gitlab-ce-13.12.15-ce.0.el7.x86_64.rpm --no-check-certificate
       yum localinstall -y gitlab-ce-13.12.15-ce.0.el7.x86_64.rpm
       
       查看psg版本,保证升级到12版本
       /opt/gitlab/embedded/bin/pg_ctl --version
       /opt/gitlab/embedded/bin/psql --version
       如果不是12,升级版本:
       gitlab-ctl pg-upgrade -v 12
       
       3、wget https://mirrors.tuna.tsinghua.edu.cn/gitlab-ce/yum/el7/gitlab-ce-14.0.12-ce.0.el7.x86_64.rpm --no-check-certificate
       yum localinstall -y gitlab-ce-14.0.12-ce.0.el7.x86_64.rpm
       
       gitlab-rake db:migrate
       
       
       4、wget https://mirrors.tuna.tsinghua.edu.cn/gitlab-ce/yum/el7/gitlab-ce-14.3.6-ce.0.el7.x86_64.rpm --no-check-certificate
       yum localinstall -y gitlab-ce-14.3.6-ce.0.el7.x86_64.rpm   

       #官方命令解决500的问题
       重复执行如下命令:
       gitlab-ctl reconfigure
       执行报错日志里已sudo gitlab-rake gitlab:background_migrations:finalize开头的命令,没重启一次,就会有一个新的,重复重启,重复执行
       直到:
       select job_class_name, table_name, column_name, job_arguments from batched_background_migrations where status <> 3; 为0行,或者reconfigure成功
       
       
       5、wget https://mirrors.tuna.tsinghua.edu.cn/gitlab-ce/yum/el7/gitlab-ce-14.9.5-ce.0.el7.x86_64.rpm --no-check-certificate
       yum localinstall -y gitlab-ce-14.9.5-ce.0.el7.x86_64.rpm
       
       6、wget https://mirrors.tuna.tsinghua.edu.cn/gitlab-ce/yum/el7/gitlab-ce-14.10.0-ce.0.el7.x86_64.rpm --no-check-certificate
       yum localinstall -y gitlab-ce-14.10.0-ce.0.el7.x86_64.rpm
       
       Mixlib::ShellOut::ShellCommandFailed: Command execution failed. STDOUT/STDERR suppressed for sensitive resource
       解决:
       sudo gitlab-rake db:migrate
       
       sudo gitlab-rake gitlab:background_migrations:finalize[ProjectNamespaces::BackfillProjectNamespaces,projects,id,'[null\,"up"]']

       gitlab-ctl restart
       
       7、wget https://mirrors.tuna.tsinghua.edu.cn/gitlab-ce/yum/el7/gitlab-ce-15.0.0-ce.0.el7.x86_64.rpm --no-check-certificate
       yum localinstall -y gitlab-ce-15.0.0-ce.0.el7.x86_64.rpm
       
       8、wget https://mirrors.tuna.tsinghua.edu.cn/gitlab-ce/yum/el7/gitlab-ce-15.3.1-ce.0.el7.x86_64.rpm --no-check-certificate
       yum localinstall -y gitlab-ce-15.3.1-ce.0.el7.x86_64.rpm 
       
    4.2、全部升级完后,登录确认数据完整性(以其中一个或几个工程为例,看一下权限、代码、分支、日志是否完整)
    4.3、设置定时任务,备份Gitlab数据
    4.4、将老ip和新服务器的ip互换
    4.5、重启GitLab,验证是否可用
    5.5、升级结束

  • 相关阅读:
    Java版工程行业管理系统源码-专业的工程管理软件-提供一站式服务
    dockerfile关键字
    抽象类和接口
    [附源码]JAVA毕业设计科院垃圾分类系统(系统+LW)
    kafka进阶核心原理详解:案例解析(第11天)
    unity快捷键
    MySQL高可用MHA
    【概率论基础进阶】多维随机变量及其分布-两个随机变量函数Z=g(X,Y)的分布
    Effective C++改善程序与设计的55个具体做法 3. 资源管理
    WEB ---- ctfshow ---- PHP特性
  • 原文地址:https://blog.csdn.net/qq_30938603/article/details/126666804