手撕包菜搭建

概述

最近做了两件事,一件事就是买了块1t硬盘,第二件事就是买了个百度云会员,无奈找不到资源下载,那就没办法了,搭建一个磁力链接搜索引擎来爬去链接,然后去找资源。

说道磁力链接搜索引擎,最好的当然是手撕包菜了。

搭建

直接使用脚本搭建安装,记住服务器内存最好1g以上的

wget --no-check-certificate https://raw.githubusercontent.com/banwagong-news/scripts/master/ssbc-setup.sh && bash ssbc-setup.sh

之后会让你输入下面的信息

请输入网站域名,多个域名用空格隔开:192.168.1.149
确定浏览器能访问网站  http://192.168.1.149  吗?[y/n]y
Username (leave blank to use 'root'): root
Email address: bboysoulcn@gmail.com
Password: 
Password (again): 
Superuser created successfully.
复制代码

等待一段时间就会有数据了,但是注意服务器一定要是国外的服务器,为什么要使用国外的服务器呢大家应该都懂的。

数据库相关

脚本安装的mariadb默认是不允许其他机器登录的,所以如果你要使用本地的数据库连接工具连接这个mariadb的话就要开启mariadb的root远程连接了,还有就是默认是没有密码的,所以最好你设置一个root密码,首先设置root密码,输入

mysql_secure_installation

之后按照提示操作就好

[root@bboysoul-centos ssbc]# mysql_secure_installation 

NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB
      SERVERS IN PRODUCTION USE!  PLEASE READ EACH STEP CAREFULLY!

In order to log into MariaDB to secure it, we'll need the current
password for the root user.  If you've just installed MariaDB, and
you haven't set the root password yet, the password will be blank,
so you should just press enter here.

Enter current password for root (enter for none): 
OK, successfully used password, moving on...

Setting the root password ensures that nobody can log into the MariaDB
root user without the proper authorisation.

Set root password? [Y/n] y
New password: 
Re-enter new password: 
Password updated successfully!
Reloading privilege tables..
 ... Success!


By default, a MariaDB installation has an anonymous user, allowing anyone
to log into MariaDB without having to have a user account created for
them.  This is intended only for testing, and to make the installation
go a bit smoother.  You should remove them before moving into a
production environment.

Remove anonymous users? [Y/n] y
 ... Success!

Normally, root should only be allowed to connect from 'localhost'.  This
ensures that someone cannot guess at the root password from the network.

Disallow root login remotely? [Y/n] n
 ... skipping.

By default, MariaDB comes with a database named 'test' that anyone can
access.  This is also intended only for testing, and should be removed
before moving into a production environment.

Remove test database and access to it? [Y/n] y
 - Dropping test database...
 ... Success!
 - Removing privileges on test database...
 ... Success!

Reloading the privilege tables will ensure that all changes made so far
will take effect immediately.

Reload privilege tables now? [Y/n] y
 ... Success!

Cleaning up...

All done!  If you've completed all of the above steps, your MariaDB
installation should now be secure.

Thanks for using MariaDB!
复制代码

之后就是开启mariadb的远程访问 首先登陆mariadb

mysql -u root -p

之后输入下面命令

MariaDB [mysql]> use mysql
Database changed
MariaDB [mysql]> update user set Host='%' where Host='localhost';
Query OK, 1 row affected (0.00 sec)
Rows matched: 1  Changed: 1  Warnings: 0

MariaDB [mysql]> flush privileges;
Query OK, 0 rows affected (0.00 sec)

MariaDB [mysql]> 
复制代码

接着就可以远程登陆数据库了 之后要修改手撕包菜程序里面的连接密码 首先关闭相关的进程

ps -ef |grep python

一般就是下面几个进程

root       958     1  0 20:51 ?        00:00:00 /usr/bin/python -Es /usr/sbin/tuned -l -P
root      3604     1  0 21:13 pts/0    00:00:00 /usr/bin/python2 /usr/bin/gunicorn ssbc.wsgi:application -b 127.0.0.1:8000 --reload
root      3616  3604  1 21:13 pts/0    00:00:09 /usr/bin/python2 /usr/bin/gunicorn ssbc.wsgi:application -b 127.0.0.1:8000 --reload
root      3693     1 12 21:15 ?        00:01:30 python simdht_worker.py
root      3694     1  0 21:15 ?        00:00:00 python index_worker.py
复制代码

