FishFishJump 是一个基于 python 的简单而基本的搜索引擎解决方案, 该项目提供了多个可供参考且支持 Docker 自动化部署的 Example, 以帮助您实现定制化的搜索引擎网站
fish_core : 包含一些其他模块所依赖的应用程序组件和工具
fish_crawlers : 基于 scrapy-redis 实现的分布式爬虫, 它包含两个 Scrapy 项目: master_crawler 将从 http://dmoztools.net / 抓取 url 并将其放入 Redis 队列, slave_crawler 则从 Redis 队列拿到 url, 然后提取信息并存储到 MongoDB 中
fish_dashboard : 用于监控和管理 Scrapy 与 Elasticsearch 的 web 应用程序
fish_searcher : 支持搜索并返回查询结果的 web 应用程序, 它依赖 Elasticsearch 与 fish_crawler 集群抓取到的数据
Usage
如果您想要独立部署这些 Example, 那么您只需要在项目的根目录下输入以下命令:
docker-compose up -d --build
有关 Docker 和 docker-compose 的更多资料请参考: https://docs.docker.com/compose/
注意: 对于 fish_crawlers 而言, 您还需要进入到 Docker 容器之中并部署 Scrapy 项目, FishFishJump 的部署方式使用 Scrapyd, 相关的配置文件位于 scrapy.cfg 中, 例如:
- # Automatically created by: scrapy startproject
- #
- # For more information about the [deploy] section see:
- # https://scrapyd.readthedocs.org/en/latest/deploy.html
- [settings]
- default = master_crawler.settings
- [deploy:master_crawler01]
- url = http://127.0.0.1:6800/
- project = master_crawler
通过以下命令进行部署:
- # 进入 Docker 容器之中
- docker exec -it [container id] /bin/bash
- # 部署的命令为'scrapyd-deploy [deploy name]', 关于 deploy name 参考文件 scrapy.cfg
- cd master_crawler
- scrapyd-deploy master_crawler01
- cd ..
- cd slave_crawler
- scrapyd-deploy slave_crawler01
- # 启动爬虫, project 与 spider 的名字同样参考 scrapy.cfg
- # 爬虫 dmoz_crawler 需要在 Redis 中先存放一个 key 为 dmoz_crawler:start_urls 值为 http://dmoztools.net / 的数据以开始启动
- # Example: redis LPUSH dmoz_crawler:start_urls http://dmoztools.net/
- curl http://localhost:6800/schedule.json -d project=master_crawler -d spider=dmoz_crawler
- curl http://localhost:6800/schedule.json -d project=slave_crawler -d spider=simple_fish_crawler
- # 退出
- exit
更多资料请参考: https://github.com/scrapy/scrapyd-client
顺便说一下, fish_crawlers 通过 Docker 自动在本地部署了 Redis 与 MongoDB, 如果您不想这样做, 可以在 docker-compose.yml 文件中删除以下内容, 然后在 Scrapy 项目下的 setting.py 配置文件中设置您的 Redis 与 MongoDB 的地址
- redis:
- image: redis
- container_name: FishFishJump_Redis
- ports:
- - "6379:6379"
- mongo:
- image: mongo
- container_name: FishFishJump_Mongo
- ports:
- - "27017:27017"
- links:
- - redis
- - mongo
如果您不想使用 Docker, 也可以使用以下方式手动部署
- # 需要先安装依赖
- pip install FishFishJump
- # 以下命令需要在 Scrapy 项目目录下执行
- scrapy crawl dmoz_crawler
- scrapy crawl simple_fish_crawler
- # 以下命令需要在 fish_dashboard 或者 fish_searcher 的根目录下执行
- python app.py
对于 fish_crawlers, 同样可以使用 Scrapyd 的部署方式进行部署 (或者通过 fish_dashboard 远程管理)
Dashboard
fish_dashboard 是用于监控 Scrapy 与 Elasticsearch 的健康状态和信息的监控平台, 它提供了一些功能可以帮助您更好地管理 Scrapy 与 Elasticsearch, 例如:
通过 ajax 轮询实现实时显示数据, 如果您不想使用这个功能, 可以将配置 POLLING_INTERVAL_TIME 设置为 0
故障报警机制, 当 Scrapy 或者 Elasticsearch 长时间没有响应时 (根据配置属性 MAX_FAILURE_TIMES),fish_dashboard 将向您发送警报邮件
传输数据机制, 提供了两种方法将数据从 MongoDB 传输到 Elasticsearch 以生成索引库进行后续的搜索, 第一种方法是手动全量传输, 数据在离线状态下一次性传输到 Elasticsearch, 第二种方法是基于线程轮询实现的自动传输
fish_dashboard 基于 Flask 实现, 其配置文件为 fish_dashboard 根目录下的 settings.py, 您也可以使用命令行接面, 具体如下:
- Usage: fish_dashboard [options] args
- Command line param for FishFishJump webapp.
- Options:
- -h, --help show this help message and exit
- --host=HOST host address, default: 0.0.0.0
- --port=PORT port, default: 5000
- --username=ADMIN_USERNAME
- administrator username for login, default: admin
- --password=ADMIN_PASSWORD
- administrator password for login, default: 123456
- -d, --debug enable debug pattern of the flask, default: True
- -t, --test enable test pattern of the flask, default: False
- --cached-expire=CACHE_EXPIRE
- expire of the flask cache, default: 60
- --scrapyd-url=SCRAPYD_URL
- url of the scrapyd for connect scrapyd service,
- default: http://localhost:6800/
- -v, --verbose verbose that log info, default: False
- --log-file-dir=LOG_FILE_DIR
- the dir path of the where store log file, default:
- E:\FishFishJump\log\
- --log-file-name=LOG_FILE_BASIS_NAME
- the name of the what log file, default:
- fish_fish_jump_webapp.log
- --elasticsearch-hosts=ELASTICSEARCH_HOSTS
- the string represent a host address for Elasticsearch,
- format: hostname:port and able to write multiple
- address by comma separated default: localhost:9200
- --polling-interval=POLLING_INTERVAL_TIME
- the time of the interval time for real-time dynamic
- update, units second default: 3
- --failure-sleep-time=FAILURE_SLEEP_TIME
- if connected fail will turn to this time window and
- return backup data in this time window, units second
- default: 30
- --max-failure-times=MAX_FAILURE_TIMES
- the number of the max failure times if occurred fail
- reaching the upper limit will sent message into the
- front-end, default: 5
- --max-failure-message-key=MAX_FAILURE_MESSAGE_KEY
- the string of the key for message sent after reaching
- the upper limit, default: timeout_error
效果图:
Searcher
fish_searcher 是一个支持搜索和返回搜索结果的 web 应用程序, 它基于 Elasticsearch 实现并提供了一些基本的搜索引擎所需要的功能
- Usage: fish_searcher [options] args
- Command line param for FishFishJump webapp.
- Options:
- -h, --help show this help message and exit
- --host=HOST host address, default: 0.0.0.0
- --port=PORT port, default: 5009
- -d, --debug enable debug pattern of the flask, default: True
- -t, --test enable test pattern of the flask, default: False
- -v, --verbose verbose that log info, default: False
- --log-file-dir=LOG_FILE_DIR
- the dir path of the where store log file, default:
- E:\FishFishJump\log\
- --log-file-name=LOG_FILE_BASIS_NAME
- the name of the what log file, default:
- fish_fish_jump_searcher.log
- --elasticsearch-hosts=ELASTICSEARCH_HOSTS
- the string represent a host address for Elasticsearch,
- format: hostname:port and able to write multiple
- address by comma separated default: localhost:9200
- --elasticsearch-index=ELASTICSEARCH_INDEX
- the string represents a list of the index for query
- data from Elasticsearch, if you want to assign
- multiple please separate with a comma, for example,
- index_a,index_b, default: ['pages']
- --elasticsearch-doc-type=ELASTICSEARCH_DOC_TYPE
- the string represents a list of the doc_type for query
- data from Elasticsearch, if you want to assign
- multiple please separate with a comma, for example,
- doc_type_a, doc_type_b, default: ['page_item']
- --redis-cache enable Redis for external cache, default: False
- --redis-host=REDIS_HOST
- the string represents a host of the Redis and the
- configuration invalid when not set config --redis-
- cache, default: 127.0.0.1
- --redis-port=REDIS_PORT
- the string represents a port of the Redis and the
- configuration invalid when not set config --redis-
- cache , default: 6379
来源: http://www.tuicool.com/articles/E3aiqqe