Gitlab升級記


一: 驗證gitlab備份是否可用

       這里所使用的操作系統環境全部都基於Cetnos7, 防火牆以及selinux全部關閉。

1. 另外找一台機器,安裝與服務器版本相同的gitlab,根據原服務器數據的大小,來決定驗證數據服務器磁盤的大小。避免因磁盤空間不足而無法正常恢復數據。

  •   配置yum源
shell> vi /etc/yum.repos.d/gitlab-ce.repo

[gitlab-ce]
name=Gitlab CE Repository
baseurl=https://mirrors.tuna.tsinghua.edu.cn/gitlab-ce/yum/el$releasever/
gpgcheck=0
enabled=1
  • 安裝指定版本
shell> yum install gitlab-ce-11.2.3
  • 將原服務器的配置文件拷貝至新部署的機器上,然后進行配置; 
 1 #這里是我的 配置文件,這里我們使用了Windows AD來作為LDAP服務器
 2 external_url 'http://gitlab.mofangge.cc'
 3 gitlab_rails['ldap_enabled'] = true
 4  gitlab_rails['ldap_servers'] = YAML.load <<-'EOS'
 5    main: # 'main' is the GitLab 'provider ID' of this LDAP server
 6      label: 'LDAP'
 7      host: 'domainserver.mofangge.cc'
 8      port: 389
 9      uid: 'sAMAccountName'
10      bind_dn: 'cn=gitadmin,cn=Users,dc=mofangge,dc=cc'
11      password: 'ling4022@163.com'
12      encryption: 'plain' # "start_tls" or "simple_tls" or "plain"
13      verify_certificates: true
14      active_directory: true
15      allow_username_or_email_login: true
16      lowercase_usernames: false
17      block_auto_created_users: false
18      base: 'OU=mofangge,DC=mofangge,DC=cc'
19      user_filter: ''
20      group_base: 'OU=mofangge,DC=mofangge,DC=cc'
21      sync_ssh_keys: false
22 EOS
23 gitlab_rails['manage_backup_path'] = true
24 gitlab_rails['backup_path'] = "/opt/data/backups"
25 gitlab_rails['backup_archive_permissions'] = 0644
26 gitlab_rails['backup_keep_time'] = 604800
27  git_data_dirs({
28    "default" => {
29      "path" => "/opt/data/git-data"
30     }
31  })
32 unicorn['worker_processes'] = 4
33 sidekiq['concurrency'] = 12
34 postgresql['shared_buffers'] = "1024MB"
35 postgresql['max_worker_processes'] = 8
我的配置文件,僅供參考
shell> grep -Ev "^$|^[#;]" /etc/gitlab/gitlab.rb
shell> scp root@youserverip:/etc/gitlab/gitlab.rb /etc/gitlab/ #然后輸入密碼即可
shell> gitlab-ctl reconfigure
shell> gitlab-ctl status
#然后這里將host 解析寫在wineos下的hosts文件中,訪問域名進行校驗
192.168.133.12  gitlab.mofangge.cc

然后進行登錄驗證,如果能正常訪問的話,接下來進行恢復工作

二: 恢復數據

將原備份文件拷貝到指定目錄下。

shell> scp root@192.168.200.27:/data/gitlabbackup/1589134406_2020_05_11_11.2.3_gitlab_backup.tar /opt/data/backups/
#由於我自定義了文件名稱,這里還需要重命名
shell> mv /opt/data/backups/1589134406_2020_05_11_11.2.3_gitlab_backup.tar /opt/data/backups/1589134406_gitlab_backup.tar
#查看驗證
shell> ls /opt/data/backups/
#進行恢復
shell> gitlab-rake gitlab:backup:restore BACKUP=1589134406
#重啟之后進行登錄驗證
shell> gitlab-ctl restart

這里登錄之后,查看數據以及配置均為正常。校驗數據沒有問題之后,進行升級的模擬操作。

三:進行升級

gitlab具有版本帝之稱,版本更新之快讓人望而卻步,由於我們想要適用gitlab ci等新功能,所以還是選擇進行升級。

這里我們可以參照官方建議的升級版本順序進行選擇,官方鏈接地址如:https://docs.gitlab.com/ee/policy/maintenance.html#upgrade-recommendations

