gitlab舊版本經(jīng)常會曝出一些遠程代碼執(zhí)行漏洞,需要升級到安全版本憔购,這里記錄一下rpm升級操作步驟嚎京,其他方式比如yum安裝的gitlab可以參考官網(wǎng)說明:
1.gitlab不允許直接跨大版本升級本冲,需要先升級到當前大版本的最后一個小版本,然后再升級下一個大版本的第一個小版本饿悬,
? 比如:11.0.x -> 11.11.x -> 12.0.x -> 12.10.x -> 13.0.x
2.下載對應(yīng)版本的RPM包,下載地址:https://packages.gitlab.com/gitlab/gitlab-ce聚霜,例如gitlab-ce-13.9.7-ce.0.el7.x86_64上傳到
3.停止當前的gitlab進程狡恬,執(zhí)行以下命令:
? gitlab-ctl stop puma
? gitlab-ctl stop sidekiq
? gitlab-ctl stop nginx
4.rpm -Uvh gitlab-ce-13.9.7-ce.0.el7.x86_64
5.一般而言RPM升級結(jié)束后會自動重啟gitlab,可以使用命令gitlab-ctl status查看蝎宇,所有子進程都為run狀態(tài)則說明重啟成功弟劲。如果有部分子進程沒有重啟,則手動執(zhí)行以下命令重啟:
? gitlab-ctl restart
======================== gitlab 升級后500解決辦法 ========================
升級以后如果訪問出現(xiàn)500頁面姥芥,可能是數(shù)據(jù)庫關(guān)系遷移失敗導(dǎo)致的:
1.執(zhí)行 gitlab-rake db:migrate:status 查看兔乞,如果有down狀態(tài)的,則執(zhí)行步驟2
2.gitlab-rake db:migrate 升級數(shù)據(jù)庫關(guān)系
3.重復(fù)步驟1凉唐,如果全部up庸追,則執(zhí)行 gitlab-ctl reconfigure
========================?13.9.7升級14.8.4排坑 =======================
1.按照之前的方式,下載了13.12.15台囱、14.0.0和14.8.4的包淡溯,依次升級到14.8.4后reconfigure報錯
2.此時先修改gitlab.rb中g(shù)itlab_rails[auto_migrate]配置項為false(否則無法reconfigure成功,則無法回退版本)
3.執(zhí)行reconfigure成功后玄坦,執(zhí)行rpm -Uvh --oldpackage回退到14.0.0版本血筑,此時訪問500
4.執(zhí)行g(shù)itlab-rake db:migrate:status 發(fā)現(xiàn)有很多down的任務(wù),執(zhí)行g(shù)itlab-rake db:migrate煎楣,然后reconfigure豺总,訪問正常
5.升級到14.8.4后執(zhí)行g(shù)itlab-rake db:migrate時出現(xiàn)錯誤關(guān)鍵字CopyColumnUsingBackgroundMigrationJob,
在官網(wǎng)查看得到結(jié)果(https://docs.gitlab.com/ee/user/admin_area/monitoring/background_migrations.html#database-migrations-failing-because-of-batched-background-migration-not-finished)
發(fā)現(xiàn)有以下幾句:
Instances running 14.0.0 - 14.0.4 should not upgrade directly to GitLab 14.2 or later, because of batched background migrations.
Upgrade first to either:
14.0.5 or a later 14.0.Z patch release.
14.1.0 or a later 14.1.Z patch release.
Batched background migrations need to finish before you update to a later version and may take longer than usual.
于是知道需要先升級到14.0.5择懂,并且需要在升級前完成所有的后臺數(shù)據(jù)遷移任務(wù)
繼續(xù)查看升級到14.2.X的說明喻喳,也進一步證實這點
6.于是下載14.0.5和14.2.0的包,先升級到14.0.5困曙,然后有以下兩種方式查看后臺遷移任務(wù)是否完成:
用管理員賬號登錄gitlab表伦,點擊Menu -> Admin -> Monitoring > Background Migrations. 查看后臺遷移任務(wù)狀態(tài)
執(zhí)行g(shù)itlab-rails dbconsole命令谦去,然后select * from batched_background_migrations where status <> 3;
7.如果所有后臺遷移任務(wù)都完成,則繼續(xù)升級到14.2.0
8.等待一天發(fā)現(xiàn)14.0.5有一個events表的后臺遷移任務(wù)仍然無法結(jié)束蹦哼,根據(jù)文檔使用以下命令嘗試手動結(jié)束任務(wù)
gitlab-rake gitlab:background_migrations:finalize[CopyColumnUsingBackgroundMigrationJob,events,id,'[["id"]\, ["id_convert_to_bigint"]]']
結(jié)果命令無法識別鳄哭,發(fā)現(xiàn)這是14.1的命令,于是嘗試先升級到14.1.0
9.升級到14.1.0后纲熏,使用步驟8命令停止后臺遷移進程成功妆丘,使用步驟6方法連接db,
執(zhí)行select * from batched_background_migrations where job_class_name = 'CopyColumnUsingBackgroundMigrationJob'局劲,發(fā)現(xiàn)events任務(wù)狀態(tài)為3(結(jié)束)
10.升級到14.8.4成功
總結(jié):
第一步:13.9.7 -> 13.12.15 -> 14.0.0
第二步:14.0.0 -> 14.1.0勺拣,等待后臺遷移任務(wù)(這一步耗時較長,可能需要幾個小時鱼填,但是務(wù)必等待大部分任務(wù)結(jié)束药有,否則可能需要回退版本再次等待,回退版本命令 rpm -Uvh --oldpackage gitlab-xxx.rpm)
第三步:如果有后臺遷移任務(wù)卡住無法結(jié)束苹丸,則使用gitlab-rake gitlab:background_migrations:finalize手動結(jié)束愤惰,gitlab-rake db:migrate:status查看是否有down狀態(tài)任務(wù),有則需要gitlab-rake db:migrate和reconfigure
第四步:14.1.0 -> 14.8.4