scrapy 如何鏈接有密碼的redis scrapy-redis 設置redis 密碼 scrapy-redis如何為redis配置密碼


# 使用scrapy_redis的調度器
SCHEDULER = "scrapy_redis.scheduler.Scheduler"
# 使用scrapy_redis的去重機制
DUPEFILTER_CLASS = "scrapy_redis.dupefilter.RFPDupeFilter"
# 在ITEM_PIPELINES中添加redis管道
# 'scrapy_redis.pipelines.RedisPipeline': 200
# 定義redis主機地址和端口號



REDIS_HOST = '176.140.7.197'
REDIS_PORT = 6379

# 設置密碼
REDIS_PARAMS = {
'password': 'admin',
}



windows下scrapy-redis如何為redis配置密碼
1. 環境
系統:win7
scrapy-redis
redis 3.0.5
python 3.6.1
2. 為redis-server配置密碼並啟動
redis在windows下的安裝與配置,請參考這篇文章:http://blog.csdn.net/zwq912318834/article/details/78770209
2.1. 修改配置文件
找到文件redis.windows.conf,對其進行如下設置:

################################## SECURITY ###################################

# Require clients to issue AUTH <PASSWORD> before processing any other
# commands. This might be useful in environments in which you do not trust
# others with access to the host running redis-server.
#
# This should stay commented out for backward compatibility and because most
# people do not need auth (e.g. they run their own servers).
#
# Warning: since Redis is pretty fast an outside user can try up to
# 150k passwords per second against a good box. This means that you should
# use a very strong password otherwise it will be very easy to break.
#
# requirepass foobared
requirepass redisPasswordTest666666

一定要注意:requirepass redisPasswordTest666666 前面不能有任何空格和字符。
2.2. 啟動redis服務
啟動redis-server時,一定要加上 redis.windows.conf 這個參數,否則redis會使用默認的參數進行啟動,這些配置信息都不會生效……
redis-server.exe redis.windows.conf
1


2.3. 使用Redis Desktop Manager進行驗證
不使用密碼,無法登錄

 

使用密碼,順利登錄

3. scrapy-redis分布式爬蟲使用密碼進行redis連接
關於原理解釋,請參考文章:http://blog.csdn.net/zwq912318834/article/details/78904192
# 使用 redis 密碼
class MySpider(RedisSpider):
"""Spider that reads urls from redis queue (myspider:start_urls)."""
name = 'xxxx'
redis_key = 'xxxx:start_urls'

# ……
custom_settings = {
'LOG_LEVEL': 'DEBUG',
'DOWNLOAD_DELAY': 0,

# 指定redis數據庫的連接參數
'REDIS_HOST': '192.168.1.99',
'REDIS_PORT': 6379,

# 指定 redis鏈接密碼,和使用哪一個數據庫
'REDIS_PARAMS' : {
'password': 'redisPasswordTest666666',
},
}

  


4. 注意事項
在windows下,安裝方式有兩種:程序安裝和壓縮包解壓。上面提到的方法是壓縮包解壓的方式。而安裝版的Redis服務是自啟動的,直接通過redis-server.exe啟動,但是,啟動時並沒有加載Redis的配置文件redis.windows.conf,這樣就導致 redis 中的密碼設置不生效。


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM