I have the Redis server working perfectly locally on my machine. I couldn’t find any proper documentation on deploying it on a digital ocean droplet that is already working. Do I have to create a new droplet for Redis and Celery? And how do I keep my Redis server to an already existing droplet?
I couldn’t interpret what was given in the documentation, so please help code through this.
This textbox defaults to using Markdown to format your answer.
You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!
These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.
Hi there!
You don’t necessarily need to create a new Droplet for Redis and Celery; you can set them up on your existing Droplet as long as it has sufficient resources to handle the additional load, in some cases Redis could use quite a bit of resources like RAM.
Alternatively, you can also use a Managed Redis cluster instead of running it on a Droplet:
Here’s a step-by-step guide to get you started with a Redis installed on the same Droplet:
1. Installing Redis on Your Droplet
SSH into Your Droplet: First, connect to your DigitalOcean droplet via SSH.
Install Redis: Update your package lists and install Redis using the following commands:
Configure Redis (Optional): If needed, you can configure Redis by editing its configuration file:
After making changes, restart Redis to apply them:
For more details here is an in-depth guide for this as well:
2. Setting Up Celery in Your Django Project
Install Celery: Add Celery to your Django project by installing it using pip:
Configure Celery: Create a new file
celery.py
in your Django project’s main module (the same directory assettings.py
).In your
__init__.py
file in the same directory, add the following to make sure the app is loaded when Django starts:Update Django Settings: In your
settings.py
, add the Celery configuration:Adjust the Redis URL if your Redis server is not running on the default port or if it’s running on a different machine.
3. Running Celery
Run Celery Worker: In your Django project directory, run the Celery worker:
Run Celery Beat (Optional): If you have periodic tasks, run Celery Beat:
On another note, to ensure that Redis and Celery run continuously and restart on failure or server reboot, you can set them up as system services using systemd.
Create a systemd Service File for Celery: Create a new file, e.g.,
/etc/systemd/system/celery.service
, and add the following configuration (adjust paths and names as needed):Enable and Start the Celery Service:
Let me know if you have any questions!
Best,
Bobby