建議安裝官方推薦的升級版本路徑進行升級,避免踩坑。

由於我目前的版本是11.2.3,這里我們先升級到11.11.8,然后升級到12.0.12,最后升級到現在的最新版本,12.10.3進行測試。希望能成功。

 這里我在准備虛擬機的階段已經將所需要的安裝包已經下載到本地了。接下來我們進行升級工作。

[root@c7-node2 ~]# ll
total 2492824
-rw-r--r-- 1 root root 664112883 May 11 15:10 gitlab-ce-11.11.8-ce.0.el7.x86_64.rpm  #第一次升級到的版本
-rw-r--r-- 1 root root 444946400 May 11 15:10 gitlab-ce-11.2.3-ce.0.el7.x86_64.rpm   #現在版本
-rw-r--r-- 1 root root 647345829 May 11 15:10 gitlab-ce-12.0.12-ce.0.el7.x86_64.rpm  #第二次升級到的版本
-rw-r--r-- 1 root root 796237830 May 11 15:11 gitlab-ce-12.10.3-ce.0.el7.x86_64.rpm  #需要升級的最終版本
[root@c7-node2 ~]# yum install gitlab-ce-11.11.8-ce.0.el7.x86_64.rpm
Loaded plugins: fastestmirror
Examining gitlab-ce-11.11.8-ce.0.el7.x86_64.rpm: gitlab-ce-11.11.8-ce.0.el7.x86_64
Marking gitlab-ce-11.11.8-ce.0.el7.x86_64.rpm as an update to gitlab-ce-11.2.3-ce.0.el7.x86_64
Resolving Dependencies
--> Running transaction check
---> Package gitlab-ce.x86_64 0:11.2.3-ce.0.el7 will be updated
---> Package gitlab-ce.x86_64 0:11.11.8-ce.0.el7 will be an update
--> Finished Dependency Resolution

Dependencies Resolved

====================================================================================================================================================================================
 Package                             Arch                             Version                                    Repository                                                    Size
====================================================================================================================================================================================
Updating:
 gitlab-ce                           x86_64                           11.11.8-ce.0.el7                           /gitlab-ce-11.11.8-ce.0.el7.x86_64                           1.5 G

Transaction Summary
====================================================================================================================================================================================
Upgrade  1 Package

Total size: 1.5 G
Is this ok [y/d/N]:

出現如下提示,則證明升級成功了。

sudo gitlab-ctl restart postgresql

