首先咱们进行scrapy-redis分布式爬取的时候 先了解一下redisredis
那么了解了以后咱们进行设置 在项目的 setting当中数据库
# 过滤器 去重
DUPEFILTER_CLASS = "scrapy_redis.dupefilter.RFPDupeFilter"
# 调度器
SCHEDULER = "scrapy_redis.scheduler.Scheduler"
# 调度状态持久化 也能够不用设置
SCHEDULER_PERSIST = True
# 请求调度使用优先队列 也能够不用设置
SCHEDULER_QUEUE_CLASS = 'scrapy_redis.queue.SpiderPriorityQueue'
# redis 使用的端口和地址
REDIS_HOST = '127.0.0.1'
REDIS_PORT = 6379
或者使用 REDIS_URL = 'redis://127.0.0.1:6379'
设置完成以后 咱们须要安装 redis可视化的工具 将他打开咱们设置
点击咱们进行加入缓存
就设置一下名字和host就能够 通常若是须要多台机器进行一块儿爬取的话那么咱们在设置host的时候 在本身电脑cmd命令行内 ipconfig 查看本身的ip地址 写入到host里面,你们还得记得将本身电脑的防火墙关闭 另一台电脑须要链接你的电脑进行爬取网络
将本身代码 py文件内 进行导入RedisCrawlSpider
咱们在安装redis 的文件内找到scrapy
开启redis服务的图像分布式
输入cmd以后出现的命令ide
输入完成以后工具
显示已经完成那么咱们在运行咱们的项目 就能够了 队列里就有数据了oop
遇到的问题 以下:this
1. 若是咱们开启 redis可视化工具的时候会报下面的错误
这是因为咱们开启redis服务 将服务开启以后就能够链接了
2. 咱们在链接 另一台电脑进行一块儿爬取的时候 会请求超时
那么 解决的方法就是 将对方的防火墙进行关闭 这样是链接成功
3. 咱们在进行远程链接的时候 须要输入外网的ip 10.30. 或者 192.168.等 因此在链接时常常会报错误
连接redis 时只能经过本地localhost (127.0.0.1)这个来连接,而不能用网络ip(192.168..)这个连接,若是用网络ip 连接会报如下的错误:
(error) DENIED Redis is running in protected mode because protected mode is enabled, no bind address was specified, no authentication password is requested to clients. In this mode connections are only accepted from the loopback interface. If you want to connect from external computers to Redis you may adopt one of the following solutions: 1) Just disable protected mode sending the command 'CONFIG SET protected-mode no' from the loopback interface by connecting to Redis from the same host the server is running, however MAKE SURE Redis is not publicly accessible from internet if you do so. Use CONFIG REWRITE to make this change permanent. 2) Alternatively you can just disable the protected mode by editing the Redis configuration file, and setting the protected mode option to 'no', and then restarting the server. 3) If you started the server manually just for testing, restart it with the '--protected-mode no' option. 4) Setup a bind address or an authentication password. NOTE: You only need to do one of the above things in order for the server to start accepting connections from the outside.
解决的方法:
进入它以后咱们设置 后面两个不用动也能够
1)打开配置文件把下面对应的注释掉
# bind 127.0.0.1
2)Redis默认不是以守护进程的方式运行,能够经过该配置项修改,使用yes启用守护进程,设置为no
daemonize no
3)保护模式
protected-mode no
将它给 注释了 我给你们发的可视化的工具包内的设置已经改完你们就不用动了