Data storage directory migration

Published 2024年11月06日

Scenario Description

This article will explain how to migrate the data storage directory in JumpServer when the server's disk usage becomes high after long periods of operation.

Configuration Description

Example: The current root directory disk usage is 92%, and we need to migrate the directory (Note: If the disk usage reaches 100%, causing server lag, you can delete unnecessary packages or recordings to temporarily alleviate the issue.)

# Command to check disk usage
df -hT
 
Filesystem              Type      Size  Used Avail Use% Mounted on
/dev/mapper/centos-root xfs        97G   90G   24G  92% /
devtmpfs                devtmpfs  7.8G     0  7.8G   0% /dev
tmpfs                   tmpfs     7.8G     0  7.8G   0% /dev/shm
tmpfs                   tmpfs     7.8G  818M  7.0G  11% /run
tmpfs                   tmpfs     7.8G     0  7.8G   0% /sys/fs/cgroup
/dev/sda1               xfs      1014M  145M  870M  15% /boot
tmpfs                   tmpfs     1.6G     0  1.6G   0% /run/user/0
overlay                 overlay    97G   90G   24G  92% /var/lib/docker/overlay2/d24a7ab1b7470d1d9a6f7f9528fa60e42c02ac400b34488887884cd66008e92e/merged
overlay                 overlay    97G   90G   24G  92% /var/lib/docker/overlay2/d9727428c862dc305de00cf18158c93dbe2851bb0298aba45258a3b8663d044f/merged
overlay                 overlay    97G   90G   24G  92% /var/lib/docker/overlay2/52f5d1cbfbfd32afbde04dc5d79ba6f33474ea8c7d813dad375b7a41fc6ba603/merged
overlay                 overlay    97G   90G   24G  92% /var/lib/docker/overlay2/43c142e913e883c53e6a614c50ef16096dfbca98318c3a42bac3cab5812ae78f/merged
overlay                 overlay    97G   90G   24G  92% /var/lib/docker/overlay2/dd96148abd067ae4edcd415f5abf710b76556f9a57c5e8b31a7296d68e2e9e23/merged
overlay                 overlay    97G   90G   24G  92% /var/lib/docker/overlay2/b63b09a1c125ce9a7f9cce0228fd060fbc68807984de9e3c3a6cb3030ae851bc/merged
overlay                 overlay    97G   90G   24G  92% /var/lib/docker/overlay2/6583defb810d2568d193daf971e6e4804bac084fa9ff6e03aac6eacc7f5fff87/merged
overlay                 overlay    97G   90G   24G  92% /var/lib/docker/overlay2/4f98bf55e3c4e874628597bdcf0be8d3c348b9feb33ebec754a88435cb145eda/merged
overlay                 overlay    97G   90G   24G  92% /var/lib/docker/overlay2/bb960b7c9b807926d56fa3fcaa67d187b5312c35e2a35328a5c0ead3e4bc7b8b/merged

Environment Description

  1. Perform data backup operations on the environment according to actual conditions.

    • Default path for recording files: /data/jumpserver/core/data/media

    • Database data backup: Execute the command < jmsctl backup_db >

    • Configuration file path: /opt/jumpserver/config/config.txt

  2. The migration locations of various directories in the current environment are as follows:

Directory Type

Directory Location Before Migration

Directory Location After Migration

Docker Directory

/var/lib/docker

/home/docker

JumpServer Storage Directory

/data/jumpserver

/home/jumpserver

Migrate Docker Storage

Check Docker Storage Location.

docker info | grep "Docker Root Dir"
 Docker Root Dir: /var/lib/docker

Stop the JumpServer and Docker services.

# Stop the JumpServer service.
jmsctl down
 
# Stop the Docker service.
systemctl stop docker

Migrate the Docker storage directory.

# Currently migrating from /var/lib/docker directory to /home/docker directory.
# It is recommended to use the cp command and delete the old directory only after confirming the migration is correct.
# For large amounts of data, please be patient during the migration process.
 
cp -r /var/lib/docker/* /home/docker/       # Make sure to note the directory structure in front and avoid copying an extra layer of directories.

Confirm whether the data migration is complete.

# Compare the data size of the new directory with the old directory.
# Old directory data size
du -sh /var/lib/docker
19G    /var/lib/docker
 
# New directory data size
du -sh /home/docker
19G    /home/docker

Modify the daemon.json configuration file.

# Backup the daemon.json configuration file.
cp /etc/docker/daemon.json /etc/docker/daemon.json.bak
 
# Edit the daemon.json configuration file.
vim /etc/docker/daemon.json
 
{
 "data-root": "/home/docker",   # Change this configuration to /home/docker.
 "live-restore": true,
 "log-driver": "json-file",
 "log-opts": {
  "max-file": "3",
  "max-size": "10m"
 },
 "registry-mirrors": [
  "https://hub-mirror.c.163.com",
  "http://f1361db2.m.daocloud.io"
 ]
}

Modify the JumpServer configuration file.

# Backup the config.txt configuration file.
cp /opt/jumpserver/config/config.txt /opt/jumpserver/config/config.txt.bak 
 
# Edit the config.txt configuration file.
vi /opt/jumpserver/config/config.txt
DOCKER_DIR=/home/docker  # Change this configuration to /home/docker. If this parameter doesn't exist, feel free to add it.

Start the Docker service and confirm that the Docker storage location is the new directory.

# Start the Docker service.
systemctl start docker 
 
# Check the Docker storage location.
docker info | grep "Docker Root Dir"
 Docker Root Dir: /home/docker

The Docker directory migration is complete; you can start the JumpServer service.

# Start the JumpServer service.
jmsctl start
 
# Check the JumpServer service status.
jmsctl status

After confirming that the newly migrated Docker is working properly, delete the old Docker directory.

# Delete the old Docker directory.
rm -rf /var/lib/docker

Migration of JumpServer Storage Directory

Stop the JumpServer service.

# Stop the JumpServer service.
jmsctl down

Migrate the JumpServer storage directory.

# Currently migrating from the /opt/jumpserver directory to the /home/jumpserver directory.
# It is recommended to use the cp command, and delete the old directory only after confirming the migration is correct.
# In cases of large data volumes, please be patient during the migration process.
 
cp -r /data/jumpserver/* /home/jumpserver/

Confirm whether the data migration is complete.

# Compare the data size between the new directory and the old directory.
# Size of the data in the old directory:
du -sh /data/jumpserver
921M    /data/jumpserver
 
# Size of the data in the new directory:
du -sh /home/jumpserver
921M    /home/jumpserver

Modify the JumpServer configuration file.

# Backup the config.txt configuration file.
cp /opt/jumpserver/config/config.txt /opt/jumpserver/config/config.txt.bak 
 
# Edit the config.txt configuration file.
vi /opt/jumpserver/config/config.txt
VOLUME_DIR=/home/jumpserver  # Change this configuration to /home/jumpserver. If this parameter doesn't exist, feel free to add it.

The migration of the JumpServer storage directory is complete; start the service.

# Start the JumpServer service.
jmsctl start
 
# Check the JumpServer service status.
jmsctl status

After confirming that the JumpServer page access, video playback, and other functions are working properly, you can delete the old JumpServer directory.

# Delete the old JumpServer directory.
 
rm -rf /data/jumpserver