V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
推荐学习书目
Learn Python the Hard Way
Python Sites
PyPI - Python Package Index
http://diveintopython.org/toc/index.html
Pocoo
值得关注的项目
PyPy
Celery
Jinja2
Read the Docs
gevent
pyenv
virtualenv
Stackless Python
Beautiful Soup
结巴中文分词
Green Unicorn
Sentry
Shovel
Pyflakes
pytest
Python 编程
pep8 Checker
Styles
PEP 8
Google Python Style Guide
Code Style from The Hitchhiker's Guide
xiaopenggggggg
V2EX  ›  Python

scrapy 疑问🤔️,各位大佬都是怎么把 scrapy 部署到服务器?

  •  
  •   xiaopenggggggg · 2018-07-12 22:59:47 +08:00 · 4104 次点击
    这是一个创建于 2086 天前的主题,其中的信息可能已经有所发展或是发生改变。

    小弟敲了一个小爬虫,网上搜到有 scrapyd 方式部署,于是本地 pip install scrapyd。在本地测试完全爬虫跑得妥妥的,于是想仍到 docker 容器里面去。写了一个 DockerFile,内容大致如下:

    FROM python:3.5.5
    ENV PATH /usr/local/bin:$PATH
    ADD . /scrapy_weather
    WORKDIR /scrapy_weather
    COPY ./scrapyd.conf /etc/scrapyd/
    EXPOSE 6800
    CMD scrapyd
    

    构建了一个 docker 镜像,然后在自己的 mac 本的 docker 里面跑得飕飕的,没有一点问题,于是把镜像推送出去,结果在 centos 的服务器上面,同样的镜像,会报以下错误:

    Another twistd server is running, PID 5
    
    This could either be a previously started instance of your application or a
    different application entirely. To start a new one, either run it in some other
    directory, or use the --pidfile and --logfile parameters to avoid clashes.	
    

    小弟实在是没招了,想与各位 py 大佬们交流一波,scrapy 的优雅部署方式

    9 条回复    2018-11-15 11:57:22 +08:00
    lanpong
        1
    lanpong  
       2018-07-12 23:45:29 +08:00 via iPhone
    哪有什么优雅的方式。
    1. 推一份源码,直接跑
    2. 推一份源码,用虚拟环境
    3. docker

    推源码的方式有很多种,scp、git、upload
    lightening
        2
    lightening  
       2018-07-12 23:48:56 +08:00
    怎么会这样,不应该发生啊
    xiaopenggggggg
        3
    xiaopenggggggg  
    OP
       2018-07-13 09:45:13 +08:00
    @lightening 确实很奇怪,在本地的 mac 本的 docker 中跑这个镜像不会报错,但是仍到服务器会报这个错误。然后在本机进入 docker 容器里面,敲 scrapyd 命令也会报同样的错误。实在不知道为什么服务器抽风了😫
    Molita
        4
    Molita  
       2018-07-13 11:02:10 +08:00
    按提示的那个 加上 pidfile logfile 试一试呗
    lightening
        5
    lightening  
       2018-07-13 15:17:49 +08:00 via iPhone
    去服务器重新 build 试试。感觉像是 pid 文件没删掉?
    xiaopenggggggg
        6
    xiaopenggggggg  
    OP
       2018-07-13 19:40:37 +08:00
    @lightening 解决了该问题,是内存不足,直接把容器给 kill 掉了。
    my8100
        7
    my8100  
       2018-11-15 00:00:29 +08:00
    如何简单高效地部署和监控分布式爬虫项目 v2ex.com/t/507933
    111qqz
        8
    111qqz  
       2018-11-15 11:45:09 +08:00
    @xiaopenggggggg 遇到了同样的问题,不过我在 docker 里面运行就不会报错,在外面用 entrypoint 或者 CMD 就都会报错,楼主最后是怎么解决的呢? 内存不足是指容器里面还是 host 中?
    111qqz
        9
    111qqz  
       2018-11-15 11:57:22 +08:00
    @lightening 感谢,解决了。果然是因为 twistd.pid 文件没有删除。
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   4084 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 35ms · UTC 05:21 · PVG 13:21 · LAX 22:21 · JFK 01:21
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.