下载地址 shell
http://apache.fayea.com/apache-mirror/nutch/1.7/apache-nutch-1.7-bin.tar.gz 数据库
安装 apache
[root@centos data]# cd /data/ [root@centos data]# mkdir nutch [root@centos data]# tar -zxvf apache-nutch-1.7-bin.tar.gz个人是root用户,若是不是的话
[root@centos nutch]# chmod +x apache-nutch-1.7
将nutch加入PATH环境变量中。 vim
[root@centos nutch]# vim /etc/profile
export NUTCH_HOME=/data/nutch/apache-nutch-1.7 export PATH=$PATH:$NUTCH_HOME/bin
执行 centos
[root@centos nutch]# nutch Usage: nutch COMMAND where COMMAND is one of:
假如我想抓取http://www.amazon.cn/
修改抓取url正则,仅容许抓amazon.cn上的内容。 ide
[root@centos apache-nutch-1.7]# vim conf/regex-urlfilter.txt
修改 fetch
# accept anything else +.
为 网站
+^http://([a-z0-9]*\.)*amazon.cn/
若是不限制的话就不须要修改 this
新建urls目录,用于存放首要抓取的url列表 url
[root@centos apache-nutch-1.7]# mkdir urls [root@centos apache-nutch-1.7]# vim urls/seed.txt
写入
http://www.amazon.cn/
若是多个的话每一行写一个url
接下来给爬行蜘蛛取个名字
[root@centos apache-nutch-1.7]# vim conf/nutch-site.xml <?xml version="1.0"?> <?xml-stylesheet type="text/xsl" href="configuration.xsl"?> <!-- Put site-specific property overrides in this file. --> <configuration> <property> <name>http.agent.name</name> <value>Liu.Xun Nutch Spider</value> </property> </configuration>
solr安装以前有介绍了
http://my.oschina.net/liuxundemo/blog/208236
一、将nutch的schema替换原solr自带的schema。
二、首先在solr里面新建一个nutch的core。首先复制一份collection1为nutch-core,删掉nutch-core里面的core.properties,而后到solr管理界面去Add Core,名字要和nutch-core文字一致
三、将nutch的schema替换原solr自带的schema
[root@centos solrhome]# cp /data/nutch/apache-nutch-1.7/conf/schema-solr4.xml nutch-core/conf/
四、备份原来的索引schema,用nutch的schema替代
[root@centos solrhome]# cd nutch-core/conf/ [root@centos conf]# mv schema.xml schema.xml.bak [root@centos conf]# mv schema-solr4.xml schema.xml
修改schema
[root@centos conf]# vim schema.xml
在<fields></fields>中间加上
<field name="_version_" type="string" stored="true" indexed="true"/>
五、启动solr,抓取数据
[root@centos conf]# cd /data/nutch/apache-nutch-1.7/ [root@centos apache-nutch-1.7]# bin/nutch crawl urls -dir towns -depth 10 -threads 10 -topN 10 -solr http://192.168.125.129:8080/solr/nutch-core 放置爬行结果的目录 -dir dirnames 设置保存所抓取网页的目录. -depth depth 代表抓取网页的层次深度 -delay delay 代表访问不一样主机的延时,单位为“秒” -threads threads 代表须要启动的线程数 -topN number 在每次迭代中限制爬行的头几个连接数,默认是Integer.MAX_VALUE
六、查看结果
1.查看crawldb数据库
查看url地址总数和它的状态及评分:bin/nutch readdb crawl/crawldb/ -stats
查看每一个url地址的详细内容,导出数据:bin/nutch readdb url/crawldb/ -dump crawldb(导出的地址)
查看具体的url,以163为例:bin/nutch readdb url/crawldb/ -url http://www.163.com/
2.查看linkdb数据库
查看连接状况:bin/nutch readlinkdb crawl/linkdb/ -url http://www.163.com/
导出linkdb数据库文件:bin/nutch readlinkdb crawl/linkdb/ -dump linkdb(导出的地址)
3.查看segments
bin/nutch readseg -list -dir crawl/segments/ 能够看到每个segments的名称,产生的页面数,抓取的开始时间和结束时间,抓取数和解析数。
bin/nutch readseg -dump crawl/segments/20090309103156 segdb 导出segments,其中crawl/segments/20090309103156为一个segments文件夹,segdb为存放转换后的内容的文件夹
四、nutch命令详解
bin/nutch crawl <urlDir> [-dir d] [-threads n] [-depth i] [-topN]