文中关键解读內容包含:ant及ivy的构建、Nutch + Hbase构建 1、ant及ivy的构建 1-1)ant免费下载详细地址bindownload.cgi 1-2)自然环境自变量配备,改动linux /etc/profile文档內容,加上以下:
export ANT_HOME=/usr/ant export PATH=$ANT_HOME/bin:$PATH1-3)免费下载ivy build.xml ivy/history/latest-milestone/samples/build.xml
1-4)在免费下载的相对路径下实行 ant 指令,取得成功后在ant的安裝相对路径下增加ivy文档夹,并将ivy下的ivy.jar复制到ANT_HOME/lib文件目录下 2、Nutch + Hbase构建 <,挑选相匹配的版本号,文中采用apache-nutch-2.3.1-src.tar.gz2-2)改动conf/nutch-site.xml,內容以下:
configuration property name http.agent.name /name value hbase_nutch /value /property property name storage.data.store.class /name .apache.gora.hbase.store.HBaseStore /value description Default class for storing data /description /property property name plugin.includes /name value protocol-httpclient|urlfilter-regex|parse-(html|tika)|index-(basic|anchor)|indexer-solr|scoring-opic|urlnormalizer-(pass|regex|basic) /value /property /configuration 2-3)conf/regex-urlfilter.txt,用于过虑爬取网站的URL标准,阅读者能够依据本人要求开展订制。 2-4)改动 ivy/ivy.xml,关键用于设定所依靠的版本号,修改有以下: 加上Hbase适用,这儿必须留意,因为版本号适配难题,这儿应用0.98.13版本号,小编检测Hbase1.2版本号,出現不正确。
= org.apache.hbase name= hbase-client rev= 0.98.13-hadoop2 conf= *- default / = org.apache.hbase name= mon rev= 0.98.13-hadoop2 conf= *- default / = org.apache.hbase name= hbase-protocol rev= 0.98.13-hadoop2 conf= *- default / = org.apache.gora name= gora-hbase rev= 0.6.1 conf= *- default /别的的jar文档阅读者能够依据必须开展删掉或是变更。
2-5)复制hbase群集配备文档,cp $HBASE_HOME/conf/hbase-site.xml $NUTCH_HOME/conf/ 2-6)改动conf/gora.properties,加上以下配备
gora..apache.gora.hbase.store.HBaseStore2-7)配备爬取连接,在conf文件目录下建立urls文件目录,用于储存爬取连接,随后原始化種子文档seed.txt,內容加上以下:
2-8)开展编译程序,建立爬取程序 ,nutch网站根目录下实行ant runtime,結果以下:
第一次時间较为长,必须免费下载jar包这些。 2-9)爬取內容,在runtime/local/bin下实行以下指令:
./crawl /usr/apache-nutch-2.3.1/conf/urls/ numberOfRounds 10crawl 指令的主要参数表述以下: Usage: crawl seedDir crawlID [ solrUrl ] numberOfRounds seedDir :置放種子文档的文件目录 crawlID :爬取每日任务的ID solrURL :用以数据库索引及检索的solr详细地址 numberOfRounds :迭代更新频次,即爬取深层
2-10)查询hbase监管网页页面网站地址为:master-status,获得到 表名字为numberOfRounds_webpage,根据Spark编码载入以下:
// please ensure HBASE_CONF_DIR is on classpath of spark driver // e.g: set it through spark.driver.extraClassPath property // in spark-defaults.conf or through --driver-class-path // command line option of spark-submit val conf = HBaseConfiguration.create() val args = Array[String]( numberOfRounds_webpage ) // Other options for configuring scan behavior are available. rmation available at // /apache/hadoop/hbase/ conf.set(TableInputFormat.INPUT_TABLE, args(0)) // Initialize hBase table if necessary val admin = new HBaseAdmin(conf) if (!admin.isTableAvailable(args(0))) { println( 不会有该表 ) return //sc.stop() val pool = new HTablePool(conf, 1000) val table = pool.getTable(args(0)) try { val rs: ResultScanner = table.getScanner(new Scan()) var r = rs.next() while (r != null) { System.out.println( 得到到rowkey: + new String(r.getRow)) for (keyValue - r.raw()) { System.out.println( ( + new String(keyValue.getFamily()) + , + new String(keyValue.getQualifier()) + ): + new String(keyValue.getValue())); r = rs.next() } catch { case e = e.printStackTrace() //sc.stop() admin.close()展现結果以下:
到此一个简易的实例进行了,阅读者能够在这个基础上加上繁杂业务流程逻辑性。 (责任编辑:admin) |