1. 程式人生 > >Nutch2.3.1 hbase配置加使用。

Nutch2.3.1 hbase配置加使用。

ivy必須配合ant

安裝ant

#yum -y install ant


#mkdir /home/nutch-hbase
#cd /home/nutch-hbase
#tar zxvf apache-nutch-2.3.1-src.tar.gz
#mv apache-nutch-2.3.1-src.tar.gz nutch


(可選)修改預設下載目錄為C:\Users\使用者名稱\.ivy2\catch目錄
修改$NUTCH_HOME/ivy/ivysettings.xml檔案中更換包位置
<ivysettings>
 <caches defaultCacheDir="E:\\work\\maven\\libs"/>


(可選)$NUTCH_HOME/ivy/ivysettings.xml修改為aliyun伺服器地址,加快下載速度
<property name="repo.maven.org"
    value="http://maven.aliyun.com/nexus/content/groups/public/"
  


  override="false"/>


$NUTCH_HOME/ivy/ivy.xml
 <dependency org="org.apache.gora" name="gora-hbase" rev="0.6.1" conf="*->default" />
 <dependency org="org.apache.hbase" name="hbase-common" rev="0.98.8-hadoop2" conf="*->default" 


/>


(必須)安裝Hbase(Hbase0.98.8)
#cd /home
#wget http://archive.apache.org/dist/hbase/hbase-0.98.8/hbase-0.98.8-hadoop2-bin.tar.gz
#tar zxvf hbase-0.98.8-hadoop2-bin.tar.gz
#mv hbase-0.98.8-hadoop2-bin.tar.gz hbase


(必須)配置Hbase環境變數,針對所有使用者
#vi /etc/profile
在最下邊,新增下列內容:
HBASE = /home/hbase-0.98.8-hadoop2/
PATH = $HBASE/bin:$PATH
儲存退出後,立即生效
#source /etc/profile


(可選)輸入命令測試是否安裝成功
#hbase -version


(必須)啟動HBase
#cd $HBASE
#./bin/start-hbase.sh


(可選)停止HBase
#./bin/stop-hbase.sh


(必須)選擇資料庫檔案,新增以下配置
#vi $NUTCH_HOME/conf/gora.properties
gora.datastore.default=org.apache.gora.hbase.store.HBaseStore


(必須)增加內容如下:
$NUTCH_HOME/conf/nutch-site.xml
<configuration>
<property>
    <name>http.agent.name</name>
    <value>mypachong</value>
</property>
<property>
    <name>storage.data.store.class</name>
    <value>org.apache.gora.hbase.store.HBaseStore</value>
    <description>Default class for storing data</description>
</property>
</configuration>


(必須)建立種子檔案列表
#cd $NUTCH_HOME/
#mkdir -p urls
#cd urls
#touch seed.txt
#vi seed.txt
http://mil.news.sina.com.cn


(必須)最後開始編譯
#cd $NUTCH_HOME
#ant clean 
#ant


(必須)編譯完成後,執行抓取
#cd $NUTCH_HOME/
#./$NUTCH_HOME/runtime/local/bin/crawl urls/ mytest 10
另一種執行方式
#./$NUTCH_HOME/runtime/local/bin/nutch crawl urls mytest -depth 3 -topN 5




(必須)抓取完成後進入hbase shell檢視資料
#hbase shell
檢視列表
>list


檢視資料(mytest_webpage)為表名,查詢所有資料
>scan 'mytest_webpage'


獲取一行記錄
>get 'mytest_webpage', 'row1'


退出HBase Shell
>quit


刪除資料庫
>disable 'test'
>drop 'test'