Getting blue-green right from the start saves hours of debugging later. In this comprehensive guide, we'll cover everything from initial setup to production-ready configuration, including strategy and migration considerations.
Prerequisites
- A VPS running Ubuntu 22.04 or later (2GB+ RAM recommended)
- Root or sudo access to the server
- Access to both source and destination servers
- Sufficient storage on the destination server
- Basic familiarity with the Linux command line
Pre-Migration Assessment
When scaling this setup, consider vertical scaling (adding more RAM/CPU) first, as it's simpler to implement. Horizontal scaling adds complexity but may be necessary for high-traffic applications.
# Pre-migration data sync with rsync
rsync -avzP --delete \
--exclude='/dev' --exclude='/proc' --exclude='/sys' --exclude='/tmp' \
-e 'ssh -p 22' \
root@old-server:/ /mnt/migration/
# Final sync with minimal downtime
rsync -avzP --delete \
-e 'ssh -p 22' \
root@old-server:/var/www/ /var/www/
Make sure to restart the service after applying these changes. Some settings require a full restart rather than a reload to take effect.
Data Transfer Process
It's recommended to test this configuration in a staging environment before deploying to production. This helps identify potential compatibility issues and allows you to benchmark performance differences.
# Database migration
# On source server:
mysqldump --single-transaction --routines --triggers --all-databases | gzip > db_backup.sql.gz
# Transfer to destination:
scp db_backup.sql.gz root@new-server:/tmp/
# On destination server:
gunzip < /tmp/db_backup.sql.gz | mysql -u root
Note that file paths may vary depending on your Linux distribution. The examples here are for Debian/Ubuntu; adjust paths accordingly for RHEL/CentOS-based systems.
Summary
You've successfully configured blue-green on your VPS. Remember to monitor performance, keep your software updated, and maintain regular backups. If you run into issues, consult the official documentation or open a support ticket for assistance.