kill之后再kill下面几个进程

ps -ef |grep search

root      3467     1  0 21:03 ?        00:00:00 searchd --config ./sphinx.conf
root      3468  3467  0 21:03 ?        00:00:02 searchd --config ./sphinx.conf
复制代码

接着修改配置文件

vim /root/ssbc/sphinx.conf

增加数据库的密码

        sql_host                = 127.0.0.1
        sql_user                = root
        sql_pass                = 
        sql_db                  = ssbc
        sql_port                = 3306  # optional, default is 3306
复制代码

vi /root/ssbc/workers/index_worker.py

SRC_HOST = '127.0.0.1'
SRC_USER = 'root'
SRC_PASS = ''
DST_HOST = '127.0.0.1'
DST_USER = 'root'
DST_PASS = ''
复制代码

上面两个密码都要修改

vi /root/ssbc/workers/simdht_worker.py

DB_HOST = '127.0.0.1'
DB_USER = 'root'
DB_PORT = 3306
DB_PASS = ''
DB_NAME = 'ssbc'
BLACK_FILE = 'black_list.txt'
复制代码

vim /root/ssbc/ssbc/settings.py

修改下面,root后面加上数据库密码

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.mysql',
        'NAME': 'ssbc',
        'HOST': '127.0.0.1',
        'PORT': 3306,
        'USER': 'root',
        'PASSWORD': 'woyaoxuehuilinux',
        'OPTIONS': {
           "init_command": "SET storage_engine=MYISAM",
        }
    }
}
复制代码

关于数据迁移

这个其实好办先在新的机器上执行脚本,执行完成之后删除数据库建立新的ssbc数据库记住编码要utf-8的,之后把老的数据库导入新的就可以了

其他的使用技巧

我就直接复制粘贴了

1.必须centos7吗?
非常建议使用centos7,centos6可能会有意想不到的错误
2.如何设置首页关键字?
登录管理员后台,点击Rec keywordss,右上角新增
3.怎么查看入库的文件?
登录管理员后台,点击 Hashs 
4.怎么查看每天入库了多少文件,以便清楚入库效率?
登录管理员后台,点击 Status reports 
5.如何确认web服务器、采集、入库正在运行?
运行 ps -ef|grep python|grep -v grep
结果里面有
gunicorn ssbc.wsgi:application -b 127.0.0.1:8000 --reload 
python simdht_worker.py  
python index_worker.py
即表示正在运行。
——————————————————————————————————————
去除搜索页 右下角广告
[root@localhost ssbc-master]# cd web/static/js
[root@localhost js]# vi ssbc.js   找到如下3行,在前面添加//进行注释,保存
//        document.write('<script src="http://v.6dvip.com/ge/?s=47688"><\/script>');
//            document.writeln("<script language=\"JavaScript\" type=\"text/javascript\" src=\"http://js.6dad.com/js/xiaoxia.js\"></script>");
//           document.writeln("<script language=\"JavaScript\" type=\"text/javascript\" src=\"http://js.ta80.com/js/12115.js\"></script>");
——————————————————————————————————————
如何修改扩展名归类?
workers/metautils.py文件中有如下代码:
def get_category(ext):
    ext = ext + '.'
    cats = {
        u'video': '.avi.mp4.rmvb.m2ts.wmv.mkv.flv.qmv.rm.mov.vob.asf.3gp.mpg.mpeg.m4v.f4v.',
        u'image': '.jpg.bmp.jpeg.png.gif.tiff.',
        u'document': '.pdf.isz.chm.txt.epub.bc!.doc.ppt.',
        u'music': '.mp3.ape.wav.dts.mdf.flac.',
        u'package': '.zip.rar.7z.tar.gz.iso.dmg.pkg.',
        u'software': '.exe.app.msi.apk.'
    }

意思是:扩展名为.exe、.app、.msi、,.apk的文件都属于software类型。
如果你把u'software': '.exe.app.msi.apk.' 改为 u'software': 'app.msi.apk.',那么exe将会被归为other类型。
所以在这里修改归类设置。
——————————————————————————————————————
如何禁止某些格式/分类的文件入库?
workers/metadata.py文件中有如下代码:
info['extension'] = metautils.get_extension(bigfname).lower()
info['category'] = metautils.get_category(info['extension'])
所以如果你要排除扩展名为.exe的文件,或者类型为software,可以在上面代码后面加上
##########这是增加的过滤-开始############
#按扩张名过滤,禁止扩展名为.exe的入库
if info['extension'] == 'exe':
    return # 直接返回,跳过下面的入库
