Skip to content

Instantly share code, notes, and snippets.

@Cdaprod
Created October 29, 2024 15:57
Show Gist options
  • Save Cdaprod/9b0a7076cfdc57e6e68c5049c80439b9 to your computer and use it in GitHub Desktop.
Save Cdaprod/9b0a7076cfdc57e6e68c5049c80439b9 to your computer and use it in GitHub Desktop.
A concise guide for preparing a Synology NAS for a distributed MinIO cluster. It covers cleaning the root filesystem, creating a logical volume for Docker, and configuring MinIO for optimal storage management.

This guide fixes Synology root storage issues, migrates Docker storage, and sets up a MinIO node for clustering.

Current Situation Summary:

  • Root Filesystem (/dev/md0):
    • Size: 2.3 GB
    • Used: 1.7 GB
    • Available: 483 MB (79% usage)
  • Data Volume (/volume1):
    • Size: 11 TB
    • Used: 4.8 TB
    • Available: 5.8 TB (46% usage)
  • Main Space Consumers on /usr:
    • Total /usr: 1.5 GB
    • Key Directories:
      • /usr/syno: 721 MB
      • /usr/syno/synoinstall: 497 MB
      • /usr/lib: 246 MB
      • /usr/local: 238 MB
      • Others: Various smaller directories

Next Steps to Free Up Additional Space on /

1. Remove Unnecessary Packages and Applications via DSM Package Center

Synology DSM manages packages through the Package Center. It's essential to remove any unused or unnecessary packages to free up space on the root filesystem. Here's how:

  1. Access DSM:

    • Open your web browser and navigate to your Synology NAS's IP address (e.g., http://192.168.0.19:5000).
    • Log in with your administrator credentials.
  2. Open Package Center:

    • Click on the Package Center icon from the main menu.
  3. Review Installed Packages:

    • Navigate to the Installed tab.
    • Identify Unused Packages:
      • Look for packages that you no longer use or need. Common candidates might include older applications, testing tools, or previously used services.
  4. Uninstall Unnecessary Packages:

    • Click on the Action button (usually represented by three dots) next to the package you want to remove.
    • Select Uninstall and confirm the action.
    • Example Packages to Consider:
      • Python2 Packages: If you had Python 2 packages installed for previous automation tasks, they might no longer be needed.
      • SMBService: If you're not using SMB/CIFS services.
      • SynoFinder: If not in use.
  5. Reboot (If Necessary):

    • Some uninstallations may require a system reboot. If prompted, proceed to reboot your NAS to apply changes.

2. Manually Remove Leftover Package Directories

Sometimes, uninstalling packages via DSM may leave residual files or directories. You can manually clean these up to reclaim additional space.

  1. List Contents of @appstore Directory:

    The @appstore directory typically contains installed packages.

    sudo ls -lh /usr/local/packages/@appstore
  2. Identify Unused or Residual Packages:

    Look for directories related to packages you have uninstalled or no longer need.

    • Example:
      • /usr/local/packages/@appstore/Python2
      • /usr/local/packages/@appstore/SMBService
  3. Remove Unnecessary Directories:

    Caution: Ensure that the directories you are about to delete are indeed related to packages you no longer need. Deleting essential system directories can render your NAS unstable.

    sudo rm -rf /usr/local/packages/@appstore/Python2
    sudo rm -rf /usr/local/packages/@appstore/SMBService
    sudo rm -rf /usr/local/packages/@appstore/SynoFinder
  4. Verify Removal:

    After deletion, check the disk usage again to confirm the space has been freed.

    df -h /

3. Clean Up Synology-Specific Directories

