scrapyd 参考(https://www.jianshu.com/p/2a189127901a)
一 Scrapyd简介
Scrapyd 是一个用来部署和运行 Scrapy 项目的应用,由 Scrapy 的开发者开发。其可以通过一个简单的 Json API 来部署(上传)或者控制你的项目。
Scrapyd 可以用来管理多个项目,并且每个项目还可以上传多个版本,不过只有最新的版本会被使用。
在安装并开启 Scrapyd 之后,它将会挂起一个服务来监听运行爬虫的请求,并且根据请求为每一个爬虫启用一个进程来运行。Scrapyd 同样支持同时运行多个进程,进程的数量由max_proc 和 max_proc_per_cpu 选项来限制。
二 Scrapyd 安装部署
通常来说,使用 pip 安装 Scrapyd 即可:
$ pip install scrapyd
部署 scrapy
rsync -avz scrapyd crawler_server1:/data --exclude '*logs' --exclude '*.pyc' --exclude '*.db' --exclude '*env' --exclude '*eggs' --exclude '*.pid' rsync -avz scrapyd crawler_server2:/data --exclude '*logs' --exclude '*.pyc' --exclude '*.db' --exclude '*env' --exclude '*eggs' pip install -r requirements.txt
安装成功后使用以下命令即可以开启 Scrapyd 服务:
使用虚拟环境运行
virtualenv -p /usr/bin/python3.6 env
source env/bin/activate python scripts/scrapyd_run.py
三 scrapyd 配置文件
Scrapyd 将会在以下地址搜索配置文件,在解析的过程中更高的配置文件拥有更高的优先级:
/etc/scrapyd/scrapyd.conf(Unix)c:\scrapyd\scrapyd.conf(Windows)/etc/scrapyd/conf.d/*(in alphabetical order, Unix)scrapyd.conf~/.scrapyd.conf(users home directory)
配置文件中支持配置以下选项:
http_portScrapyd的API监听的端口,默认为6800。bind_address网页和Json服务监听的IP地址,默认为
127.0.0.1。max_proc同时启动的最大Scrapy进程数,如果没有设置或者设置为
0,那么将会使用当前cpu可用的核数乘以max_proc_per_cpu的值。默认为0。max_proc_per_cpu每个cpu能同时启动的最大Scrapy进程数。默认为
4。debug是否开启
debug模式,默认为off。开启之后,如果在调用Scrapy的Json API的时候出错,则会返回详细的traceback信息。eggs_dir项目的
eggs文件存储的目录。dbs_dir项目存储数据库的目录,也包括爬虫队列。
logs_dir存储
Scrapy日志的目录。如果不希望存储日志,那么需要设置成如下所示:logs_dir =
items_dir存储
items的目录,一般来说不需要设置这个选项,因为抓取下来的数据都会存到数据库中。如果设置这个选项,那么将会覆盖Scrapy的FEED_URL设置,将抓取下来的items保存到指定目录。jobs_to_keep每个
spider保留多少个完成的job,默认为5。这更多指的是item和log。finished_to_keep启动器中保留的已完成进程的数量,默认为
100。poll_interval轮询队列的间隔,以秒为单位,默认值为
5,可以为浮点数。runner用来启动子进程的启动器,可以自定义启动的模块。
node_name每个节点的节点名称,默认为
${socket.gethostname()}。
以下是一个默认的配置文件的例子:
[scrapyd]
eggs_dir = eggs
logs_dir = logs
items_dir =
jobs_to_keep = 5
dbs_dir = dbs
max_proc = 0
max_proc_per_cpu = 4
finished_to_keep = 100
poll_interval = 5.0
bind_address = 127.0.0.1
http_port = 6800
debug = off
runner = scrapyd.runner
application = scrapyd.app.application
launcher = scrapyd.launcher.Launcher
webroot = scrapyd.website.Root [services]
schedule.json = scrapyd.webservice.Schedule
cancel.json = scrapyd.webservice.Cancel
addversion.json = scrapyd.webservice.AddVersion
listprojects.json = scrapyd.webservice.ListProjects
listversions.json = scrapyd.webservice.ListVersions
listspiders.json = scrapyd.webservice.ListSpiders
delproject.json = scrapyd.webservice.DeleteProject
delversion.json = scrapyd.webservice.DeleteVersion
listjobs.json = scrapyd.webservice.ListJobs
daemonstatus.json = scrapyd.webservice.DaemonStatus
四 配置访问认证
由于 Scrapyd 本身不提供访问的认证,所以接口都是暴露在公共网络中的,需要使用 Nginx 配置反向代理等方法来设置访问认证。
五 API
在开启了 scrapyd 服务之后,就可以通过 Scrapyd 提供的 API 接口来操作你的 Scrapy 项目了。
daemonstatus.json
用来检查服务器的负载状态。支持的请求方法:GET。
request例子:
curl http://localhost:6800/daemonstatus.json
response例子:
{ "status": "ok", "running": "", "pending": "", "finished": "", "node_name": "node-name" }
addversion.json
给项目增加一个版本,如果项目不存在的话那么就创建一个项目。这个接口主要被用来上传项目或者更新项目版本。支持的请求方法:POST。
参数:
project(string, required) - 项目的名称version(string, required) - 项目的版本egg(file, required) - 一个包含项目代码的 egg文件
request例子:
$ curl http://localhost:6800/addversion.json -F project=myproject -F version=r23 -F egg=@myproject.egg
相应例子:
{"status": "ok", "spiders": 3}
schedule.json
调度运行一个爬虫(也成为 job ),并返回一个 jobid。支持的请求方法:POST。
参数:
project(string, required) - 项目的名称spider(string, required) - 爬虫的名称setting(string, optional) - 爬虫运行时要用到的Scrapy设置jobid(string, optional) - 用来作为标识的jobid,会覆盖掉默认生成的UUID_version(string, optional) - 使用的项目版本- 任何其他的参数将会传递作为爬虫的参数
request例子:
$ curl http://localhost:6800/schedule.json -d project=myproject -d spider=somespider
response例子:
{"status": "ok", "jobid": "6487ec79947edab326d6db28a2d86511e8247444"}
以下是传递 spider 参数和 setting 参数的例子:
$ curl http://localhost:6800/schedule.json -d project=myproject -d spider=somespider -d setting=DOWNLOAD_DELAY=2 -d arg1=val1
cancel.json
取消一个 job 的运行,如果这个 job 处于等待的状态,那么将会被移除,如果这个 job 正在运行,那么它将会被终止。支持的请求方法:POST。
参数:
project(string, required) - 项目的名称job(string, required) -job的id
request例子:
$ curl http://localhost:6800/cancel.json -d project=myproject -d job=6487ec79947edab326d6db28a2d86511e8247444
response例子:
{"status": "ok", "prevstate": "running"}
listprojects.json
获取上传到服务器的项目列表。支持请求方法:GET,无参数。
request例子:
$ curl http://localhost:6800/listprojects.json
response例子:
{"status": "ok", "projects": ["myproject", "otherproject"]}
listversions.json
获取某个或某些项目的版本列表。返回的版本将会按顺序排列,最后的那个版本是当前正在使用的版本。支持请求参数:GET。
参数:
project(string, required) - 项目名称
request例子:
$ curl http://localhost:6800/listversions.json?project=myproject
response例子:
{"status": "ok", "versions": ["r99", "r156"]}
listspiders.json
默认获取某个项目最新版本中的spider列表。支持的请求方法:GET。
参数:
project(string, required) - 项目的名称_version(string, optional) - 检查的项目版本
request例子:
$ curl http://localhost:6800/listspiders.json?project=myproject
response例子:
{"status": "ok", "spiders": ["spider1", "spider2", "spider3"]}
listjobs.json
获取某个项目正在等待、运行或者运行完毕的job列表。支持的请求类型:GET。
参数:
project(string, required) - 项目名称
request例子:
$ curl http://localhost:6800/listjobs.json?project=myproject
response例子:
{"status": "ok",
"pending": [{"id": "78391cc0fcaf11e1b0090800272a6d06", "spider": "spider1"}],
"running": [{"id": "422e608f9f28cef127b3d5ef93fe9399", "spider": "spider2", "start_time": "2012-09-12 10:14:03.594664"}],
"finished": [{"id": "2f16646cfcaf11e1b0090800272a6d06", "spider": "spider3", "start_time": "2012-09-12 10:14:03.594664", "end_time": "2012-09-12 10:24:03.594664"}]}
delversion.json
删除某个项目的某个版本,如果这个项目不再有能用的版本,那么项目也会被删除。支持的请求方法:POST。
参数:
project(string, required) - 项目名称version(string, required) - 要删除的项目版本
request例子:
$ curl http://localhost:6800/delversion.json -d project=myproject -d version=r99
response例子:
{"status": "ok"}
delproject.json
删除指定项目。支持请求方法:POST。
参数:
project(string, required) - 项目名称
request例子:
$ curl http://localhost:6800/delproject.json -d project=myproject
response例子:
{"status": "ok"}
scrapyd 参考(https://www.jianshu.com/p/2a189127901a)的更多相关文章
- python cookie登录DVWA,phpstudy搭建DVWA参考https://www.jianshu.com/p/97d874548300
import requestsheader={"User-Agent": "Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleW ...
- [转]https://www.jianshu.com/p/06443248f4d8
eos是什么? 原文 https://www.jianshu.com/p/06443248f4d8 简介 用一句话来定义eos,即:区块链操作系统,支持在它之上构建dapp,支持智能合约.帐户.身份验 ...
- fastdfs(https://www.jianshu.com/p/1c71ae024e5e)
参考 官方网站:https://github.com/happyfish100/ 配置文档:https://github.com/happyfish100/fastdfs/wiki/ 参考资料:htt ...
- 当我写下Map<String,Object> map = new HashMap<>() https://www.jianshu.com/p/6b2e350e99be
当我写下Map<String,Object> map = new HashMap<>();我到底在写什么? 我什么时候会写HashMap? 一个函数同时需要返回 多种 状态的情 ...
- Zabbix调优不完全指南(https://www.jianshu.com/p/2d911d55448f)
从学习搭建zabbix到完成各类监控.调优.二次开发已经过去了两年,期间通过QQ学习群.zabbix官方社区.各个技术博客整理学习了不少关于各种报错的处理方法,现在将常见的一些报错处理方法整理出来分享 ...
- 接口测试之——Charles抓包及常见问题解决(转载自https://www.jianshu.com/p/831c0114179f)
简介 Charles其实是一款代理服务器,通过成为电脑或者浏览器的代理,然后截取请求和请求结果达到分析抓包的目的.该软件是用Java写的,能够在Windows,Mac,Linux上使用,安装Charl ...
- jar与war包区别,转自https://www.jianshu.com/p/3b5c45e8e5bd
https://www.jianshu.com/p/3b5c45e8e5bd
- 参考 https://raspberrypi.stackexchange.com/questions/3617/how-to-install-unrar-nonfree > 1.卸载unrar-free。 $ sudo apt-get remove unrar-free \ 2.通过编辑确保您拥有源存储库/etc/apt/sources.list。 $ cat /etc/apt/sources.
from my CSDN: https://blog.csdn.net/su_cicada/article/details/86939944 参考 https://raspberrypi.stacke ...
- https://www.jianshu.com/p/1038c6170775
import os # 方法一: os.walk实现 def items_dir(rootname): l = [] for main_dir, dirs, file_name_list in os. ...
随机推荐
- VS2017在Release下编译错误C1001
在使用VS2017编译C程序时,Debug模式下编译链接执行都没有问题,但是一转到Release模式下就出现下列编译链接错误(IDE:VS2017 /VC++/MFC程序,目标平台x86+Win32位 ...
- tp5 select回显
<select name="role_id" id="" class="form-control" required> {vol ...
- Spring.net方法的替换
.为什么有时候你再执行某个方法的时候比如某个操作 a.权限验证 b.任务执行 当我执行到这个方法的时候,我可以先验证权限,如果验证不通过则替换到另一个方法去执行 public class MyValu ...
- zigbee初探
什么是zigbee? 1.它是一种通信方式,一种通信协议: 2.其作用就是构建一个类似无线局域网的东西:如果这个局域网用于传感器的数据收集.监控,那么这个网络就叫做无线传感器网络. 应用领域:家居.工 ...
- Hibernate环境搭建
Hibernate的环境搭建,主要步骤分为一下四步: 首先创建一个工程,在工程里创建一个实体类User,在这个实体类中必须包含无参的构造器,和这个类对属性的存取方法(getter and setter ...
- Webstorm 10.0.4 配置
1. 更换为sublime text的keymaps: https://github.com/ekaragodin/idea-sublime-keymap (idea-sublime-keymap- ...
- CMDB和运维自动化
IT运维,指的是对已经搭建好的网络,软件,硬件进行维护.运维领域也是有细分的,有硬件运维和软件运维 硬件运维主要包括对基础设施的运维,比如机房的设备,主机的硬盘,内存这些物理设备的维护 软件运维主要包 ...
- linux常用Java程序员使用命令(一)
pwd 显示当前路径cd 切换目录 . .. ~ls 显示文件(夹) -l 显示详细信息 -a 显示全部,包括隐藏文件(夹) mkdir 创建文件夹 -p 递归创建 touch 创建空白文件 echo ...
- 保证Service不被Kill的解决方案
1.Service设置成START_STICKY(onStartCommand方法中),kill 后会被重启(等待5秒左右),重传Intent,保持与重启前一样 2.通过 startForegroun ...
- (转)深入理解最强桌面地图控件GMAP.NET --- 百度地图
原文地址:http://www.cnblogs.com/enjoyeclipse/archive/2013/01/14/2859026.html 前两篇介绍了GMAP.NET的一些基本功能和如何在自己 ...