sameersbn/gitlab9.3.5升级gitlab-ce14.3.4

王书宸 2021年11月5日09:08:02
评论
2713 10600字

因为之前没有接触过gitlab,现在有一台版本比较低的sameersbn/gitlab9.3.5需要升级,由于网上可查的资料有限,所以我打算把sameersbn/gitlab迁移为gitlab-ce14.3.4版本,以下是迁移升级过程以及遇到的问题。

准备

目前版本:9.3.5
要升级到:14.3.4
升级过程,需要9个中间版本

升级1:9.3.5-ce.0->9.5.10-ce.0
升级2:9.5.10-ce.0->10.8.7-ce.0
升级3:10.8.7-ce.0->11.11.8-ce.0
升级4:11.11.8-ce.0->12.10.14-ce.0
升级5:12.10.14-ce.0->13.0.14-ce.0
升级6:13.0.14-ce.0->13.9.7-ce.0
升级7:13.9.7-ce.0->13.12.11-ce.0
升级8:13.12.11-ce.0->14.0.10-ce.0
升级9:14.0.10-ce.0->14.3.4-ce.0

root@wscyun:/home/wscyun# docker images 
REPOSITORY                         TAG             IMAGE ID       CREATED         SIZE
gitlab/gitlab-ce                   14.3.4-ce.0     9601b36495ba   6 days ago      2.29GB
gitlab/gitlab-ce                   14.0.10-ce.0    9b85f67002bb   2 months ago    2.21GB
gitlab/gitlab-ce                   13.12.11-ce.0   5ac99566c971   2 months ago    2.25GB
gitlab/gitlab-ce                   13.9.7-ce.0     e4646cbed65c   6 months ago    2.21GB
gitlab/gitlab-ce                   13.0.14-ce.0    c5b3d9743731   14 months ago   1.82GB
gitlab/gitlab-ce                   12.10.14-ce.0   e4e2cab224d6   16 months ago   2GB
gitlab/gitlab-ce                   11.11.8-ce.0    1e938af658a7   2 years ago     1.86GB
gitlab/gitlab-ce                   10.8.7-ce.0     fbd8a7cae3e0   3 years ago     1.48GB
gitlab/gitlab-ce                   9.5.10-ce.0     62e9c4e492d8   3 years ago     1.42GB
gitlab/gitlab-ce                   9.3.5-ce.0      b3f3aa1a4b41   4 years ago     1.28GB

 

备份sameersbn/gitlab9.3.5

root@git:/# gitlab-rake gitlab:backup:create

 

部署新的gitlab9.3.5-ce.0

从新部署一个9.3.5环境,把数据迁移过来,验证数据完整

docker run --detach  \
--hostname git.wscyun.cn \
--publish 443:443 \
--publish 80:80 \
--publish 222:22 \
--name gitlab \
--restart always \
--volume /home/gitlab/config:/etc/gitlab \
--volume /home/gitlab/logs:/var/log/gitlab \
--volume /home/gitlab/data:/var/opt/gitlab \
gitlab/gitlab-ce:9.3.5-ce.0

查看日志,看看有没有报错之类的

docker logs -f gitlab

sameersbn/gitlab9.3.5升级gitlab-ce14.3.4

sameersbn/gitlab9.3.5升级gitlab-ce14.3.4

恢复9.3.5数据

把备份的数据从旧机器上拷贝过来,放到/home/gitlab/data/backups/下面

root@wscyun:/home/wscyun# mv 1635141160_2021_10_25_9.3.5_gitlab_backup.tar /home/gitlab/data/backups/
root@wscyun:/home/wscyun# docker exec -it gitlab bash
root@git:/# gitlab-rake gitlab:backup:restore BACKUP=1635141160_2021_10_25_9.3.5
Unpacking backup ...

 

升级1 gitlab/gitlab-ce:9.5.10-ce.0

root@wscyun:/home/wscyun# docker stop gitlab
root@wscyun:/home/wscyun# docker rm -f gitlab
root@wscyun:/home/wscyun# docker run --detach \
> --hostname git.wscyun.cn \
> --publish 443:443 \
> --publish 80:80 \
> --publish 222:22 \
> --name gitlab \
> --restart always \
> --volume /home/gitlab/config:/etc/gitlab \
> --volume /home/gitlab/logs:/var/log/gitlab \
> --volume /home/gitlab/data:/var/opt/gitlab \
> gitlab/gitlab-ce:9.5.10-ce.0
f72d94de6b8be5fe6e44aa860d4c65cd0dde0af934fe45bd9a039afd60c2728b
root@wscyun:/home/wscyun# docker logs -f gitlab 

sameersbn/gitlab9.3.5升级gitlab-ce14.3.4

 

升级2 gitlab/gitlab-ce:10.8.7-ce.0

root@wscyun:/home/wscyun# docker stop gitlab 
root@wscyun:/home/wscyun# docker rm -f gitlab
root@wscyun:/home/wscyun# docker run --detach \
> --hostname git.wscyun.cn \
> --publish 443:443 \
> --publish 80:80 \
> --publish 222:22 \
> --name gitlab \
> --restart always \
> --volume /home/gitlab/config:/etc/gitlab \
> --volume /home/gitlab/logs:/var/log/gitlab \
> --volume /home/gitlab/data:/var/opt/gitlab \
> gitlab/gitlab-ce:10.8.7-ce.0

root@wscyun:/home/wscyun# docker logs -f gitlab 

sameersbn/gitlab9.3.5升级gitlab-ce14.3.4

 

升级3 gitlab/gitlab-ce:11.11.8-ce.0

root@wscyun:/home/wscyun# docker stop gitlab
root@wscyun:/home/wscyun# docker rm -f gitlab
root@wscyun:/home/wscyun# docker run --detach \
> --hostname git.wscyun.cn \
> --publish 443:443 \
> --publish 80:80 \
> --publish 222:22 \
> --name gitlab \
> --restart always \
> --volume /home/gitlab/config:/etc/gitlab \
> --volume /home/gitlab/logs:/var/log/gitlab \
> --volume /home/gitlab/data:/var/opt/gitlab \
> gitlab/gitlab-ce:11.11.8-ce.0
b94e07d6a226fe0bf7c4b9d245a4bd4b4eafcdab55b4e5e08932ad3f858c77c1
root@wscyun:/home/wscyun# docker logs -f gitlab 

sameersbn/gitlab9.3.5升级gitlab-ce14.3.4

 

升级4 gitlab/gitlab-ce:12.10.14-ce.0

root@wscyun:/home/wscyun# docker stop gitlab && docker rm -f gitlab
root@wscyun:/home/wscyun# docker run --detach \
> --hostname git.wscyun.cn \
> --publish 443:443 \
> --publish 80:80 \
> --publish 222:22 \
> --name gitlab \
> --restart always \
> --volume /home/gitlab/config:/etc/gitlab \
> --volume /home/gitlab/logs:/var/log/gitlab \
> --volume /home/gitlab/data:/var/opt/gitlab \
> gitlab/gitlab-ce:12.10.14-ce.0
cfd47b8e09dd855e26042142ce02422d6de51139545c0db8852438fa312c840d
root@wscyun:/home/wscyun# docker logs -f gitlab 

sameersbn/gitlab9.3.5升级gitlab-ce14.3.4

 

升级5 gitlab/gitlab-ce:13.0.14-ce.0

root@wscyun:/home/wscyun# docker stop gitlab && docker rm -f gitlab
root@wscyun:/home/wscyun# docker run --detach \
> --hostname git.wscyun.cn \
> --publish 443:443 \
> --publish 80:80 \
> --publish 222:22 \
> --name gitlab \
> --restart always \
> --volume /home/gitlab/config:/etc/gitlab \
> --volume /home/gitlab/logs:/var/log/gitlab \
> --volume /home/gitlab/data:/var/opt/gitlab \
> gitlab/gitlab-ce:13.0.14-ce.0
4d50a8e245284cb4acf39b58217529859ecf21b7a30de5e737b76a58dfa058cb
root@wscyun:/home/wscyun# docker logs -f gitlab 

报错:

Running handlers:
There was an error running gitlab-ctl reconfigure:

ruby_block[warn pending redis restart] (redis::enable line 82) had an error: RuntimeError: Execution of the command `/opt/gitlab/embedded/bin/redis-cli -s /var/opt/gitlab/redis/redis.socket INFO` failed with a non-zero exit code (1)
stdout: 
stderr: Could not connect to Redis at /var/opt/gitlab/redis/redis.socket: No such file or directory


Running handlers complete
Chef Client failed. 61 resources updated in 44 seconds

重启gitlab

root@wscyun:/home/wscyun# docker exec -it gitlab bash
root@git:/# gitlab-ctl restart
ok: run: alertmanager: (pid 1171) 0s
ok: run: gitaly: (pid 1181) 1s
ok: run: gitlab-exporter: (pid 1200) 0s
ok: run: gitlab-workhorse: (pid 1202) 0s
ok: run: grafana: (pid 1220) 0s
ok: run: logrotate: (pid 1241) 1s
ok: run: nginx: (pid 1247) 0s
ok: run: postgres-exporter: (pid 1255) 1s
ok: run: postgresql: (pid 1264) 0s
ok: run: prometheus: (pid 1349) 1s
ok: run: puma: (pid 1367) 0s
ok: run: redis: (pid 1372) 0s
ok: run: redis-exporter: (pid 1377) 1s
ok: run: sidekiq: (pid 1385) 0s
ok: run: sshd: (pid 1393) 0s
root@git:/# gitlab-ctl reconfigure

