我的scrapy_redis在windows上跑起来了,现在准备移植到Linux上。
项目中用到了MongoDb,Redis两个数据库,用到了scrapy框架,用到了scrapy-redis模块。
1. Linux上,安装MongoDb, 配置path
2. Linux上,安装Redis, 配置path
2.1 Redis中配置下,允许共享。
3.1 配置redis.conf 将 bind 127.0.0.1 使用#注释掉,改为# bind 127.0.0.1(bind配置的是允许连接的ip,默认只允许本机连接;若远程连接需注释掉,或改为0.0.0.0) 将 protected-mode yes 改为 protected-mode no(3.2之后加入的新特性,目的是禁止公网访问redis cache,增强redis的安全性) 将 requirepass foobared 注释去掉,foobared为密码,也可修改为别的值(可选,建议设置)
requirepass my_password 3.2 设置iptables规则,允许外部访问6379端口 iptables -I INPUT 1 -p tcp -m state --state NEW -m tcp --dport 6379 -j ACCEPT 临时生效,重启后失效。若想永久生效,请参考另一篇文章:http://www.cnblogs.com/jinjiyese153/p/8600855.html 3.3 启动redis,并指定配置文件 ./redis-server ../redis.conf
3. Linux上,安装Python3.6,(检查pip) 配置path
4. Linux上,安装依赖包: 配置path
1:yum -y install zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gdbm-devel db4-devel libpcap-devel xz-devel 2:yum -y install zlib zlib-devel 3:yum install gcc
5. python中,安装依赖模块
pip install requests
pip install pymongo
6. python中, 安装 scrapy
pip install scrapy
如果报错:Could not find a version that satisfies the requirement Twisted>=13.1.0 (from Scrapy) (from versions: )
No matching distribution found for Twisted>=13.1.0 (from Scrapy)
原因是没有安装Twisted
解决方案:安装Twisted。
wget https://pypi.python.org/packages/source/T/Twisted/Twisted-15.2.1.tar.bz2 --no-check-certificate tar -xjvf Twisted-15.2.1.tar.bz2 cd Twisted-15.2.1 python setup.py install
7. 安装成功检查:
7.1 在python3中导入scrapy:表示安装成功。
[root@localhost Python3.6.3]# python3 Python 3.6.3 (default, Aug 21 2018, 20:41:20) [GCC 4.8.5 20150623 (Red Hat 4.8.5-28)] on linux Type "help", "copyright", "credits" or "license" for more information. >>> import scrapy >>> exit()
7.2 检查能不能掉出来。如果不能掉出来就需要建立一个软连接(快捷方式)到 `/usr/bin/` 文件夹中。因为所有的可以直接调用的命令快捷方式都在这里
$ sudo ln -s /home/yyq/python36/bin/scrapy /usr/bin/scrapy # 把`/home/yyq/python36/bin/`这个目下的 可执行文件 scrapy 复制一个link快捷方式到这个文件夹下:`/usr/bin/`, 快捷方式的名称 也叫做 “scrapy”
8. python中安装scrapy-redis模块
pip install scrapy-redis
9. 拷贝爬虫项目,到随便文件夹下。
10. 进入文件夹中,还是```scrapy crawl name```跑起来。