Synology maintains specific directories for its services. Cleaning these up can help, but proceed with caution.

  1. Examine /usr/syno/synoinstall Directory:

    This directory may contain installation files or temporary data.

    sudo du -h /usr/syno/synoinstall | sort -hr | head -n 20
  2. Remove Unnecessary Files:

    If you identify files that are no longer needed (e.g., leftover installation files), you can remove them.

    sudo rm -rf /usr/syno/synoinstall/*
  3. Check /usr/syno/synoman and Related Directories:

    Similar to synoinstall, ensure no unnecessary files are taking up space.

    sudo du -h /usr/syno/synoman | sort -hr | head -n 20
    sudo rm -rf /usr/syno/synoman/webman/texts
    sudo rm -rf /usr/syno/synoman/webman/modules

    Note: Only remove directories if you're certain they're not required by any active services.

4. Investigate and Clean Up Remaining Large Directories

If /usr still occupies 1.5 GB after removing packages, identify specific large files or subdirectories.

  1. Find Large Files in /usr:

    sudo find /usr -type f -size +100M -exec ls -lh {} \; | sort -k 5 -rh | head -n 20

    This command lists the top 20 largest files within /usr that are larger than 100 MB.

  2. Review and Remove Unnecessary Large Files:

    • Python-Related Files: If you've already removed Python 3.8, ensure no residual Python files remain.

    • Imageio_ffmpeg Binaries:

      These binaries might be large and unnecessary if not in use.

      sudo rm -rf /usr/lib/python3.8/site-packages/imageio_ffmpeg
    • GeoIP Database:

      If not needed, consider removing or relocating.

      sudo rm -rf /usr/share/geoip
    • Other Unnecessary Large Files:

      Carefully evaluate each large file before deletion.

5. Clean Up Core Dumps and Crash Reports

Core dumps can take up significant space.

  1. Find and Remove Core Dumps:

    sudo find / -type f -name "core" -exec rm -f {} \;
    sudo find / -type f -name "core.*" -exec rm -f {} \;
  2. Check for Crash Reports:

    Synology may store crash reports in /var/crash. Remove them if they are no longer needed.

    sudo rm -rf /var/crash/*

6. Verify Space Freed

After performing the cleanup steps, verify the available space on the root filesystem.

df -h /

You should see a reduction in used space, ideally bringing usage below 70% to provide some buffer.

Step 2: Creating a New Volume for Docker

Once you've successfully cleaned up the root filesystem and have freed additional space, the next step is to create a new volume dedicated to Docker storage. This will ensure Docker's data doesn't consume space on the root filesystem.

2.1. Verify Available Space in Volume Group

Ensure that your vg1000 volume group on /volume1 has sufficient free space.

sudo vgdisplay vg1000

Look for the Free PE / Size line to confirm available space.

2.2. Create a New Logical Volume for Docker

Allocate 1-2 TB for Docker storage.

sudo lvcreate -L 2T -n docker_storage vg1000

2.3. Format the New Logical Volume

Format the new logical volume with the ext4 filesystem.

sudo mkfs.ext4 /dev/vg1000/docker_storage

2.4. Mount the New Volume

  1. Create Mount Point:

    sudo mkdir /mnt/docker_storage
  2. Mount the Logical Volume:

    sudo mount /dev/vg1000/docker_storage /mnt/docker_storage
  3. Make the Mount Persistent:

    Add the following line to /etc/fstab to ensure the volume mounts automatically on boot.

    echo "/dev/vg1000/docker_storage /mnt/docker_storage ext4 defaults 0 0" | sudo tee -a /etc/fstab

Step 3: Setting Up Docker to Use the New Volume

With the new volume ready, configure Docker to use it for its storage.

3.1. Stop Docker Service

Since synoservice isn't available, use alternative commands to stop Docker. On Synology NAS, Docker is typically managed via DSM, but you can try the following:

sudo systemctl stop docker

If systemctl isn't available, attempt:

sudo service docker stop

If these commands don't work, use DSM's interface:

  1. Open DSM.
  2. Go to Package Center.
  3. Find Docker.
  4. Stop Docker from the Package Center.

3.2. Move Docker Data to the New Volume

  1. Move Docker's Data Directory:

    sudo mv /var/lib/docker /mnt/docker_storage
  2. Create a Symbolic Link:

    sudo ln -s /mnt/docker_storage/docker /var/lib/docker

    This ensures Docker continues to operate as if its data directory is still at /var/lib/docker, while the actual data resides on the new volume.

3.3. Start Docker Service

Start Docker again using the appropriate method:

sudo systemctl start docker

Or via DSM's Package Center:

  1. Open DSM.
  2. Go to Package Center.
  3. Start Docker.

3.4. Verify Docker Storage Location

Confirm that Docker is now using the new storage location:

docker info | grep "Docker Root Dir"

The output should show /mnt/docker_storage/docker as the Docker Root Dir.

Step 4: Set Up MinIO Cluster

Now that Docker is properly set up with its storage on a separate volume, you can proceed to set up your NAS as part of a distributed MinIO cluster.

4.1. Pull MinIO Docker Image

docker pull minio/minio

4.2. Create MinIO Data Directory

Ensure MinIO has a dedicated directory on /volume1 for its data.

sudo mkdir -p /volume1/minio/data
sudo chown -R 1000:1000 /volume1/minio/data  # Adjust ownership as needed

4.3. Run MinIO in Distributed Mode

Assuming you have multiple NAS units for the distributed cluster, run MinIO containers on each, pointing to their respective data directories.

Example Command:

docker run -d --name minio \
  -p 9000:9000 \
  -p 9001:9001 \
  -v /volume1/minio/data:/data \
  -e "MINIO_ACCESS_KEY=your-access-key" \
  -e "MINIO_SECRET_KEY=your-secret-key" \
  minio/minio server http://<nas1-ip>/data http://<nas2-ip>/data http://<nas3-ip>/data http://<nas4-ip>/data

Parameters:

  • -p 9000:9000: Exposes MinIO API on port 9000.
  • -p 9001:9001: Exposes MinIO Console on port 9001.
  • -v /volume1/minio/data:/data: Mounts the data directory.
  • MINIO_ACCESS_KEY and MINIO_SECRET_KEY: Set your credentials.
  • server: Specifies the MinIO server mode with multiple endpoints for distributed storage.

Note:

  • Replace <nas1-ip>, <nas2-ip>, etc., with the actual IP addresses of your NAS units.
  • Ensure all NAS units have Docker configured to use their respective /volume1/docker_storage for Docker data.

4.4. Verify MinIO Cluster

  1. Check Container Status:

    docker ps -a
  2. Check Logs:

    docker logs minio
  3. Access MinIO Console:

    Navigate to http://<your-nas-ip>:9001 in your web browser and log in with your access and secret keys.

4.5. Configure Load Balancing (Optional but Recommended)

For better performance and high availability, consider setting up a load balancer (like NGINX or HAProxy) in front of your MinIO cluster.

Example with NGINX:

  1. Install NGINX on Docker:

    docker pull nginx
  2. Run NGINX Container:

    docker run -d --name nginx-lb \
      -p 80:80 \
      -v /path/to/nginx.conf:/etc/nginx/nginx.conf \
      nginx
  3. Configure nginx.conf:

    Create a configuration file (nginx.conf) that balances traffic across your MinIO instances.

    upstream minio_cluster {
        server <nas1-ip>:9000;
        server <nas2-ip>:9000;
        server <nas3-ip>:9000;
        server <nas4-ip>:9000;
    }
    
    server {
        listen 80;
    
        location / {
            proxy_pass http://minio_cluster;
        }
    
        location /minio {
            proxy_pass http://minio_cluster;
        }
    }
  4. Reload NGINX Configuration:

    docker exec nginx-lb nginx -s reload

Step 5: Final Verification and Maintenance

  1. Check Root Filesystem Usage:

    df -h /

    Ensure usage is now below 80%, ideally around 70% or lower.

  2. Monitor Docker and MinIO:

    Regularly check Docker containers and MinIO health to ensure everything is functioning correctly.

  3. Set Up Regular Maintenance:

    • Log Rotation: Ensure logs are rotated to prevent future space issues.
    • Automated Cleanup: Use scripts or Docker settings to clean up unused images and containers.
  4. Backup Configuration:

    Ensure you have backups of your MinIO data and Docker configurations to prevent data loss.

Conclusion

You've successfully:

  1. Cleaned up the root filesystem by removing unnecessary Python libraries and other temporary files.
  2. Created a new logical volume for Docker, ensuring Docker's data doesn't consume root filesystem space.
  3. Configured Docker to use the new volume, keeping the root filesystem clean.
  4. Prepared to set up a distributed MinIO cluster using Docker, leveraging the newly allocated storage.

By following these steps, your NAS should be well-prepared to function as a distributed part of your MinIO cluster, with Docker and MinIO operating efficiently without impacting the root filesystem's stability.

Caution: Always ensure that any deletions or modifications to system directories are performed carefully to avoid disrupting essential services. If unsure about any step, consider consulting Synology support or referring to official Synology documentation.

Feel free to reach out if you encounter any issues or need further assistance with any of the steps!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment