Home > Database > Mysql Tutorial > body text

Ubuntu12.04+Nutch2.2.1+MySQL 配置笔记

WBOY
Release: 2016-06-07 15:24:41
Original
1080 people have browsed it

日期:2013/10/13 系统 :Ubuntu12.04LTS JDK :1.7.0_21 Nutch :2.2.1 MySQL :5.5.32 ------------------------------------------------------------------------------------------------------------------------------------------------------------

    

日期:2013/10/13

系统:Ubuntu12.04LTS

JDK:1.7.0_21

Nutch:2.2.1

MySQL:5.5.32

--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

Pre1:安装配置OracleJDK

Pre2:安装配置MySQL      sudo apt-get install mysql-server,mysql-client

Pre3:安装配置Apache Ant  sudo apt-get install ant

Start:Ubuntu下搭建Nutch2.2.1,并以MySQL作为数据库,UTF-8为默认编码综合配置

     

Step1:MySQL配置

首先编辑 /etc/mysql/my.cnf 文件在[mysqld]下面添加以下内容:

innodb_file_format=barracuda
innodb_file_per_table=true
innodb_large_prefix=true
character-set-server=utf8
collation-server=utf8mb4_unicode_ci
max_allowed_packet=500M
Copy after login

然后创建数据库与数据表:

CREATE DATABASE nutch DEFAULT CHARACTER SET utf8mb4 DEFAULT COLLATE utf8;
Copy after login
CREATE TABLE `webpage` (
`id` varchar(767) 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,
`batchId` varchar(32) CHARACTER SET latin1 DEFAULT NULL, 
`baseUrl` varchar(767) DEFAULT NULL,
`content` longblob,
`title` varchar(2048) DEFAULT NULL,
`reprUrl` varchar(767) 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
ROW_FORMAT=COMPRESSED
DEFAULT CHARSET=utf8;
Copy after login
注:表中的字段根据nutch的conf文件“gora-sql-mapping”进行设置。同时也可通过自动方式生成数据库和表:配置好“gora-sql-mapping”、“gora.properties”及其它文件后,首次通过运行”bin/nutchinject urls”即可自动生成数据库和表,不过或许在自动生成的时候你会遇到问题,不过没有关系,通过及时查看hadoop.log文件你便会发现很多问题(如下图之一)与MySQL支持的数据类型、数据长度有关,只需要根据日志提示做修改、调试(可借助navicat工具像SQLServer方便操作数据库),然后再重复自动生成过程,直到成功为止。


Step2:Nutch配置

获取Nutch2.2.1,从官网http://www.apache.org/dyn/closer.cgi/nutch/下载,然后解压至本地安装目录,如本地根目录为${APACHE_NUTCH_HOME}

 配置nutch对mysql的支持,修改${APACHE_NUTCH_HOME}/ivy/ivy.xml文件

将以下行的注释取消:

<dependency org="”mysql”" name="”mysql-connector-java”" rev="”5.1.18″" conf="”*-">default”/></dependency>
Copy after login
<span><dependency org="org.apache.gora" name="gora-sql" rev="0.1.1-incubating" conf="*->default"></dependency></span>
Copy after login

修改以下行:

<pre class="brush:php;toolbar:false"><span><dependency org="org.apache.gora" name="gora-core" rev="0.3" conf="*->default"></dependency></span>
Copy after login
为:

<span><dependencyorg name="gora-core"><span>rev="0.2.1"</span>conf="*->default"/></dependencyorg></span>
Copy after login

Step3:数据库连接配置

编辑${APACHE_NUTCH_HOME}/conf/gora.properties文件,注释掉默认的数据库连接配置,同时添加以下配置内容:

###############################
#  MySQL configure   #
###############################
gora.sqlstore.jdbc.driver=com.mysql.jdbc.Driver
gora.sqlstore.jdbc.url=jdbc:mysql://localhost:3306/nutch?createDatabaseIfNotExist=true
gora.sqlstore.jdbc.user=xxxx(MySQL用户名)
gora.sqlstore.jdbc.password=xxxx(MySQL密码)
Copy after login

Step4:数据表映射配置

修改${APACHE_NUTCH_HOME}/conf/gora.properties文件,这里的修改建议按照前面介绍的自动生成数据表的方法进行修改,网上说的要将primarykey的长度从512修改成767,即:

改:  为:

Step5:nutch-site.xml配置

添加以下配置:

<property>
	<name>http.agent.name</name>
	<value>Your Nutch Spider</value>
</property>
<property>
	<name>http.accept.language</name>
	<value>zh-cn, en-us,en-gb,en;q=0.7,*;q=0.3</value>
	<description>*</description>
</property>
<property>
	<name>parser.character.encoding.default</name>
	<value>utf-8</value>
	<description>*</description>
</property>
<property>
	<name>storage.data.store.class</name>
	<value>org.apache.gora.sql.store.SqlStore</value>
	<description>*</description>
</property>
Copy after login
特别需要注意,本人在配置过程中也遇到了:
java.lang.NullPointerException 
at org.apache.avro.util.Utf8.<init>(Utf8.java:37) 
at org.apache.nutch.crawl.GeneratorReducer.setup(GeneratorReducer.java:100) 
at org.apache.hadoop.mapreduce.Reducer.run(Reducer.java:174) 
at org.apache.hadoop.mapred.ReduceTask.runNewReducer(ReduceTask.java:649) 
at org.apache.hadoop.mapred.ReduceTask.run(ReduceTask.java:418) 
at org.apache.hadoop.mapred.LocalJobRunner$Job.run(LocalJobRunner.java:398) </init>
Copy after login
解决办法就是在上述文件中另外添加一个属性:
<property>

    <name>generate.batch.id</name>

    <value>*</value>

</property>
Copy after login
Step6:使用ant 构建Nutch

(关于ant的命令,这里就不说明了),只需要切换到${APACHE_NUTCH_HOME}下执行ant clean 然后ant 即可。构建完毕后会在${APACHE_NUTCH_HOME}目录下生成runtime 文件夹。

Step:7 网页抓取,种子配置

创建种子文件

cd${APACHE_NUTCH_HOME}/runtime/local 
mkdir -p urls 
echo 'http://www.sina.com.cn' > urls/seed.txt
echo 'http://www.ifeng.com' > urls/seed.txt
Copy after login
执行爬取操作
bin/nutchcrawl urls -depth 5   -topN 10
Copy after login

至此,已经完成了基本的配置。






Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template