Introduction: Django is a Web-based Python plug-in, celery is a task queue, and rabbitmq is a message queue. Such a system is deployed for asynchronous task execution.
0. Install tk-8.5.7-5.el6.x86_64 when installing the system, if not installed, you can install from the disc
1. If the yum source is unavailable, you can use the epel source.
Download: http://mirrors.ustc.edu.cn/epel/6/x86_64/epel-release-6-8.noarch.rpm
Rpm-IVH epel-release-6-8.noarch.rpm
Set gpgcheck = 0 in/etc/yum. Repos. D.
MV ns6-adv.repo ns6-adv.repo.bak
2. Install pip (Python package management tool)
Wget http://python-distribute.org/distribute_setup.py
Sudo Python distribute_setup.py
Wget https://github.com/pypa/pip/raw/master/contrib/get-pip.py
Sudo Python get-pip.py
You can use Pip help to view help information. For simple use, you only need Pip search and PIP install.
3. Install Django
PIP install Django
4. Install celery
Easy_install celery
5. Install Python-Django-Celery
Easy_install Django-Celery
In ubuntu (easy_install Python-Django-celery)
6. Install rabbitmq-server (install TK first)
Yum install rabbitmq-server.noarch librabbitmq. x86_64
Run:
Rabbitmq-Server &
View status: rabbitmqctl status
Service rabbitmq-server START | stop
After the project is written, start celery as follows:
Python manage. py celeryd -- loglevel = Info-F/var/log/celery. log &
Python manage. py runserver
Configure celery to run 1 for demon
Https://github.com/celery/celery/tree/master/extra/centos download required script
CP celeryd/etc/init. d/
CP celeryd. sysconfig/etc/sysconfig/celeryd
Modify Configuration:
# contents should be placed in the file /etc/sysconfig/celeryd,copy this file to /etc/sysconfig/celeryd,copy# Names of nodes to start (space-separated)CELERYD_NODES="localhost"# Where to chdir at start. This could be the root of a virtualenv.CELERYD_CHDIR="/opt/openstack/httpd/oadt"# How to call celeryd-multiCELERYD_MULTI="$CELERYD_CHDIR/manage.py celeryd_multi"# How to call "manage.py celery"#CELERY_BIN="$CELERYD_CHDIR/manage.py celery"# Extra argumentsCELERYD_OPTS="--time-limit=300 --concurrency=8 --loglevel=INFO"# Name of the celery config module.CELERY_CONFIG_MODULE="celeryconfig"# Create log/pid dirs, if they don't already existCELERY_CREATE_DIRS=1# %n will be replaced with the nodenameCELERYD_LOG_FILE="/var/log/OADT/oadtdeploy.log"CELERYD_PID_FILE="/var/run/celery/%n.pid"# Workers run as an unprivileged userCELERYD_USER=rootCELERYD_GROUP=root# Name of the projects settings module.export DJANGO_SETTINGS_MODULE="oadt.settings"
Service celeryd restart
Service celeryd stop
Configure celery to run 2 for demon (use supervisor)
Install supervisord with APT-Get
Create/etc/Supervisor/CONF. d/celery. conf Config File
Paste somethis In the celery. conf file
[Program: Celery]
Directory =/my_project/
Command =/usr/bin/Python manage. py celery worker
Plus (if you need) some optional and useful stuff (with dummy values)
User = celery_user
Group = celery_group
Stdout_logfile =/var/log/celeryd. Log
Stderr_logfile =/var/log/celeryd. Err
Autostart = true
Environment = Path = "/Some/path/", foo = "bar"
Restart Supervisor (or do supervisorctl reread; supervisorctl Add celery)
After that you get the nice CTL commands to manage the celery process:
Supervisorctl start/restart/Stop celery
Supervisorctl tail [-F] celery [stderr]
Deploy to Apache
Create oadt. conf and put it under/etc/httpd/CONF. d. The content is as follows:
WSGIScriptAlias / /opt/openstack/httpd/oadt/oadt/wsgi.pyWSGIPythonPath /opt/openstack/httpd/oadt/<Directory /opt/openstack/httpd/oadt/><Files wsgi.py>Order deny,allowAllow from all</Files></Directory>Alias /static/ /opt/openstack/httpd/oadt/hosts/static/<Directory /opt/openstack/httpd/oadt/hosts/static/>Order deny,allowAllow from all</Directory>
Restart service httpd restart