celery-rabbitmq 安装部署
一:Python安装
1.下载python3源码
wget https://www.python.org/ftp/python/3.5.0/Python-3.5.0.tgz
2.解压
tar xf Python-3.5.0.tgz
3.进入下载目录
cd Python-3.5.0
4.编译
./configure --prefix=/usr/local/python3
make&& make install
5.创建软链接
ln -s /usr/local/python3/bin/python3 /usr/bin/python3
ln -s /usr/local/python3/bin/pip3 /usr/bin/pip3
6.celery安装
pip install celery
ln -s /usr/local/python3/bin/celery /usr/bin/celery
二:rabbitmp安装使用
1.rabbitmq安装包下载
wget http://www.rabbitmq.com/releases/rabbitmq-server/v3.5.0/rabbitmq-server-3.5.0-1.noarch.rpm
2.erlang依赖下载
wget http://www.rabbitmq.com/releases/erlang/erlang-19.0.4-1.el7.centos.x86_64.rpm
3.安装
rpm -ivh xxx.rpm
4.配置
1)添加用户并设置密码:rabbitmqctl add_user admin 123456
2)添加权限(使admin用户对虚拟主机“/” 具有所有权限):rabbitmqctl set_permissions -p / admin ".*" ".*" ".*"
3)修改用户角色(加入administrator用户组):rabbitmqctl set_user_tags admin administrator
4)在/etc/rabbitmq/rabbitmq.config 添加:
[{rabbit, [{tcp_listeners, [5672]}, {loopback_users, ["admin"]}]}].
5.启动服务
service rabbitmq-server start
service rabbitmq-server status
service rabbitmq-server stop
6.启动监控界面
rabbitmq-plugins enable rabbitmq_management
三、监控安装
1. pip3 install flower
2.启动flower
假设在server2上启动flower,flower默认的端口是5555.
celery flower --broker=amqp://admin:admin@172.16.1.8:5672//
启动worker命令
celery -A center worker --loglevel=debug
配置mq
RABBITMQ_HOSTS = "172.16.1.8"
RABBITMQ_PORT = 5672
RABBITMQ_VHOST = '/'
RABBITMQ_USER = 'admin'
RABBITMQ_PWD = 'admin'
BROKER_URL = 'amqp://%s:%s@%s:%d/%s' % (RABBITMQ_USER, RABBITMQ_PWD, RABBITMQ_HOSTS, RABBITMQ_PORT, RABBITMQ_VHOST)
添加用户并设置密码:
rabbitmqctl add_user admin 123456
添加权限(使admin用户对虚拟主机“/” 具有所有权限):
rabbitmqctl set_permissions -p "/" admin ".*" ".*" ".*"
修改用户角色(加入administrator用户组)
rabbitmqctl set_user_tags admin administrator
后台启动服务
celery multi start w1 -A celery_app worker --loglevel=debug
启动: rabbitmq-server –detached
关闭:rabbitmqctl stop
若单机有多个实例,则在rabbitmqctlh后加–n 指定名称
新建用户:rabbitmqctl add_user xxxpwd
删除用户: rabbitmqctl delete_user xxx
查看用户:rabbitmqctl list_users
改密码: rabbimqctlchange_password {username} {newpassword}
设置用户角色:rabbitmqctlset_user_tags {username} {tag ...}
Tag可以为 administrator,monitoring, management
权限设置:set_permissions [-pvhostpath] {user} {conf} {write} {read}
Vhostpath
Vhost路径
user
用户名
Conf
一个正则表达式match哪些配置资源能够被该用户访问。
Write
一个正则表达式match哪些配置资源能够被该用户读。
Read
一个正则表达式match哪些配置资源能够被该用户访问。
celery -A worker worker --loglevel=debug -n workerA.%h -Q for_task_1,for_task_2 gevent -c 1
celery worker -A celery_app --loglevel=info -P gevent -c 1
celery -A celery_app worker --loglevel=debug
优先级配置
from kombu import Exchange, Queue
CELERY_QUEUES = (
Queue('task1', Exchange('task1', type='direct'), routing_key='task1',
consumer_arguments={'x-priority': 0}),
Queue('task2', Exchange('task2', type='direct'), routing_key='task2',
consumer_arguments={'x-priority': 10}),
)
from kombu import Queue
from kombu import Exchange
task_queues = (
Queue('priority_low', exchange=Exchange('priority', type='direct'), routing_key='priority_low'),
Queue('priority_high', exchange=Exchange('priority', type='direct'), routing_key='priority_high'),
)
task_routes = ([
('tasks.add', {'queue': 'priority_low'}),
('tasks.multiply', {'queue': 'priority_high'}),
],)
你可以限制任务的速率,这样每分钟只允许处理 10 个该类型的任务:
celeryconfig.py:
CELERY_ANNOTATIONS = {
'tasks.add': {'rate_limit': '10/m'}
}
使用 rabbitmq 缺陷及注意事项:
RabbitMQ Result Backend
The RabbitMQ result backend (amqp) is special as it does not actually store the states, but rather sends them as messages. This is an important difference as it means that a result can only be retrieved once; If you have two processes waiting for the same result, one of the processes will never receive the result!
Even with that limitation, it is an excellent choice if you need to receive state changes in real-time. Using messaging means the client does not have to poll for new states.
There are several other pitfalls you should be aware of when using the RabbitMQ result backend:
Every new task creates a new queue on the server, with thousands of tasks the broker may be overloaded with queues and this will affect performance in negative ways. If you’re using RabbitMQ then each queue will be a separate Erlang process, so if you’re planning to keep many results simultaneously you may have to increase the Erlang process limit, and the maximum number of file descriptors your OS allows.
Old results will be cleaned automatically, based on the CELERY_TASK_RESULT_EXPIRES setting. By default this is set to expire after 1 day: if you have a very busy cluster you should lower this value.
For a list of options supported by the RabbitMQ result backend, please see AMQP backend settings.
使用传统数据库达的缺陷及注意事项:
Database Result Backend
Keeping state in the database can be convenient for many, especially for web applications with a database already in place, but it also comes with limitations.
Polling the database for new states is expensive, and so you should increase the polling intervals of operations such as result.get().
Some databases use a default transaction isolation level that is not suitable for polling tables for changes.
In MySQL the default transaction isolation level is REPEATABLE-READ, which means the transaction will not see changes by other transactions until the transaction is committed. It is recommended that you change to the READ-COMMITTED isolation level.
队列优先级未测试完成
1.资料博客
https://blog.csdn.net/weixin_40475396/article/details/80439781
https://github.com/celery/celery/issues/2635
erlang 版本查询
erl -V
erlang 下载地址
1.http://erlang.org/download/otp_src_R16B03.tar.gz
2. ./configure --prefix=/usr/local/erlang --enable-hipe --enable-threads --enable-smp-support --enable-kernel-poll --without-javac
3. make && make install
** celery 队列只能实现队列内的优先级,不能实现队列之间的优先级
celery-rabbitmq 安装部署的更多相关文章
- rabbitmq安装部署
本文主要介绍rabbitmq-server-3.6.12的安装部署 # 检查是否已经安装旧版本的软件 rpm -qa|grep erlang rpm -qa|grep rabbitmq # 如果之前 ...
- 10分钟学会RabbitMQ安装部署
一.单机版的 RabbitMQ 的安装部署 1.安装 Erlang 环境 wget http://erlang.org/download/otp_src_19.3.tar.gz tar -zxvf o ...
- 一、WINDOWS下 RabbitMQ安装部署
安装需要用管理员权限,全部右键管理员身份运行.建议安装到虚拟机里面,免得影响日常使用. 1.下载 https://dl.bintray.com/rabbitmq/all/rabbitmq-serv ...
- RabbitMQ的安装部署
RabbitMQ安装部署 一.软件准备 wget http://erlang.org/download/otp_src_19.3.tar.gz wget http://www.rabbitmq.com ...
- Linux 安装 RabbitMQ 3.7.8 安装部署
Linux 安装 rabbitmq 3.7.8 安装部署 安装 ncurses 1.安装GCC GCC-C++ Openssl等模块 yum -y install make gcc gcc-c++ k ...
- Windows下RabbitMQ安装,部署,配置
安装部署 1.当前环境以及参考资料出处 部署环境:windows server 2008 r2 enterprise 官方安装部署文档:http://www.rabbitmq.com/install- ...
- Docker:安装部署RabbitMQ
前言 今天原本想讲解SpringBoot集成RabbitMQ的,临近开始写时才发现家里的电脑根本没有安装RabbitMQ呀.这下只好利用已有的阿里云服务器,直接Docker安装一下了,顺道记录下,算是 ...
- Centos7安装部署Rabbitmq教程
依赖关系: 版本依赖一定要提前看清楚. RabbitMQ相关版本依赖关系查看 https://www.rabbitmq.com/which-erlang.html 可以看到要求版本Erlang21.3 ...
- airflow 安装配置celery+rabbitmq celery+redis
AirFlow的安装可以参考:https://www.cnblogs.com/braveym/p/11378851.html 这里介绍的是AirFlow 安装配置celery+rabbitmq 和 ...
- Centos 6.5 Rabbitmq 安装和集群,镜像部署
centos 6.5 rabbitmq 安装和集群,镜像部署 安装erlang: yum install gcc glibc-devel make ncurses-devel openssl-deve ...
随机推荐
- [i.MX6q]i.MX6q处理器,linux操作系统平台搭建 从SD卡启动系统
转自:http://www.07net01.com/linux/2016/02/1232094.html 参照1:http://blog.csdn.net/girlkoo/article/detail ...
- [转]基于Storm的实时数据处理方案
1 文档说明 该文档描述的是以storm为主体的实时处理架构,该架构包括了数据收集部分,实时处理部分,及数据落地部分. 关于不同部分的技术选型与业务需求及个人对相关技术的熟悉度有关,会一一进行分析. ...
- log4cplus基本用法
说起日志系统,不得不提大名鼎鼎的Log4j.特别是使用Java的人们,能够说是无人不知无人不晓无人不用. Log4j以其简单的使用方式(引入一个jar包.一行代码就可以调用).灵活(可通过配置文件任意 ...
- Ci 错误 In order to use the Session class you are required to set an encryption key in your config file.
说明自己没有给session 加密 ,在配置文件config中 $config['encryption_key'] = '2rf3f3fwefwefwef2';
- (转)android从应用到驱动之—camera(1)---程序调用流程
一.开篇 写博客还得写开篇介绍,可惜,这个不是我所擅长的.就按我自己的想法写吧. 话说camera模块,从上层到底层一共包含着这么几个部分: 1.apk------java语言 2.camera的ja ...
- sed替换
1. sed可以替换给定的文本中的字符串,可以利用正则表达式进行匹配$ sed 's/pattern/replace_string/' file或者$ cat file | sed 's/patter ...
- strust2自定义interceptor的基本方法及操作
需求:制作一个网站需要用户登陆后才能查看,即一个权限的问题 1.首先明确在用户没登陆前有两个Action请求是可以通过的,即注册和登陆. 2.创建拦截器,如UserLoginInterceptor.j ...
- php如何优化压缩的图片
php程序开发中经常涉及到生成缩略图,利用php生成缩略图这个过程本身没难度,但是你知道php能够优化调节生成的缩略图的质量吗?也就是说php能够控制生成缩略图的清晰度以及生成后的缩略图的体积.下面我 ...
- 【NLP】主题识别文档
http://www.biostatistic.net/thread-94974-1-1.html http://www.doc88.com/p-9843685205530.html http://w ...
- 漫游kafka实战篇之搭建Kafka开发环境(3)
上篇文章中我们搭建了kafka的服务器,并可以使用Kafka的命令行工具创建topic,发送和接收消息.下面我们来搭建kafka的开发环境. 添加依赖 搭建开发环境需要引入kafka的jar包 ...