前段时间我们弄了btlike项目,但是后来停止更新了。 现在我们重新立了一个btlet的项目,大家有兴趣的话可以来看看。
演示地址:http://www.btlet.com
github地址:https://github.com/qsbaq/btlet.com
爬虫是Go写的,PHP部分基于Onethink PHP。
如果大家觉得项目好的话,记得赞助我们哦~
Table of Contents
- 1 VPS主机推荐
- 2 环境需求
- 3 推荐PHP空间
- 3.1 安装步骤:
- 3.1.1 1、新建数据库 btlet ,导入 init.sql
- 3.1.2 2、运行爬虫(爬虫可以分布在多台机器上同时运行,使用参数连接到指定数据库即可) , 参数详情:
- 3.1.3 3、上传文件到php空间中(空间必须支持 php-mysqli 扩展),并确保文件权限:
- 3.1.4 4、配置php中的数据库文件:
- 3.1.5 5、Rewrite 配置
- 3.1.6 6、前端php后台地址(请确保上面的rewrite已正常工作,否则无法打开后台)
- 3.1.7 7、Linux中每12小时,重启爬虫spider。我们把爬虫放在/root目录中
- 3.1.8 8、设置每天爬取统计,同爬虫设置一样
- 3.1.9 9、启用sphinx/coreseek搜索(可选项)
- 3.2 原生的sphinx教程,使用coreseek的不需要安装
- 3.1 安装步骤:
- 4 配置PHP文件
VPS主机推荐
Vultr 充5美元可以用5个月VPS 充值最高送100美元
环境需求
64位的系统版本( x64)
php > ?5.3.0 mysql
推荐PHP空间
老季淘宝店:https://item.taobao.com/item.htm?id=41356970136
安装步骤:
1、新建数据库 btlet ,导入 init.sql
2、运行爬虫(爬虫可以分布在多台机器上同时运行,使用参数连接到指定数据库即可) , 参数详情:
-u=”btlet” 数据库用户名
-p=”laoji.org” 数据库密码
-h=”v.laoji.org” 数据库地址,默认是localhost
-d=”btlet” 数据库名
-P=”3306″ 数据库端口,默认3306
Windows ( spider.exe-forwin?重命名为:spider.exe,可以先运行文件夹中的 cmd.bat ,然后运行一下命令):
spider.exe -u="数据库用户名" -p="数据库密码" -d="数据库名"
Linux ( spider-forlinux?重命名为:spider):
chmod +x spider //第一次运行时需要添加可执行权限 ./spider -u="数据库用户名" -p="数据库密码" -d="数据库名"
爬虫可以分散在N台机器上运行,只需指定数据库IP
-u="数据库用户名" -p="数据库密码" -d="数据库名" -h="数据库域名地址或IP"
注:爬虫必须在公网IP上运行,内网爬不到数据 Linux下同理,可以将爬虫挂在screen命令中运行。
Screen运行实例:
screen -S laoji ./spider -u="数据库用户名" -p="数据库密码" -d="数据库名"
等到开始跳出文字,刚开始的时候有些慢。直到出现下面内容: 2017/02/21 07:11:54 ed2bea744442aafd21102d6e2f5d52eb7d2973d4 2017/02/21 07:12:07 c26ede340f0f620dab01835f48177bbbfbf27dc0
切出Screen返回刚才的终端:
CTRL+A,d
具体Screen使用方法请看:Linux Screen 简单用法 图文教程
3、上传文件到php空间中(空间必须支持 php-mysqli 扩展),并确保文件权限:
Runtime (Linux中确定权限为777:chmod 777 Runtime -R)
4、配置php中的数据库文件:
将/Application/Common/Conf/config.sample.php重命名为: Application/Common/Conf/config.php,修改 第40行开始:
/* 数据库配置 */ 'DB_TYPE' => 'mysqli', // 数据库类型 'DB_HOST' => 'localhost', // 服务器地址 'DB_NAME' => 'btlet', // 数据库名 'DB_USER' => 'btlet', // 用户名 'DB_PWD' => 'laoji.org', // 密码 'DB_PORT' => '3306', // 端口 'DB_CHARSET' => 'utf8mb4', 'DB_PREFIX' => 'laoji_', // 数据库表前缀
将/Application/User/Conf/config.sample.php重命名为:/Application/User/Conf/config.php。修改 第18行:
define('UC_DB_DSN', 'mysqli://数据库用户名:数据库密码@数据库地址:3306/数据库名'); // 数据库连接,使用Model方式调用API必须配置此项
5、Rewrite 配置
nginx下配置Rewrite规则:
if (!-e $request_filename) { rewrite ^/(.*)$ /index.php/$1; }
Apache 环境下只需支持.htaccess即可。
<IfModule mod_rewrite.c> Options +FollowSymlinks RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^(.*)$ index.php/$1 [QSA,PT,L] </IfModule>
6、前端php后台地址(请确保上面的rewrite已正常工作,否则无法打开后台)
/admin 默认
用户名:admin
默认密码:laoji.org
7、Linux中每12小时,重启爬虫spider。我们把爬虫放在/root目录中
crontab -e
添加如下命令:
1 */6 * * * pkill spider ; cd /root && ./spider -u="btlet" -p="密码" -h="127.0.0.1" -d="btlet" >> /dev/null 2>&1 &
8、设置每天爬取统计,同爬虫设置一样
chmod +x statistics //首次运行时需要 ./statistics -u="btlet" -p="jjjjjj" -h="127.0.0.1" -date="2017-02-16"
Linux 下 可以加入到crontab中,
0 */6 * * * cd /root && ./statistics -u="btlet" -p="jjjjjj" >> /dev/null
-date=”2017-02-16″ // 指定统计日期,如不带此参数默认统计昨天的数据
windows中可以加入到计划任务中。
9、启用sphinx/coreseek搜索(可选项)
在crontab中添加coreseek定时重建索引任务:
crontab -e
0 */6 * * * /usr/local/coreseek/bin/indexer -c /usr/local/coreseek/etc/sphinx.conf --rotate --all >> /dev/null
原生的sphinx教程,使用coreseek的不需要安装
CentOS6.4 64位下安装sphinx及sphinx for php扩展
必须确定php环境已支持sphinx,在phpinfo中看到如下扩展:

