写点什么

从零开始搭建完整的电影全栈系统(五)——WEB 网站、Api 以及爬虫的部署

用户头像
刘强西
关注
发布于: 2020 年 09 月 22 日

这节我们记录下WEB网站、Api以及爬虫部署到服务器的过程。

服务器配置:CentOS7.8单核1G内存

运行环境为了简化安装宝塔面板。运行环境nginx、PHP7.4、Mysql5.6.48、Python3.7.8,参考下图:



WEB网站和API部署:



通过宝塔面板新建网站,新建数据库参考下图:

将项目代码,如下图,整个上传到服务器,并将数据库导入到服务器:

我们WEB有两部分组成,网站和API。将对应的域名分别绑定到对应的文件夹。比如我这里[

](http://www.shipinbofang.com)指向网站目录,api.shipinbofang.com指向Api目录。如下图:



这里有两点注意,取消宝塔的防跨站攻击和设置伪静态规则。如下图:



Yii2的nginx伪静态规则:



location / {
# Redirect everything that isn't a real file to index.php
try_files $uri $uri/ /index.php?$args;
}



至此,网站和Api我们已经搭建好了。网站的SSL和CDN请自行设置。我也搭建了在线版本,演示地址如下:



网站演示地址:https://www.shipinbofang.com/

Api演示地址:https://api.shipinbofang.com/



爬虫部署:

上传爬虫代码。

进入宝塔面板——软件商城 安装 Python项目管理器:

通过Python项目管理器新建项目,如下图:

启动方式选python、选择安装依赖、端口6800(保证在面板中开放6800端口),模块依赖的requirements.txt如下:



absl-py==0.9.0
astunparse==1.6.3
attrs==19.3.0
Automat==20.2.0
beautifulsoup4==4.9.1
cachetools==4.1.1
certifi==2020.6.20
cffi==1.14.2
chardet==3.0.4
constantly==15.1.0
crypto==1.4.1
cryptography==3.0
cssselect==1.1.0
fake-useragent==0.1.11
gast==0.3.3
google-auth==1.20.1
google-auth-oauthlib==0.4.1
google-pasta==0.2.0
grpcio==1.31.0
h5py==2.10.0
hyperlink==20.0.1
idna==2.10
incremental==17.5.0
itemadapter==0.1.0
itemloaders==1.0.2
jmespath==0.10.0
joblib==0.16.0
Keras==2.0.1
Keras-Preprocessing==1.1.2
lxml==4.5.2
Markdown==3.2.2
mouse==0.7.1
mysql-connector==2.2.9
mysqlclient==2.0.1
Naked==0.1.31
numpy==1.18.5
oauthlib==3.1.0
opt-einsum==3.3.0
parsel==1.6.0
peewee==3.13.3
Pillow==7.2.0
Protego==0.1.16
protobuf==3.13.0
pyasn1==0.4.8
pyasn1-modules==0.2.8
pycparser==2.20
PyDispatcher==2.0.5
PyHamcrest==2.0.2
PyMySQL==0.10.0
pyOpenSSL==19.1.0
pypinyin==0.39.0
pywin32==228
PyYAML==5.3.1
queuelib==1.5.0
redis==3.5.3
requests==2.24.0
requests-oauthlib==1.3.0
rsa==4.6
scikit-learn==0.23.2
scipy==1.4.1
Scrapy==2.3.0
selenium==3.141.0
service-identity==18.1.0
shellescape==3.8.1
six==1.15.0
soupsieve==2.0.1
tensorboard==2.3.0
tensorboard-plugin-wit==1.7.0
tensorflow==2.3.0
tensorflow-estimator==2.3.0
termcolor==1.1.0
Theano==1.0.5
threadpoolctl==2.1.0
Twisted @ https://download.lfd.uci.edu/pythonlibs/w3jqiv8s/Twisted-20.3.0-cp38-cp38-win_amd64.whl
urllib3==1.25.10
w3lib==1.22.0
Werkzeug==1.0.1
wrapt==1.12.1
zope.interface==5.1.0

将requirements.txt保存上传到爬虫目录。



进入爬虫目录修改RetryMySQLDatabase.py中的Mysql链接信息为你的WEB网站数据库的链接信息,这样爬取的数据直接入库在web网站展示。如下图:

添加计划任务,让爬虫定时自动运行:



source /www/wwwroot/MoviesSpider/moviespider_venv/bin/activate&&cd /www/wwwroot/MoviesSpider/ && scrapy crawl okzy -s JOBDIR=job_info/001

将以上自动执行的脚本修改成你自己的python虚拟环境目录,修改爬虫名称。



完成,网站、Api、爬虫全部搭建完成,一个涵盖很全的影视站出来了。(本人不上传任何片源,仅供编程交流学习之用)



后续我将打包项目代码,上传到群共享。

欢迎各位大佬入裙吹水(群号:879782113):



发布于: 2020 年 09 月 22 日阅读数: 49
用户头像

刘强西

关注

还未添加个人签名 2019.06.12 加入

还未添加个人简介

评论

发布
暂无评论
从零开始搭建完整的电影全栈系统(五)——WEB网站、Api以及爬虫的部署