Here I choose Redis as the middleman for the celery asynchronous task, and the system chooses CentOS6.5 64 bits.
For the installation of Redis, celery and supervisor see the official documentation.
When the installation is complete:
1, create an instance of celery/home/user_00/learn/tasks.py file
tasks.py:
#-*-coding:utf-8-*- fromCeleryImportcelery, Platformsapp= Celery ('Tasks', backend='REDIS://LOCALHOST:6379/1', broker='redis://localhost:6379/0')#celery cannot ROOT user start resolution (c_force_root Environment), plus this line can bePlatforms. C_force_root =True@app.taskdefAdd (x, y):returnX + y
2, start the Redis service and the Celery professional server,
Redis-server
Celery-a tasks worker--loglevel=info
Open the Python shell in the tasks.py file sibling directory:
inch [1]: From tasks import add inch [2]: Add.delay (4, 6) out[2]: <AsyncResult:3e346dba-f8dc-4295-bc68-bba0bf9c1f94>
In [ten]: Result.get ()
OUT[10]: 10
You can also see the log output of the celery service: 10, this time close the celery service, and next add it to the Supervisor process Manager
3, after installing Supoervisor, generate Supervisor configuration file
echo_supervisord_conf >/etc/supervisord.conf
With vim, open the configuration file you just generated supervisord.conf, and edit the last two lines to read:
= Sv.ini
This is the time to create the/etc/sv.ini file:
Touch/etc/sv.ini
Edit the Sv.ini file to write the following:
[Program:celery]command=celery-a tasks worker--loglevel=infodirectory=/home/user_00/ Learnstdout_logfile=/home/user_00/learn/logs/celery.logautorestart=trueredirect_ stderr=true
Create/home/user_00/learn/logs/celery.log at the same time
This time, the process called celery is ready to be configured.
4. After changing the configuration file, to load the latest configuration file:
SUPERVISORCTL Update
To start the Supervisor service:
Supervisord
Enter the Supervisor management interface:
Supervisorctl
To start the celery process:
Start celery
5. Test it at this time.
Enter the/home/user_00/learn/logs directory and monitor the Celery.log
- F *
Open the Python shell in the tasks.py file sibling directory:
In [1]: From Tasks import AddIn [2]: Add.delay (4, 6) out[2]: <asyncresult: 3e346dba-f8dc-4295-bc68-bba0bf9c1f94>
In [ten]: Result.get ()
OUT[10]: 10
You can see the output in the log information of the monitor: 10
This is the time to complete the example of using supervisor to manage the celery process.
Celery and supervisor with the Supervisor management celery process