neokylin6,centos,redhat,fedora 中django+celery+rabbitmq环境安装过程

简介

django是基于web的python插件,celery是一个任务队列,而rabbitmq是消息队列,部署这样一套系统用于异步执行任务。



0.安装系统时候要安装 tk-8.5.7-5.el6.x86_64,若没有安装可以从光盘安装

1.yum源不好用的可以使用epel的源

下载:http://mirrors.ustc.edu.cn/epel/6/x86_64/epel-release-6-8.noarch.rpm
rpm -ivh epel-release-6-8.noarch.rpm
去/etc/yum.repos.d下设置gpgcheck=0

mv ns6-adv.repo  ns6-adv.repo.bak

2.安装pip(python包管理工具)

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

可以通过pip help来查看帮助。简单用的话只要pip search和pip install就好了。

3.安装django

pip install django

4.安装celery

easy_install celery

5.安装python-django-celery

easy_install django-celery
ubuntu中(easy_install python-django-celery)

6.安装 rabbitmq-server (tk需要先安装好)

yum install rabbitmq-server.noarch librabbitmq.x86_64 


使用

运行:
rabbitmq-server &
查看状态:rabbitmqctl  status
service rabbitmq-server start|stop

项目写好后,如下方式启动celery
python manage.py celeryd --loglevel=INFO -f /var/log/celery.log&
python manage.py runserver

配置celery为demon运行1

https://github.com/celery/celery/tree/master/extra/centos 下载所需脚本
cp celeryd /etc/init.d/
cp celeryd.sysconfig /etc/sysconfig/celeryd
修改配置:
# 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-multi
CELERYD_MULTI="$CELERYD_CHDIR/manage.py celeryd_multi"
# How to call "manage.py celery"
#CELERY_BIN="$CELERYD_CHDIR/manage.py celery"
# Extra arguments
CELERYD_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 exist
CELERY_CREATE_DIRS=1


# %n will be replaced with the nodename
CELERYD_LOG_FILE="/var/log/OADT/oadtdeploy.log"
CELERYD_PID_FILE="/var/run/celery/%n.pid"


# Workers run as an unprivileged user
CELERYD_USER=root
CELERYD_GROUP=root


# Name of the projects settings module.
export DJANGO_SETTINGS_MODULE="oadt.settings"

service celeryd restart
service celeryd stop

配置celery为demon运行2(使用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]



部署到apache

创建oadt.conf放在/etc/httpd/conf.d下,内容如下

WSGIScriptAlias / /opt/openstack/httpd/oadt/oadt/wsgi.py
WSGIPythonPath /opt/openstack/httpd/oadt/

<Directory /opt/openstack/httpd/oadt/>
<Files wsgi.py>
Order deny,allow
Allow from all
</Files>
</Directory>


Alias /static/ /opt/openstack/httpd/oadt/hosts/static/

<Directory /opt/openstack/httpd/oadt/hosts/static/>
Order deny,allow
Allow from all
</Directory>

重启service httpd restart 既可

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

day walker

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值