手撕包菜搭建
概述
最近做了兩件事,一件事就是買了塊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: [email protected] 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: 1Changed: 1Warnings: 0 MariaDB [mysql]> flush privileges; Query OK, 0 rows affected (0.00 sec) MariaDB [mysql]>
接著就可以遠端登陸資料庫了
之後要修改手撕包菜程式裡面的連線密碼
首先關閉相關的程序
ps -ef |grep python
一般就是下面幾個程序
root95810 20:51 ?00:00:00 /usr/bin/python -Es /usr/sbin/tuned -l -P root360410 21:13 pts/000:00:00 /usr/bin/python2 /usr/bin/gunicorn ssbc.wsgi:application -b 127.0.0.1:8000 --reload root361636041 21:13 pts/000:00:09 /usr/bin/python2 /usr/bin/gunicorn ssbc.wsgi:application -b 127.0.0.1:8000 --reload root36931 12 21:15 ?00:01:30 python simdht_worker.py root369410 21:15 ?00:00:00 python index_worker.py
kill之後再kill下面幾個程序
ps -ef |grep search
root346710 21:03 ?00:00:00 searchd --config ./sphinx.conf root346834670 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。 —————————————————————————————————————— SQL/">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的部落格ofollow,noindex">www.bboysoul.com
Have Fun