Sphinx+Mysql+Php 12亿DNS数据秒查
来源:互联网 发布:windows系统的特点 编辑:程序博客网 时间:2024/05/22 05:20
最近得到一个接近12亿的全球ns节点的数据,本来想用来做一个全国通过dns反查域名然后进行全国范围的网站收集和扫描的,后来发现网站的数量不是很准确,加上一个人的精力和财力实在难以完成这样一个庞大的任务,就没有做下去,只留下了这个搭建的笔记。
看很多人好奇最后的文件有多大,我就补充一下几张图片
这是数据库倒入完成的大小
这是索引文件的大小
这是我机器的配置情况
前后折腾大约用了半个月时间,一开始倒入走错路,加上经验不足没有建立主键倒入浪费太多时间
文本格式,简单的文本搜索,速度太慢,一次搜索接近花掉5-10分钟时间,决定将其倒入数据库进行一次优化,速度应该能提升不到,电脑上只有AMP的环境,那么就决定将其倒入到mysql中,
一开始使用Navicat进行倒入,刚好数据的格式是 ip,ns 这样的格式,倒入了接近5个小时发现还没有倒入到百分之一,这可是纯文本格式化的时候大小为54G的数据文件啊!
后来发现用mysql自带的load data local infile只话了30分钟左右,第一次导入的时候忘记新建主键了,只好重新导入一次
1
mysql>
load
data
local
infile
'E:\\dns\\rite\\20141217-rdns.txt'
into
table
dns
2
fields terminated
by
','
;
3
Query OK, 1194674130
rows
affected, 1700 warnings (29
min
26.65 sec)
4
Records: 1194674130 Deleted: 0 Skipped: 0 Warnings: 1700
接着是建立索引,因为我需要的模糊查询,所以在这里建立的是Full Text+Btree,差不多花了3天时间索引才建立完成,期间因为一不小心把mysql的执行窗口关闭了,以为就这么完蛋了,最后发现其实mysql还在后台默默的建立索引。
建立了索引之后发现查询速度也就比没有建立索引快那么一点,执行了一条
1
select
*
from
ns
where
ns
like
'%weibo.com'
然后就开始使用SPhinx来做索引提升速度,
从官方下载了64位的SPHINX MYSQL SUPPORT的包下载地址
接着配置配置文件,src里配置要mysql的账号密码
- source src1
- {
- sql_host = localhost
- sql_user = root
- sql_pass = root
- sql_db = ns
- sql_port = 3306
- sql_query = \
- SELECT id,ip,ns from ns //这里写上查询语句
- sql_attr_uint = id
- searchd
- {
- listen = 9312
- listen = 9306:mysql41
- log = E:/phpStudy/splinx/file/log.log
- query_log = E:/phpStudy/splinx/file/query.log
- pid_file = E:/phpStudy/splinx/file/searchd.pid
- searchd test1 #test1是你source的名称
然后切换到api目录下执行
- E:\phpStudy\splinx\api>test.py asd
- DEPRECATED: Do not call this method or, even better, use SphinxQL instead of an
- API
- Query 'asd ' retrieved 1000 of 209273 matches in 0.007 sec
- Query stats:
- 'asd' found 209291 times in 209273 documents
- Matches:
- 1. doc_id=20830, weight=1
- 2. doc_id=63547, weight=1
- 3. doc_id=96147, weight=1
- 4. doc_id=1717000, weight=1
- 5. doc_id=2213385, weight=1
- 6. doc_id=3916825, weight=1
- 7. doc_id=3981791, weight=1
- 8. doc_id=5489598, weight=1
- 9. doc_id=9348383, weight=1
- 10. doc_id=18194414, weight=1
- 11. doc_id=18194415, weight=1
- 12. doc_id=18195126, weight=1
- 13. doc_id=18195517, weight=1
- 14. doc_id=18195518, weight=1
- 15. doc_id=18195519, weight=1
- 16. doc_id=18195520, weight=1
- 17. doc_id=18195781, weight=1
- 18. doc_id=18195782, weight=1
- 19. doc_id=18200301, weight=1
- 20. doc_id=18200303, weight=1
01
<?php
02
include
'sphinxapi.php'
;
03
$conn
=mysql_connect(
'127.0.0.1'
,
'root'
,
'root'
);
04
mysql_select_db(
'ns'
,
$conn
);
05
$sphinx
=
new
SphinxClient();
06
$now
=time();
07
$sphinx
->SetServer (
'127.0.0.1'
, 9312 );
08
$result
=
$sphinx
->query (
'weibo.com'
,
'test1'
);
09
foreach
(
$result
[
'matches'
]
as
$key
=>
$val
){
10
$sql
=
"select * from ns where id='{$key}'"
;
11
$res
=mysql_query(
$sql
);
12
$res
=mysql_fetch_array(
$res
);
13
echo
"{$res['ip']}:{$res['ns']}"
;
14
15
}
16
echo
time()-
$now
;
17
?>
- 123.125.104.176:w-176.service.weibo.com
- 123.125.104.178:w-178.service.weibo.com
- 123.125.104.179:w-179.service.weibo.com
- 123.125.104.207:w-207.service.weibo.com
- 123.125.104.208:w-208.service.weibo.com
- 123.125.104.209:w-209.service.weibo.com
- 123.125.104.210:w-210.service.weibo.com
- 202.106.169.235:staff.weibo.com
- 210.242.10.56:weibo.com.tw
- 218.30.114.174:w114-174.service.weibo.com
- 219.142.118.228:staff.weibo.com
- 60.28.2.221:w-221.hao.weibo.com
- 60.28.2.222:w-222.hao.weibo.com
- 60.28.2.250:w-222.hao.weibo.com
- 61.135.152.194:sina152-194.staff.weibo.com
- 61.135.152.212:sina152-212.staff.weibo.com
- 65.111.180.3:pr1.cn-weibo.com
- 160.34.0.155:srm-weibo.us2.cloud.oracle.com
- 202.126.57.40:w1.weibo.vip.hk3.tvb.com
- 202.126.57.41:w1.weibo.hk3.tvb.com
- 0
0 0
- Sphinx+Mysql+Php 12亿DNS数据秒查
- Sphinx+MySQL+PHP 12亿DNS数据秒查
- Sphinx+MySQL+PHP 12亿DNS数据秒查
- php+mysql 海量数据的查询--Sphinx的方式
- sphinx+mysql+php做千万数据级别的搜索引擎
- PHP+Sphinx+Mysql做搜索引擎
- PHP+MySQL+SPHINX安装配置与测试
- 配置sphinx+mysql+php+python+memcache环境
- sphinx + scws + Mysql + PHP全文检索
- PHP+MySQL+sphinx+scws实现全文检索
- 为什么Sphinx查的数据比用SQL查还少?
- sqlserver 数据行统计,秒查语句
- 实战:上亿数据如何秒查
- 实战:上亿数据如何秒查
- 实战:上亿数据如何秒查
- 实战:上亿数据如何秒查
- 实战:上亿数据如何秒查?
- 实战:上亿数据如何秒查?
- CSS布局学习笔记之图片居中
- 解决: g++: internal compiler error: Killed (program cc1plus)
- 详解I2C(一)
- 根据月份分类 重构数组
- VS2010启动调试运行 和开始执行(不调试)的区别与耗时
- Sphinx+Mysql+Php 12亿DNS数据秒查
- HDU 5000 Clone (2014年鞍山赛区网络赛D题)
- Easyui - frozenColumns
- document.getElementById("xx").style.xxx中的所有属性
- 连接Oracle时报错ORA-12541: TNS: 无监听程序
- spring之Ioc机制
- 盤古化
- 毕业后头五年决定你的一生
- hdu 5349 MZL's simple problem