Changes between Version 3 and Version 4 of waue/2009/0409


Ignore:
Timestamp:
Apr 9, 2009, 6:29:08 PM (15 years ago)
Author:
waue
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • waue/2009/0409

    v3 v4  
    5555#!sh
    5656export JAVA_HOME=/usr/lib/jvm/java-6-sun
    57 
    5857export HADOOP_HOME=/opt/nutch
    59 
    6058export HADOOP_CONF_DIR=/opt/nutch_conf
    61 
    6259export HADOOP_SLAVES=$HADOOP_CONF_DIR/slaves
    63 
    64 export HADOOP_LOG_DIR=/tmp/nutch/logs
    65 
    66 export HADOOP_PID_DIR=/tmp/nutch/pid
    67 
     60export HADOOP_LOG_DIR=/tmp/hadoop/logs
     61export HADOOP_PID_DIR=/tmp/hadoop/pid
    6862export NUTCH_HOME=/opt/nutch
    69 
    7063export NUTCH_CONF_DIR=/opt/nutch_conf
    7164}}}
     
    8073#!sh
    8174<configuration>
    82 <property>
     75
     76  <property>
     77
    8378    <name>fs.default.name</name>
    84     <value>gm1.nchc.org.tw:9000</value>
    85     <description> The name of the default file system. Either the literal string "local" or a host:port for NDFS. </description>
    86 </property>
    87 <property>
     79
     80    <value>hdfs://node1:9000/</value>
     81
     82    <description> </description>
     83
     84  </property>
     85
     86  <property>
     87
    8888    <name>mapred.job.tracker</name>
    89     <value>gm1.nchc.org.tw:9001</value>
    90     <description> The host and port that the MapReduce job tracker runs at. If "local", then jobs are run in-process as a single map and reduce task. </description>
    91 </property>
     89
     90    <value>node1:9001</value>
     91
     92    <description>  </description>
     93
     94  </property>
     95
     96  <property>
     97
     98    <name>hadoop.tmp.dir</name>
     99
     100    <value>/tmp/hadoop/hadoop-${user.name}</value>
     101
     102    <description> </description>
     103
     104  </property>
     105
    92106</configuration>
    93107}}}
    94108=== 3.3 nutch-site.xml ===
     109 * 重要的設定檔,新增了必要的內容於內,然而想要了解更多參數資訊,請見nutch-default.xml
    95110{{{
    96111#!sh
     
    98113<property>
    99114  <name>http.agent.name</name>
    100   <value>waue</value>
     115  <value>nutch</value>
    101116  <description>HTTP 'User-Agent' request header. </description>
    102117</property>
    103118<property>
    104119  <name>http.agent.description</name>
    105   <value>MyTest</value>
     120  <value>nutch-crawl</value>
    106121  <description>Further description</description>
    107122</property>
    108123<property>
    109124  <name>http.agent.url</name>
    110   <value>gm1.nchc.org.tw</value>
     125  <value>node1</value>
    111126  <description>A URL to advertise in the User-Agent header. </description>
    112127</property>
    113128<property>
    114129  <name>http.agent.email</name>
    115   <value>waue@nchc.org.tw</value>
     130  <value>user@nchc.org.tw</value>
    116131  <description>An email address
    117132  </description>
    118133</property>
     134<property>
     135
     136  <name>plugin.folders</name>
     137
     138  <value>/opt/nutch/plugins</value>
     139
     140  <description>Directories where nutch plugins are located. </description>
     141
     142</property>
     143
     144<property>
     145
     146  <name>plugin.includes</name>
     147
     148  <value>protocol-(http|httpclient)|urlfilter-regex|parse-(text|html|js|ext|msexcel|mspowerpoint|msword|oo|pdf|rss|swf|zip)|index-(more|basic|anchor)|query-(more|basic|site|url)|response-(json|xml)|summary-basic|scoring-opic|urlnormalizer-(pass|regex|basic)</value>
     149
     150  <description> Regular expression naming plugin directory names</description>
     151
     152 </property>
     153
     154 <property>
     155
     156  <name>parse.plugin.file</name>
     157
     158  <value>parse-plugins.xml</value>
     159
     160  <description>The name of the file that defines the associations between
     161
     162  content-types and parsers.</description>
     163
     164 </property>
     165
     166 <property>
     167
     168   <name>db.max.outlinks.per.page</name>
     169
     170   <value>-1</value>
     171
     172   <description> </description>
     173
     174 </property>
     175
     176 <property>
     177
     178   <name>http.content.limit</name>
     179
     180   <value>-1</value>
     181
     182 </property>
     183
     184<property>
     185
     186<property>
     187
     188  <name>indexer.mergeFactor</name>
     189
     190  <value>500</value>
     191
     192  <description>The factor that determines the frequency of Lucene segment
     193
     194  merges. </description>
     195
     196</property>
     197
     198
     199<property>
     200
     201  <name>indexer.minMergeDocs</name>
     202
     203  <value>500</value>
     204
     205  <description>This number determines the minimum number of Lucene. </description>
     206
     207</property>
     208
    119209</configuration>
    120210}}}
    121211=== 3.4 slaves ===
    122 其實不用改,因為原本就是localhost
    123 {{{
    124 #!sh
    125 localhost
     212
     213 * 這個檔不用設定,因為依照hadoop的叢集環境,下面列出我們環境所設定的
     214{{{
     215#!sh
     216node1
     217node2
    126218}}}
    127219=== 3.5 crawl-urlfilter.txt ===
    128 將此檔的兩行改為下面內容
    129 {{{
    130 #!sh
     220 * 重新編輯爬檔規則,此檔重要在於若設定不好,則爬出來的結果幾乎是空的,也就是說最後你的搜尋引擎都找不到資料啦!
     221{{{
     222#!sh
     223# skip  ftp:, & mailto: urls
     224-^(ftp|mailto):
     225# skip image and other suffixes we can't yet parse
     226-\.(gif|GIF|jpg|JPG|png|PNG|ico|ICO|css|sit|eps|wmf|mpg|xls|gz|rpm|tgz|mov|MOV|exe|jpeg|JPEG|bmp|BMP)$
    131227# skip URLs containing certain characters as probable queries, etc.
    132228-[*!@]
    133 
    134 # accept hosts in MY.DOMAIN.NAME
    135 +^http://([a-z0-9]*\.)*.*/
    136 }}}
    137 
    138 
    139 == step 4 執行 ==
     229# accecpt anything else
     230+.*
     231}}}
     232
     233=== 3.6 regex-urlfilter.txt ===
     234 * 雖然官方網站鮮少介紹到此檔,但是crawl-urlfilter.txt用來設定爬intranet的規則,而regex-urlfilter.txt則是用來設定爬internet的規則
     235
     236{{{
     237$ cd /opt/nutch_conf
     238$ cp regex-urlfilter.txt regex-urlfilter.txt-bek
     239$ cp crawl-urlfilter.txt regex-urlfilter.txt
     240}}}
     241
     242== step 4 執行nutch ==
     243
     244 * 在此假設你已經把hadoop 啟動並且正在運作了。因此nutch是利用這個已經在運做的平台上
     245 * 如果你的hadoop還沒啟動,則請在master節點(此篇以node1當作master)下 bin/start-all.sh指令;如果你的環境很clean,則請在master節點下
     246   * 到/opt/nutch 或 /opt/hadoop皆可
     247{{{
     248$ cd /opt/nutch
     249$ bin/hadoop namenode -format
     250$ bin/start-all.sh
     251}}}
     252
    140253=== 4.1 編輯url清單 ===
    141254{{{
     
    146259{{{
    147260#!sh
    148 http://lucene.apache.org
    149 }}}
    150 
    151 === 4.2 開啟HDFS ===
    152 {{{
    153 $ bin/hadoop namenode -format
    154 $ bin/start-all.sh
    155 }}}
    156 === 4.3 上傳清單到HDFS ===
     261http://www.nchc.org.tw
     262}}}
     263
     264=== 4.2 上傳清單到HDFS ===
    157265{{{
    158266$ bin/hadoop -put urls urls
    159267}}}
    160 === 4.4 執行nutch crawl ===
    161 {{{
    162 $ bin/nutch crawl urls -dir crawl01 -depth 3
    163 }}}
    164 == step 5 web瀏覽 ==
     268=== 4.3 執行nutch crawl ===
     269 * 用下面的指令就可以命令nutch開始工作了,之後map reduce會瘋狂工作
     270{{{
     271$ bin/nutch crawl urls -dir search -threads 2 -depth 3 -topN 100000
     272}}}
     273   * 執行上個指令會把執行過程秀在stdout上。若想要以後慢慢看這些訊息,可以用io導向的方式傾倒於日誌檔
     274{{{
     275$ bin/nutch crawl urls -dir search -threads 2 -depth 3 -topN 100000 >& nutch.log
     276}}}
     277 * 在nutch運作的同時,可以在node1節點用瀏覽器,透過 [http://localhost:50030 job管理頁面],[http://localhost:50070 hdfs管理頁面],[http://localhost:50060 程序運作頁面] 來監看程序。
     278
     279== step 5 瀏覽搜尋結果 ==
     280 * nutch 在 step 4 的工作是把你寫在urls.txt檔內的網址,用map reduce的程序來進行資料分析,但是分析完之後,要透過tomcat來觀看結果。以下就是安裝與設定你的客製化搜尋引擎的步驟。
    165281
    166282=== 5.1 安裝tomcat ===
    167  * 下載
     283 * 下載tomcat
    168284{{{
    169285$ cd /opt/
     
    177293}}}
    178294
    179 === 5.2 將crawl結果匯入tomcat ===
    180 
     295=== 5.1 tomcat server設定 ===
     296
     297 * 修改 /opt/tomcat/conf/server.xml 以修正中文亂碼問題
     298{{{
     299#!sh
     300 <Connector port="8080" protocol="HTTP/1.1"
     301               connectionTimeout="20000"
     302               redirectPort="8443" URIEncoding="UTF-8"
     303               useBodyEncodingForURI="true" />
     304}}}
     305=== 5.3 下載crawl結果===
     306
     307 * 先把放在hdfs上,nutch的運算結果下載到local端
     308{{{
     309$ cd /opt/nutch
     310$ bin/hadoop dfs -get search /opt/search
     311}}}
     312
     313=== 5.4 設定nutch的搜尋引擎頁面到tomcat ===
     314
     315 * 把nutch的搜尋引擎頁面取代為tomcat的webapps/ROOT
    181316{{{
    182317$ cd /opt/nutch
     
    188323$ cd /opt/nutch
    189324$ mv /opt/nutch/web /opt/tomcat/webapps/ROOT
     325}}}
     326=== 5.5  設定搜尋引擎內容的來源路徑 ===
     327 * 5.4的步驟雖然設定好搜尋引擎的頁面,然而其只能當作是介面而已,因此這個步驟把要搜尋的內容與搜尋介面做個連結
     328{{{
    190329$ vim /opt/tomcat/webapps/ROOT/WEB-INF/classes/nutch-site.xml
    191330}}}
     
    201340}}}
    202341
    203 並且修改 /opt/tomcat/conf/server.xml 以修正中文問題
    204 {{{
    205 #!sh
    206     <Connector port="8080" protocol="HTTP/1.1"
    207                connectionTimeout="20000"
    208                redirectPort="8443" URIEncoding="UTF-8"/>
    209 }}}
    210 === 5.3 瀏覽crawl結果 ===
     342=== 5.6 啟動tomcat ===
    211343{{{
    212344$ /opt/tomcat/bin/startup.sh
    213345}}}
    214346
    215 
    216 [http://gm1.nchc.org.tw:8080]
     347== step 6 享受結果 ==
     348
     349Enjoy ! [http://localhost:8080]