sameersbn/gitlab9.3.5升级gitlab-ce14.3.4

设置HASH存储

root@git:/# gitlab-rake gitlab:storage:migrate_to_hashed
Enqueuing migration of 67 projects in batches of 200. Done!
root@git:/# gitlab-rake gitlab:storage:hashed_projects
* Found 67 projects using Hashed Storage

更新令牌

如本地存储转HASH显示成功,查询没有HASH数据更新下令牌重新转HASH

请参考:Repository storage Rake tasks | GitLab

升级6 gitlab/gitlab-ce:13.9.7-ce.0

root@wscyun:/home/wscyun# docker stop gitlab && docker rm -f gitlab
root@wscyun:/home/wscyun# docker run --detach \
> --hostname git.wscyun.cn \
> --publish 443:443 \
> --publish 80:80 \
> --publish 222:22 \
> --name gitlab \
> --restart always \
> --volume /home/gitlab/config:/etc/gitlab \
> --volume /home/gitlab/logs:/var/log/gitlab \
> --volume /home/gitlab/data:/var/opt/gitlab \
> gitlab/gitlab-ce:13.9.7-ce.0
4ac5d144bb87c8e7c2dd8f3e2c6f4f95bdd3b9c9b4a8e1c0bcb96ba1b8b3e4e7
root@wscyun:/home/wscyun# docker logs -f gitlab 

sameersbn/gitlab9.3.5升级gitlab-ce14.3.4

 

升级7 gitlab/gitlab-ce:13.12.11-ce.0

root@wscyun:/home/wscyun# docker stop gitlab && docker rm -f gitlab
root@wscyun:/home/wscyun# docker run --detach \
> --hostname git.wscyun.cn \
> --publish 443:443 \
> --publish 80:80 \
> --publish 222:22 \
> --name gitlab \
> --restart always \
> --volume /home/gitlab/config:/etc/gitlab \
> --volume /home/gitlab/logs:/var/log/gitlab \
> --volume /home/gitlab/data:/var/opt/gitlab \
> gitlab/gitlab-ce:13.12.11-ce.0
761af2ac975d29af6b32aebfe1e3e90d0c56f8527de861611666cc37b597cdef
root@wscyun:/home/wscyun# docker logs -f gitlab 

sameersbn/gitlab9.3.5升级gitlab-ce14.3.4

 

升级8 gitlab/gitlab-ce:14.0.10-ce.0

root@wscyun:/home/wscyun# docker stop gitlab && docker rm -f gitlab
root@wscyun:/home/wscyun# docker run --detach \
> --hostname git.wscyun.cn \
> --publish 443:443 \
> --publish 80:80 \
> --publish 222:22 \
> --name gitlab \
> --restart always \
> --volume /home/gitlab/config:/etc/gitlab \
> --volume /home/gitlab/logs:/var/log/gitlab \
> --volume /home/gitlab/data:/var/opt/gitlab \
> gitlab/gitlab-ce:14.0.10-ce.0
71d51e4891c0487367ad5f939a6adcc1021638bc79ca1b26c02422ea49389af3
root@wscyun:/home/wscyun# docker logs -f gitlab 

sameersbn/gitlab9.3.5升级gitlab-ce14.3.4

设置修改gitlab账号为超级用户

我升级一直卡在14.0.10这里因为有一个报错,后来用下面的操作才成功升级。

root@wscyun:/home/wscyun# docker exec -it gitlab bash
root@git:/# gitlab-rails console -e production
--------------------------------------------------------------------------------
 Ruby:         ruby 2.7.2p137 (2020-10-01 revision 5445e04352) [x86_64-linux]
 GitLab:       14.0.10 (2ed12048430) FOSS
 GitLab Shell: 13.19.1
 PostgreSQL:   12.7
--------------------------------------------------------------------------------
Loading production environment (Rails 6.1.3.2)
irb(main):001:0> user = User.where(id: 1).first
=> #<User id:1 @root>
irb(main):002:0> user.password = 'wscyun6760'
=> "wscyun6760"
irb(main):003:0> user.password_confirmation = 'wscyun6760'
=> "wscyun6760"
irb(main):004:0> user.state = "active"
irb(main):005:0> user.save!
=> true
irb(main):006:0> quit
root@git:/# gitlab-ctl restart
ok: run: alertmanager: (pid 1598) 0s
ok: run: gitaly: (pid 1622) 0s
ok: run: gitlab-exporter: (pid 1636) 0s
ok: run: gitlab-workhorse: (pid 1644) 1s
ok: run: grafana: (pid 1659) 0s
ok: run: logrotate: (pid 1668) 0s
ok: run: nginx: (pid 1678) 1s
ok: run: postgres-exporter: (pid 1684) 0s
ok: run: postgresql: (pid 1692) 0s
ok: run: prometheus: (pid 1705) 0s
ok: run: puma: (pid 1717) 0s
ok: run: redis: (pid 1723) 1s
ok: run: redis-exporter: (pid 1729) 0s
ok: run: sidekiq: (pid 1814) 0s
ok: run: sshd: (pid 1822) 0s
root@git:/# gitlab-rake gitlab:storage:legacy_projects
* Found 0 projects using Legacy Storage
root@git:/# gitlab-rails dbconsole
psql (12.7)
Type "help" for help.

