背景
本文描述的是docker部署的Gitlab,从一台服务器迁移到另外一台服务器。
停止正在运行的容器
root@dev-server:~# docker stop gitlab.amihome.cn
gitlab.amihome.cn
传输数据目录到新服务器
用rsync命令,将gitlab容器挂载的数据目录,传输到新服务器:
root@dev-server:/mnt/disk5t/data# rsync -avz gitlab.amihome.cn [email protected]:/mnt/disk5t
The authenticity of host '192.168.3.201 (192.168.3.201)' can't be established.
ED25519 key fingerprint is SHA256:xzcLjUSv***********************NQZnzPwz8ogyOA.
This key is not known by any other names
Are you sure you want to continue connecting (yes/no/[fingerprint])? yes
Warning: Permanently added '192.168.3.201' (ED25519) to the list of known hosts.
[email protected]'s password:
sending incremental file list
gitlab.amihome.cn/
gitlab.amihome.cn/docker-compose.yml
gitlab.amihome.cn/config/
gitlab.amihome.cn/config/gitlab-secrets.json
gitlab.amihome.cn/config/gitlab.rb
…………局域网内,2.5G的网卡、万兆交换机,不到1分钟…………
gitlab.amihome.cn/logs/sshd/current
gitlab.amihome.cn/logs/sshd/lock
sent 993,168,798 bytes received 179,973 bytes 11,755,606.76 bytes/sec
total size is 5,058,761,702 speedup is 5.09
root@dev-server:/mnt/disk5t/data#
检阅docker-compose.yml文件
在新服务器上,检查一下,主要是查看目录是否正确:
root@cap-server:/mnt/disk5t/gitlab.amihome.cn# vi docker-compose.yml
内容如下:(和之前的文章略有区别,删除了一层data目录)
version: '3.6'
services:
web:
image: 'registry.gitlab.cn/omnibus/gitlab-jh:16.7.6'
restart: always
container_name: gitlab.amihome.cn
hostname: 'gitlab.amihome.cn'
environment:
GITLAB_OMNIBUS_CONFIG: |
external_url 'https://gitlab.amihome.cn'
gitlab_rails['gitlab_shell_ssh_port'] = 2224
ports:
- '60002:443'
- '8929:80'
- '2224:22'
dns:
- 192.168.3.254
volumes:
- '/mnt/disk5t/gitlab.amihome.cn/config:/etc/gitlab'
- '/mnt/disk5t/gitlab.amihome.cn/logs:/var/log/gitlab'
- '/mnt/disk5t/gitlab.amihome.cn/data:/var/opt/gitlab'
- '/home/certd/gitlab.amihome.cn:/etc/gitlab/ssl'
shm_size: '256m'
启动容器
用docker-compose启动容器:
root@cap-server:/mnt/disk5t/gitlab.amihome.cn# docker-compose up -d
Creating network "gitlabamihomecn_default" with the default driver
Pulling web (registry.gitlab.cn/omnibus/gitlab-jh:16.7.6)...
16.7.6: Pulling from omnibus/gitlab-jh
d66d6a6a3687: Pull complete
69b4e98ec663: Pull complete
33d64feb3e33: Pull complete
92f2674f9018: Pull complete
ef32215ff226: Pull complete
e6ccdd486b58: Pull complete
4475ff4ff63c: Pull complete
7940e6d9c9c9: Pull complete
Digest: sha256:bb9f6c93fb4465acea546f988afad81f648d2b625b00f2c06062ee1cefddd68d
Status: Downloaded newer image for registry.gitlab.cn/omnibus/gitlab-jh:16.7.6
Creating gitlab.amihome.cn ... done
查看容器的状态:
root@cap-server:/mnt/disk5t/gitlab.amihome.cn# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
d1915f6fb5de registry.gitlab.cn/omnibus/gitlab-jh:16.7.6 "/assets/wrapper" About a minute ago Up About a minute (health: starting) 0.0.0.0:2224->22/tcp, :::2224->22/tcp, 0.0.0.0:8929->80/tcp, :::8929->80/tcp, 0.0.0.0:60002->443/tcp, :::60002->443/tcp gitlab.amihome.cn
一个错误
多次用docker ps查看容器状态,直至最终发现容器状态是unhealthy:
root@cap-server:/mnt/disk5t/gitlab.amihome.cn# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
d1915f6fb5de registry.gitlab.cn/omnibus/gitlab-jh:16.7.6 "/assets/wrapper" 8 minutes ago Up 6 minutes (unhealthy) 0.0.0.0:2224->22/tcp, :::2224->22/tcp, 0.0.0.0:8929->80/tcp, :::8929->80/tcp, 0.0.0.0:60002->443/tcp, :::60002->443/tcp gitlab.amihome.cn
用docker logs gitlab.amihome.cn查看日志,接近尾部的时候有如下关键的一句:
……很长的日志……
2024-03-19_03:43:09.98701 22197:M 19 Mar 2024 03:43:09.986 # Fatal error loading the DB: Permission denied. Exiting.
……后边还有……
解决办法,执行下述命令:
root@cap-server:/mnt/disk5t/gitlab.amihome.cn# docker exec -it gitlab.amihome.cn update-permissions
这个命令几秒就执行完毕,输出的日志很长,就不贴在这里了。
重新启动容器
root@cap-server:/mnt/disk5t/gitlab.amihome.cn# docker-compose restart
Restarting gitlab.amihome.cn ... done
root@cap-server:/mnt/disk5t/gitlab.amihome.cn# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
d1915f6fb5de registry.gitlab.cn/omnibus/gitlab-jh:16.7.6 "/assets/wrapper" 10 minutes ago Up About a minute (healthy) 0.0.0.0:2224->22/tcp, :::2224->22/tcp, 0.0.0.0:8929->80/tcp, :::8929->80/tcp, 0.0.0.0:60002->443/tcp, :::60002->443/tcp gitlab.amihome.cn
在浏览器中访问,完全正常。
标签:gitlab,cn,0.0,Gitlab,tcp,amihome,迁移,docker From: https://www.cnblogs.com/amisoft/p/18082182/move-gitlab