crawlab是一个开源且简单好用的爬虫管理平台。在GitHub已收到7.6k的star,官网:https://github.com/crawlab-team/crawlab
。本次尝试部署:使用Docker容器部署方式,简单方便;参数从简,适合小白,先开起来再研究QAQ~
一、需要准备的环境
二、部署步骤
三、写在最后
由于使用Centos7系统进行安装,所以系统的yum就能直接安装Docker
yum install -y yum-utils device-mapper-persistent-data lvm2 #安装依赖
yum install docker
systemctl start docker
此处先省略,如果有需要以后会专门写一篇文章介绍。
pip install docker-compose
crawlab镜像有国内源,下载会快一点,需要编辑 /etc/docker/daemon.json
文件
vim /etc/docker/daemon.json
#加入以下内容
{
"registry-mirrors": ["https://registry.docker-cn.com"]
}
需要重启docker服务:
systemctl restart docker
然后将镜像pull下来:
docker pull tikazyq/crawlab:latest
等进度条走完即可。
docker-compose.yml
文件记录了容器的启动方式,可灵活编辑改文件以达到想要的配置,以下介绍一个最简单的示例,能将平台启动起来。
version: '3.3'
services:
master:
image: tikazyq/crawlab:latest #使用的镜像
container_name: crawlab-master #启动的容器名称
environment:
CRAWLAB_SERVER_MASTER: "Y" #是否作为主节点Y/N
CRAWLAB_MONGO_HOST: "mongo" #mongodb数据库
CRAWLAB_REDIS_ADDRESS: "redis" #redis数据库
ports:
- "8080:8080" #将容器前端8080端口映射至宿主机
depends_on:
- mongo #依赖的容器
- redis #依赖的容器
worker:
image: tikazyq/crawlab:latest
container_name: crawlab-worker
environment:
CRAWLAB_SERVER_MASTER: "N" #不作为主节点,即为工作节点,注意不能有一个以上的主节点
CRAWLAB_MONGO_HOST: "mongo"
CRAWLAB_REDIS_ADDRESS: "redis"
depends_on:
- mongo
- redis
mongo: #mongodb数据库
image: mongo:latest
restart: always
redis: #redis数据库
image: redis:latest
restart: always
编辑好后保存文件。
执行以下命令启动
docker-compose up
启动后使用 宿主机IP:8080 访问平台,默认账号密码:admin/admin
docker-compose up
命令的相同目录中即可;docker-compose ps
命令检查配置文件;mongodb
以及redis
的镜像并启动,之后都不用;docker-compose.yml
文件的配置定义:version: '3.3'
services:
master:
image: tikazyq/crawlab:latest
container_name: master
environment:
# CRAWLAB_API_ADDRESS: "https://<your_api_ip>:<your_api_port>" # backend API address 后端 API 地址. 适用于 https 或者源码部署
CRAWLAB_SERVER_MASTER: "Y" # whether to be master node 是否为主节点,主节点为 Y,工作节点为 N
CRAWLAB_MONGO_HOST: "mongo" # MongoDB host address MongoDB 的地址,在 docker compose 网络中,直接引用服务名称
# CRAWLAB_MONGO_PORT: "27017" # MongoDB port MongoDB 的端口
# CRAWLAB_MONGO_DB: "crawlab_test" # MongoDB database MongoDB 的数据库
# CRAWLAB_MONGO_USERNAME: "username" # MongoDB username MongoDB 的用户名
# CRAWLAB_MONGO_PASSWORD: "password" # MongoDB password MongoDB 的密码
# CRAWLAB_MONGO_AUTHSOURCE: "admin" # MongoDB auth source MongoDB 的验证源
CRAWLAB_REDIS_ADDRESS: "redis" # Redis host address Redis 的地址,在 docker compose 网络中,直接引用服务名称
# CRAWLAB_REDIS_PORT: "6379" # Redis port Redis 的端口
# CRAWLAB_REDIS_DATABASE: "1" # Redis database Redis 的数据库
# CRAWLAB_REDIS_PASSWORD: "password" # Redis password Redis 的密码
# CRAWLAB_LOG_LEVEL: "info" # log level 日志级别. 默认为 info
# CRAWLAB_LOG_ISDELETEPERIODICALLY: "N" # whether to periodically delete log files 是否周期性删除日志文件. 默认不删除
# CRAWLAB_LOG_DELETEFREQUENCY: "@hourly" # frequency of deleting log files 删除日志文件的频率. 默认为每小时
# CRAWLAB_SERVER_REGISTER_TYPE: "mac" # node register type 节点注册方式. 默认为 mac 地址,也可设置为 ip(防止 mac 地址冲突)
# CRAWLAB_SERVER_REGISTER_IP: "127.0.0.1" # node register ip 节点注册IP. 节点唯一识别号,只有当 CRAWLAB_SERVER_REGISTER_TYPE 为 "ip" 时才生效
# CRAWLAB_TASK_WORKERS: 8 # number of task executors 任务执行器个数(并行执行任务数)
# CRAWLAB_RPC_WORKERS: 16 # number of RPC workers RPC 工作协程个数
# CRAWLAB_SERVER_LANG_NODE: "Y" # whether to pre-install Node.js 预安装 Node.js 语言环境
# CRAWLAB_SERVER_LANG_JAVA: "Y" # whether to pre-install Java 预安装 Java 语言环境
# CRAWLAB_SETTING_ALLOWREGISTER: "N" # whether to allow user registration 是否允许用户注册
# CRAWLAB_SETTING_ENABLETUTORIAL: "N" # whether to enable tutorial 是否启用教程
# CRAWLAB_NOTIFICATION_MAIL_SERVER: smtp.exmaple.com # STMP server address STMP 服务器地址
# CRAWLAB_NOTIFICATION_MAIL_PORT: 465 # STMP server port STMP 服务器端口
# CRAWLAB_NOTIFICATION_MAIL_SENDEREMAIL: admin@exmaple.com # sender email 发送者邮箱
# CRAWLAB_NOTIFICATION_MAIL_SENDERIDENTITY: admin@exmaple.com # sender ID 发送者 ID
# CRAWLAB_NOTIFICATION_MAIL_SMTP_USER: username # SMTP username SMTP 用户名
# CRAWLAB_NOTIFICATION_MAIL_SMTP_PASSWORD: password # SMTP password SMTP 密码
ports:
- "8080:8080" # frontend port mapping 前端端口映射
depends_on:
- mongo
- redis
# volumes:
# - "/var/crawlab/log:/var/logs/crawlab" # log persistent 日志持久化
worker:
image: tikazyq/crawlab:latest
container_name: worker
environment:
CRAWLAB_SERVER_MASTER: "N"
CRAWLAB_MONGO_HOST: "mongo"
CRAWLAB_REDIS_ADDRESS: "redis"
depends_on:
- mongo
- redis
# environment:
# MONGO_INITDB_ROOT_USERNAME: username
# MONGO_INITDB_ROOT_PASSWORD: password
# volumes:
# - "/var/crawlab/log:/var/logs/crawlab" # log persistent 日志持久化
mongo:
image: mongo:latest
restart: always
# volumes:
# - "/opt/crawlab/mongo/data/db:/data/db" # make data persistent 持久化
# ports:
# - "27017:27017" # expose port to host machine 暴露接口到宿主机
redis:
image: redis:latest
restart: always
# command: redis-server --requirepass "password" # set redis password 设置 Redis 密码
# volumes:
# - "/opt/crawlab/redis/data:/data" # make data persistent 持久化
# ports:
# - "6379:6379" # expose port to host machine 暴露接口到宿主机
# splash: # use Splash to run spiders on dynamic pages
# image: scrapinghub/splash
# container_name: splash
# ports:
# - "8050:8050"
1、本文记录于第一次部署并启动crawlab
2、crawlab有多种部署方式,使用docker部署是最简单的方式
3、新手使用默认配置,高手选择自定义配置
4、学无止境,同一路上有人前赴后继,也不失为一种美趣。