配置sphinx.conf
vi /usr/local/sphinx/etc/sphinx.conf
# # Minimal Sphinx configuration sample (clean, simple, functional) # source btlet { type = mysql sql_host = localhost sql_user = btlet sql_pass = laoji.org #数据库密码 sql_db = btlet sql_port = 3306 # optional, default is 3306 sql_query = SELECT id,name,infohash,files, UNIX_TIMESTAMP(update_time) AS update_time FROM laoji_infohash # sql_attr_uint = id sql_attr_string = name sql_attr_string = infohash sql_field_string = files sql_attr_timestamp = update_time } index infohash { source = btlet path = /usr/local/sphinx/var/data/hash } indexer { mem_limit = 128M } searchd { listen = 9312 listen = 9306:mysql41 log = /usr/local/sphinx/var/log/searchd.log query_log = /usr/local/sphinx/var/log/query.log read_timeout = 5 max_children = 30 pid_file = /usr/local/sphinx/var/log/searchd.pid seamless_rotate = 1 preopen_indexes = 1 unlink_old = 1 workers = threads # for RT to work binlog_path = /usr/local/sphinx/var/data }
配置PHP文件
在php的配置文件中启用Application/Common/Conf/config.php
'USE_SPHINX' => true,
常见问题
- bash: ./spider: cannot execute binary file
请检查系统版本是64位的( x64)版本。我们git包里只编译了X64的,X86的有环境的小伙伴可以自行编译。 大家有什么问题的话可以在这里留言或者加QQ群提问!
评论已关闭