gitlab Reconfigured!
Restarting previously running GitLab services
ok: run: alertmanager: (pid 20783) 1s
ok: run: gitaly: (pid 20597) 5s
ok: run: gitlab-monitor: (pid 20658) 4s
ok: run: gitlab-workhorse: (pid 20627) 5s
ok: run: logrotate: (pid 20806) 1s
ok: run: nginx: (pid 20812) 0s
ok: run: node-exporter: (pid 20647) 5s
ok: run: postgres-exporter: (pid 20796) 1s
ok: run: postgresql: (pid 1146) 6862s
ok: run: prometheus: (pid 20676) 3s
ok: run: redis: (pid 20325) 52s
ok: run: redis-exporter: (pid 20666) 4s
ok: run: sidekiq: (pid 20823) 1s
ok: run: unicorn: (pid 20830) 0s

     _______ __  __          __
    / ____(_) /_/ /   ____ _/ /_
   / / __/ / __/ /   / __ `/ __ \
  / /_/ / / /_/ /___/ /_/ / /_/ /
  \____/_/\__/_____/\__,_/_.___/
  

Upgrade complete! If your GitLab server is misbehaving try running
  sudo gitlab-ctl restart
before anything else.
If you need to roll back to the previous version you can use the database
backup made during the upgrade (scroll up for the filename).

  Verifying  : gitlab-ce-11.11.8-ce.0.el7.x86_64                                                                                                                                1/2 
  Verifying  : gitlab-ce-11.2.3-ce.0.el7.x86_64                                                                                                                                 2/2 

Updated:
  gitlab-ce.x86_64 0:11.11.8-ce.0.el7                                                                                                                                               

Complete!

然后進行登錄校驗,這里我依然使用LDAP賬戶進行登錄,因為我之前沒有standard賬戶,root下是沒有數據的。

然后繼續進行升級,這次升級到10.0.12版本,因為11.11.8是11的最后一個版本。也是升級的必須步驟。

 

[root@c7-node2 ~]# yum install gitlab-ce-12.0.12-ce.0.el7.x86_64.rpm -y
#這里出現的結果跟上次一樣,就證明升級成功
Upgrade complete! If your GitLab server is misbehaving try running
  sudo gitlab-ctl restart
before anything else.
If you need to roll back to the previous version you can use the database
backup made during the upgrade (scroll up for the filename).

  Verifying  : gitlab-ce-12.0.12-ce.0.el7.x86_64                                                                                                                                1/2 
  Verifying  : gitlab-ce-11.11.8-ce.0.el7.x86_64                                                                                                                                2/2 

Updated:
  gitlab-ce.x86_64 0:12.0.12-ce.0.el7                                                                                                                                               

Complete!

然后請繼續進行登錄和數據校驗。有任何一個過程出問題,就需要考慮回滾。 數據最重要。

接下來,我將升級到最新版本,12.10.3。

[root@c7-node2 ~]# yum install gitlab-ce-12.10.3-ce.0.el7.x86_64.rpm -y
Loaded plugins: fastestmirror
Examining gitlab-ce-12.10.3-ce.0.el7.x86_64.rpm: gitlab-ce-12.10.3-ce.0.el7.x86_64
Marking gitlab-ce-12.10.3-ce.0.el7.x86_64.rpm as an update to gitlab-ce-12.0.12-ce.0.el7.x86_64
Resolving Dependencies
--> Running transaction check
---> Package gitlab-ce.x86_64 0:12.0.12-ce.0.el7 will be updated
---> Package gitlab-ce.x86_64 0:12.10.3-ce.0.el7 will be an update
--> Finished Dependency Resolution

出現如下界面,則證明升級成功,最后也可以通過gitlab-ctl status進行驗證。

Upgrade complete! If your GitLab server is misbehaving try running
  sudo gitlab-ctl restart
before anything else.
If you need to roll back to the previous version you can use the database
backup made during the upgrade (scroll up for the filename).

  Verifying  : gitlab-ce-12.10.3-ce.0.el7.x86_64                                                                                                                                1/2 
  Verifying  : gitlab-ce-12.0.12-ce.0.el7.x86_64                                                                                                                                2/2 

Updated:
  gitlab-ce.x86_64 0:12.10.3-ce.0.el7                                                                                                                                               

Complete!
[root@c7-node2 ~]# gitlab-ctl status
run: alertmanager: (pid 17180) 13s; run: log: (pid 1707) 2186s
run: gitaly: (pid 16392) 62s; run: log: (pid 10965) 1559s
run: gitlab-exporter: (pid 17194) 13s; run: log: (pid 16224) 81s
run: gitlab-workhorse: (pid 17196) 12s; run: log: (pid 11313) 1525s
run: grafana: (pid 17209) 12s; run: log: (pid 11359) 1500s
run: logrotate: (pid 17221) 11s; run: log: (pid 1699) 2186s
run: nginx: (pid 17228) 11s; run: log: (pid 1703) 2186s
run: node-exporter: (pid 17237) 11s; run: log: (pid 1697) 2186s
run: postgres-exporter: (pid 17242) 10s; run: log: (pid 1705) 2186s
run: postgresql: (pid 15614) 162s; run: log: (pid 1676) 2186s
run: prometheus: (pid 17250) 10s; run: log: (pid 1709) 2186s
run: redis: (pid 15956) 152s; run: log: (pid 1670) 2186s
run: redis-exporter: (pid 17264) 9s; run: log: (pid 1693) 2186s
run: sidekiq: (pid 17270) 9s; run: log: (pid 11303) 1526s
run: unicorn: (pid 12625) 1299s; run: log: (pid 1688) 2186s

最后給大家來一張升級成功的圖片,以示鼓勵。加油~~

 

接下來大家可以在服務器端進行升級操作,如果服務器是虛擬機的話,建議先做快照,以便出問題時進行恢復,一定要做備份,數據最重要。


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM