nutch mysql solr_Nutch2.1+mysql+solr3.6.1+中文网站抓取
1、mysql 數據庫配置 linux mysql安裝步驟省略。 創建數據庫與表 [sql] view plaincopyprint? CREATE DATABASE nutch DEFAULT CHARACTER SET utf8 DEFAULT COLLATE utf8_general_ci; CREATE TABLE `webpage`( `id` varchar (767) CHARACTER SET latin1 NOT N
1、mysql 數據庫配置
linux mysql安裝步驟省略。
創建數據庫與表
[sql]
view plaincopyprint?
CREATE DATABASE nutch DEFAULT CHARACTER SET utf8 DEFAULT COLLATE utf8_general_ci;
CREATE TABLE `webpage` (
`id` varchar(767) CHARACTER SET latin1 NOT NULL,
`headers` blob,
`text` mediumtext DEFAULT NULL,
`status` int(11) DEFAULT NULL,
`markers` blob,
`parseStatus` blob,
`modifiedTime` bigint(20) DEFAULT NULL,
`score` float DEFAULT NULL,
`typ` varchar(32) CHARACTER SET latin1 DEFAULT NULL,
`baseUrl` varchar(512) CHARACTER SET latin1 DEFAULT NULL,
`content` mediumblob,
`title` varchar(2048) DEFAULT NULL,
`reprUrl` varchar(512) CHARACTER SET latin1 DEFAULT NULL,
`fetchInterval` int(11) DEFAULT NULL,
`prevFetchTime` bigint(20) DEFAULT NULL,
`inlinks` mediumblob,
`prevSignature` blob,
`outlinks` mediumblob,
`fetchTime` bigint(20) DEFAULT NULL,
`retriesSinceFetch` int(11) DEFAULT NULL,
`protocolStatus` blob,
`signature` blob,
`metadata` blob,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
2、安裝nutch2.1A、 nutch下載地址:http://apache.etoak.com/nutch/2.1/apache-nutch-2.1-src.zip
下載完成后家壓縮,
B、以下將nutch的根目錄定位${APACHE_NUTCH_HOME}.
C、配置nutch對mysql的支持,修改${APACHE_NUTCH_HOME}/ivy/ivy.xml文件
將這行的注釋取消default”/>
修改${APACHE_NUTCH_HOME}/conf/gora.properties文件,
注釋默認存儲配置
[html]
view plaincopyprint?
###############################
# Default SqlStore properties #
###############################
#gora.sqlstore.jdbc.driver=org.hsqldb.jdbc.JDBCDriver
#gora.sqlstore.jdbc.url=jdbc:hsqldb:hsql://localhost/nutchtest
#gora.sqlstore.jdbc.user=sa
#gora.sqlstore.jdbc.password=
取消以下代碼注釋,
###############################
# MySQL properties
################################
gora.sqlstore.jdbc.driver=com.mysql.jdbc.Driver
gora.sqlstore.jdbc.url=jdbc:mysql://localhost:3306/nutch?createDatabaseIfNotExist=true
gora.sqlstore.jdbc.user=xxxxx(mysql用戶名)
gora.sqlstore.jdbc.password=xxxxx(mysql密碼)
D、修改${APACHE_NUTCH_HOME}/conf/nutch-site.xml 加入如下代碼:
[html]
view plaincopyprint?
http.agent.namename>
Your Nutch Spidervalue>
property>
http.accept.languagename>
ja-jp, en-us,en-gb,en;q=0.7,*;q=0.3value>
Value of the “Accept-Language” request header field.
This allows selecting non-English language as default one to retrieve.
It is a useful setting for search engines build for certain national group.
description>
property>
parser.character.encoding.defaultname>
utf-8value>
The character encoding to fall back to when no other information
is availabledescription>
property>
storage.data.store.classname>
org.apache.gora.sql.store.SqlStorevalue>
The Gora DataStore class for storing and retrieving data.
Currently the following stores are available: ….
description>
property>
E、使用ant編譯 ${APACHE_NUTCH_HOME} 。
F、設置待抓取的網站
cd ${APACHE_NUTCH_HOME}/runtime/local
mkdir -p urls
echo 'http://nutch.apache.org/' > urls/seed.txt
G、執行爬行操作: bin/nutch crawl urls -depth 3 -topN 5
執行完在mysql中即可以查看到爬蟲抓取的內容
3、安裝solr,對nutch抓取的內容進行索引
(注意:參考資料中推薦使用solr4.0版本,4.0的兩個版本我都試了,沒有成功,所以替換為3.6.1版本)
solr下載地址:http://www.fayea.com/apache-mirror/lucene/solr/3.6.1/apache-solr-3.6.1.zip
A、解壓縮下載包,
B、下載
http://nlp.solutions.asia/wp-content/uploads/2012/08/schema.xml替換${APACHE_SOLR_HOME}/example/solr/conf/schema.xml.
C、啟動solr
cd ${APACHE_SOLR_HOME}/example
java -jar start.jar
D、在瀏覽器輸入地址http://localhost:8983/solr 測試是否啟動成功。
E、另起linux終端,輸入如下命令,使solr對nutch抓取內容進行索引。
cd ${APACHE_NUTCH_HOME}/runtime/local/
bin/nutch solrindex http://127.0.0.1:8983/solr/ -reindex
4、測試
在瀏覽器輸入
http://localhost:8983/solr ,看到如下界面:
在文本框中輸入 content:nutch 點擊查詢,便可查處內容中包含nutch關鍵字的網頁
本條技術文章來源于互聯網,如果無意侵犯您的權益請點擊此處反饋版權投訴
本文系統來源:php中文網
總結
以上是生活随笔為你收集整理的nutch mysql solr_Nutch2.1+mysql+solr3.6.1+中文网站抓取的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: gcasDtServ.exe是什么进程
- 下一篇: gcASCleaner.exe是什么进程