这两天搭建了基于nutch-2.2.1 hbase-0.90.6 solr-4.7.0 的本地搜索引擎,其中遇到了不少问题,故回忆着将过程和问题整理一下,以供学习交流
一 下载所需要文件
Nutch: http://mirrors.cnnic.cn/apache/nutch/2.2.1/apache-nutch-2.2.1-src.tar.gz
Hbase: http://archive.apache.org/dist/hbase/hbase-0.90.6/hbase-0.90.6.tar.gz
Solr: http://apache.fayea.com/apache-mirror/lucene/solr/4.7.0/solr-4.7.0.tgz
二 配置和编译Nutch
官方文档:http://wiki.apache.org/nutch/Nutch2Tutorial
这里运行ant编译时耗时较长,建议睡觉时进行 >.<
这里遇到了一个问题:
Fetcher: No agents listed in ‘http.agent.name’ property
解决方法是在nutch-site.xml文件中加入下面的配置:
<property>
<name> http.agent.name</name>
<value> HD nutch agent</value>
</property>
这里的value可能是随意的,然后如果修改的是.../runtime/local/下的nutch-site.xml,则不需要重新编译nutch,否则需要重新编译。
PS.
2014-04-04更新
忽然遇到了无法Parse文档的错误,logs/hadoop.log中记录:
2014-04-04 09:06:32,282 WARN parse.ParseUtil - Error parsing http://www.jinhaozszy.com/
java.util.concurrent.ExecutionException: java.lang.NoClassDefFoundError: org/cyberneko/html/parsers/DOMFragmentParser
.......
Caused by: java.lang.NoClassDefFoundError: org/cyberneko/html/parsers/DOMFragmentParser
.......
解决方法是下载缺少的
jar文件到lib里即可。(参见
http://lucene.472066.n3.nabble.com/Parsing-error-java-lang-NoClassDefFoundError-org-cyberneko-html-LostText-td4029958.html)
三 安装Hbase
官方文档:http://hbase.apache.org/book/quickstart.html
这里需要注意的是,如果系统是Ubuntu等系统,需要按文档要求修改/etc/hosts文件
四 配置Solr
这里需要注意,网上很多教程中说的需要将Nutch下的一个schema.xml替换掉solr下的一个同名文件以使solr可以索引nutch的文档,但是在solr这一版本中是不需要的。
但是这样在抓取网页后会遇到索引出错,Solr日志中有类似以下的记录:
2859895 [qtp1478922764-16] INFO org.apache.solr.update.processor.LogUpdateProcessor ? [collection1] webapp=/solr path=/update params={wt=javabin&version=2} {} 0 1
2859902 [qtp1478922764-16] ERROR org.apache.solr.core.SolrCore ? org.apache.solr.common.SolrException: ERROR: [doc=http://www.36kr.com/] unknown field 'host'
这里需要做的是,编辑~/solr-4.7.0/example/solr/collection1/conf/schema.xml,在<fields>…</fields>中增加以下的字段:
<field name="host" type="string" stored="false" indexed="true"/>
<field name="digest" type="string" stored="true" indexed="false"/>
<field name="segment" type="string" stored="true" indexed="false"/>
<field name="boost" type="float" stored="true" indexed="false"/>
<field name="tstamp" type="date" stored="true" indexed="false"/>
<field name="anchor" type="string" stored="true" indexed="true" multiValued="true"/>
<field name="cache" type="string" stored="true" indexed="false"/>
(参考
http://blog.csdn.net/panjunbiao/article/details/12171147)
听说要给solr配置IKanalyzer 那就未完待续吧~