gitlabhq_production=> UPDATE projects SET runners_token = null, runners_token_encrypted = null;
UPDATE 67
gitlabhq_production=> UPDATE namespaces SET runners_token = null, runners_token_encrypted = null;
UPDATE 46
gitlabhq_production=> UPDATE application_settings SET runners_registration_token_encrypted = null;
UPDATE 1
gitlabhq_production=> UPDATE application_settings SET encrypted_ci_jwt_signing_key = null;
UPDATE 1
gitlabhq_production=> UPDATE ci_runners SET token = null, token_encrypted = null;
UPDATE 4
gitlabhq_production=> exit
could not save history to file "/var/opt/gitlab/.psql_history": Permission denied
root@git:/# gitlab-rake gitlab:storage:migrate_to_hashed
There are no projects requiring storage migration. Nothing to do!

root@git:/# exit
exit
root@wscyun:/home/wscyun# vim /home/gitlab/data/postgresql/data/postgresql.conf 
listen_addresses = '*'
root@wscyun:/home/wscyun# vim /home/gitlab/data/postgresql/data/pg_hba.conf 
# 最下面新增两行
local all all trust
host all all 127.0.0.1/32 trust
root@wscyun:/home/wscyun# docker exec -it gitlab bash
root@git:/# gitlab-ctl restart
ok: run: alertmanager: (pid 2603) 0s
ok: run: gitaly: (pid 2613) 1s
ok: run: gitlab-exporter: (pid 2636) 0s
ok: run: gitlab-workhorse: (pid 2644) 0s
ok: run: grafana: (pid 2646) 1s
ok: run: logrotate: (pid 2664) 0s
ok: run: nginx: (pid 2670) 1s
ok: run: postgres-exporter: (pid 2676) 0s
ok: run: postgresql: (pid 2723) 1s
ok: run: prometheus: (pid 2772) 0s
ok: run: puma: (pid 2785) 0s
ok: run: redis: (pid 2790) 1s
ok: run: redis-exporter: (pid 2796) 0s
ok: run: sidekiq: (pid 2805) 0s
ok: run: sshd: (pid 2813) 1s
root@git:/# su - gitlab-psql
$ /opt/gitlab/embedded/bin/psql -h 127.0.0.1 gitlabhq_production
psql (12.7)
SSL connection (protocol: TLSv1.3, cipher: TLS_AES_256_GCM_SHA384, bits: 256, compression: off)
Type "help" for help.

gitlabhq_production=# ALTER USER gitlab WITH SUPERUSER;
ALTER ROLE
gitlabhq_production=# \q

 

升级9 gitlab/gitlab-ce:14.3.4-ce.0

root@wscyun:/home/wscyun# docker stop gitlab && docker rm -f gitlab
root@wscyun:/home/wscyun# docker run --detach \
> --hostname git.wscyunr.cn \
> --publish 443:443 \
> --publish 80:80 \
> --publish 222:22 \
> --name gitlab \
> --restart always \
> --volume /home/gitlab/config:/etc/gitlab \
> --volume /home/gitlab/logs:/var/log/gitlab \
> --volume /home/gitlab/data:/var/opt/gitlab \
> gitlab/gitlab-ce:14.3.4-ce.0
8479a6a62ee4a8cd6168fd27cb04c0c4ddbb8f0c2d3d6e3c0e4dd914ac6dfb00
root@wscyun:/home/wscyun# docker logs -f gitlab 

sameersbn/gitlab9.3.5升级gitlab-ce14.3.4

 

继续阅读
王书宸
  • 本文由 发表于 2021年11月5日09:08:02
  • 转载请务必保留本文链接:https://www.wscyun.com/2926
自动化装机工具-kickstart 运维

自动化装机工具-kickstart

导言 作为中小公司的运维,经常会遇到一些机械式的重复工作,例如:有时公司同时上线几十甚至上百台服务器,而且需要我们在短时间内完成系统安装。 常规的办法有什么? 光盘安装系统===>一个服务器DV...
自动化装机工具-cobbler 服务器

自动化装机工具-cobbler

在看Cobbler之前请大家先看一下Kickstart无人值守安装,了解一下Cobbler的实现原理。但是Cobbler是独立的,不需要先安装Kickstart然后再安装Cobbler,这是写给不了解...