#按文件类型过滤,禁止类型为software的入库
if info['category'] == 'software':
    return
#禁止类型为other的入库
if info['category'] == 'other':
    return
##########这是增加的过滤-结束############
——————————————————————————————————————
如何重建索引?
第一步:
删除/data目录
第二步:
进入数据库,把search_hash表中所有记录的tagged字段置为0。
UPDATE search_hash SET tagged=0
然后启动sphinx、index_worker.py。
——————————————————————————————————————
MySQL server has gone away提示怎么办?
ssbc 运行一段时间后,大概半个小时,就莫名奇妙停止不爬了。 错误提示如下:
MySQL server has gone away
通过错误提示可以看出,其实是ssbc与mysql(maridb)断开连接了,导致程序异常,当然就插入不了数据了。
有3种解决办法:
方法1是写个脚本,定时重启爬虫。
方法2是修改下代码,当mysql断开连接时,再次重连mysql就可以拉。
方法3是修改Mysql配置,将闲置时间wait_timeout设置长一点。
——————————————————————————————————————
哪里设置爬虫线程?让爬虫爬快/慢点?
在workers/simdht_worker.py里面把MAX_QUEUE_LT、MAX_QUEUE_PT、max_node_qsize设大/小一点。
如何关闭调试模式?设置404页面?
请参考 http://www.githubs.cn/post/19
——————————————————————————————————————
如何在搜索结果页面添加迅雷链接?
在web/views.py文件加入以下代码生成迅雷链接:
import base64
xunleiurl = 'AAmagnet:?xt=urn:btih:' + d['info']['info_hash'] + 'ZZ'
d['xunlei_url'] = 'thunder://' + base64.b64encode(xunleiurl)
可以在模板中用“ {{xunlei_url}} ”调用。位置要放在return render(request, 'info.html', d)的前面。
——————————————————————————————————————
SSBC如何搬家?
数据库用mysqldump导出sql,在新服务器上运行一键包,再导入刚才的sql。
——————————————————————————————————————
提示duplicate id 'xxxx'解决办法
进入数据库,执行语句
update search_hash set tagged=True where id=xxxx;
复制代码

欢迎关注Bboysoul的博客www.bboysoul.com Have Fun

转载于:https://juejin.im/post/5bbefdf6f265da0ae505348a

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
作为最早在国内研究和实践DHT爬虫的人,我的灵感是来自芬兰Helsinki大学的这篇论文: Real-World Sybil Attacks in BitTorrent Mainline DHT 英文好的同学应该很容易读懂,跟我写的不到300行的爬虫代码大致原理一样。初次接触DHT网络的可以结合我之前的文章阅读,或者拜读Kevin Lynx的博客。所以具体原理在这里就不再阐述了。 包菜一开始只是为了纯粹的技术研究,没有去想这个搜索引擎能给网民带来什么样的福利。当时采集了大量的数据,发现有一半以上的资源为限级内容,于是试图去对资源进行分类并且做了很多这方面的工作。譬如,基本上能通过一套规则能筛选出限级内容,对资源进行分类,如果是视频还能匹配出是哪一部影片。可惜,这些工作我主观上认为对生活应用并没有太大价值,于是就放弃了深入的研究。或许是因为网民使用此类搜索引擎大部分都是具有明显的目的性。 包菜经历了多次点技术变更开源版本使用了django网站框架重写,之前是Flask,再早期是tornado。电影FM也是使用tornado,后来发现tornado并不适用于任何场景。以内容为王的网站还是django比较擅长,只是入门时间比其他框架都较长。早期数据库采用了MongoDB,因为配合Python读写数据很方便,也不用关注数据结构,搜索功能采用自带的关键词搜索,不过后来随着资源数量增加,性能也明显跟不上。今年换了WiredTiger引擎,自带的fulltext search还是不给力。另外Amazon的cloudsearch是个坑,土豪可以考虑,性能真的很不错,就是比较贵。最后还是搭建一个SphinxSearch吧,数据库也换成MySQL(MyISAM引擎),配合起来也很方便。Sphinx创建全文索引的速度很给力,官方的自评也很高,我自己测试1000w的资源(大概3GB),1分钟左右就索引完毕。不信,大家可以自测一下。 标签:ssbc
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值