Docker installation and deployment Gitlab storage path migration

1. Migration background

  • Server disk space is full
  • Need to replace server
  • Gitlab cannot start normally
  • Other exceptions require reinstallation

In summary, regardless of any migration background, we need to retain historical data

2. Install GitLab

2.1. Docker installation and deployment of Gitlab

Docker installation and deployment GitLab

3. Migration steps

3.1. Stop GitLab

To prevent users from writing data when migrating the repository, first stop GitLab

# docker 停止 gitLab
docker stop gitlab

3.2. Migrate data

The first step is to create the gitlab directory on the new server (reinstallation can be ignored)

# 创建 gitlab 目录
mkdir -p /home/docker/gitlab

The second step is to migrate data remotely (reinstallation can be ignored)

# 复制 gitlab 配置存放目录
scp -r /home/docker/gitlab/etc/ root@192.168.1.2:/home/docker/gitlab/

# 复制 gitlab 日志存放目录
scp -r /home/docker/gitlab/log/ root@192.168.1.2:/home/docker/gitlab/

# 复制 gitlab 数据存放目录
scp -r /home/docker/gitlab/data/ root@192.168.1.2:/home/docker/gitlab/

Reference example
Insert image description here
Step 3: Initialize data and configure storage directory permissions

# 修改 gitlab 配置存放目录权限
chown -R 200 /home/docker/gitlab/etc

# 修改 gitlab 日志存放目录权限
chown -R 200 /home/docker/gitlab/log

# 修改 gitlab 数据存放目录权限
chown -R 200 /home/docker/gitlab/data

The fourth step is to back up the data and delete the original container (it can be ignored if it has been backed up).
Remember to back up the historical data. When the Gitlab container is started, you can execute the following command to copy the data.

# 复制 gitlab 容器配置文件到指定目录
docker cp -a gitlab:/etc/gitlab /home/docker/gitlab/etc

# 复制 gitlab 容器日志文件到指定目录
docker cp -a gitlab:/var/log/gitlab /home/docker/gitlab/log

# 复制 gitlab 容器数据文件到指定目录
docker cp -a gitlab:/var/opt/gitlab /home/docker/gitlab/data

# 删除 gitlab 容器
docker rm -f gitlab

Step 5, install Gitlab

# 安装并启动 gitlab
docker run -d -p 443:443 -p 80:80 \
--name gitlab \
--network woniu_network \
--ip 172.0.0.19 \
--restart unless-stopped \
-v /home/docker/gitlab/etc:/etc/gitlab \
-v /home/docker/gitlab/log:/var/log/gitlab \
-v /home/docker/gitlab/data:/var/opt/gitlab \
beginor/gitlab-ce:11.0.1-ce.0

4. Abnormal situations

4.1. Abnormal file permissions

Exception information

Error executing action `run` on resource 'execute[/opt/gitlab/embedded/service/gitlab-shell/bin/gitlab-keys check-permissions]'  

solution

# 重新修改文件权限
docker exec -it gitlab update-permissions

# 重启 gitlab
docker restart gitlab

4.2. Reinitialize configuration

If other abnormalities prevent normal startup, you can try to reinitialize the configuration.

# 重新初始化配置,该操作会还原历史配置信息
docker exec -it gitlab gitlab-ctl reconfigure

# 重启 gitlab
docker restart gitlab

Practice is the only criterion for testing truth. One click to send three consecutive attentions to avoid getting lost.

Guess you like

Origin blog.csdn.net/u011374856/article/details/125614261