16 | | == 環境 == |
| 16 | = 環境 = |
| 17 | * 目錄 |
| 18 | || /opt/nutch || nutch 家目錄|| |
| 19 | || /opt/nutch_conf || nutch設定檔 || |
| 20 | || /opt/hadoop || hadoop家目錄 || |
| 21 | || /opt/conf || hadoop設定檔 || |
| 22 | || /tmp/ || 日誌檔、中間檔與暫存檔 || |
| 23 | |
| 24 | * |
| 25 | == step 1 安裝好Hadoop叢集 == |
| 26 | |
| 27 | * 可以參考這篇 [wiki:0330Hadoop_Lab3hadoop叢集安裝] |
| 28 | * 當然單機版也可以,只是這樣就直接安裝nutch更省事囉!單機安裝nutch可以參考這裡[wiki:waue/2009/0406 nutch安裝],但是設定檔要參考這篇的才完整。 |
| 29 | |
| 30 | == step 2 下載與安裝 == |
| 31 | |
| 32 | * 下載 java 1.6 |
| 33 | {{{ |
| 34 | $ sudo apt-get install sun-java6-bin |
| 35 | }}} |
| 36 | * 下載 nutch 1.0 (2009/03/28) |
| 37 | {{{ |
| 38 | $ wget http://ftp.twaren.net/Unix/Web/apache/lucene/nutch/nutch-1.0.tar.gz |
| 39 | }}} |
| 40 | |
| 41 | == step 3 編輯設定檔 == |
| 42 | * 所有的設定檔都在 $NUTCH_HOME/conf 下 |
| 43 | === 3.1 hadoop-env.sh === |
| 44 | 將原本的檔案hadoop-env.sh任意處插入 |
| 45 | {{{ |
| 46 | #!sh |
| 47 | export JAVA_HOME=/usr/lib/jvm/java-6-sun |
| 48 | export HADOOP_HOME=/opt/nutch |
| 49 | export HADOOP_LOG_DIR=/tmp/nutch/logs |
| 50 | export HADOOP_SLAVES=/opt/nutch/conf/slaves |
| 51 | }}} |
| 52 | === 3.2 hadoop-site.xml === |
| 53 | {{{ |
| 54 | #!sh |
| 55 | <configuration> |
| 56 | <property> |
| 57 | <name>fs.default.name</name> |
| 58 | <value>gm1.nchc.org.tw:9000</value> |
| 59 | <description> The name of the default file system. Either the literal string "local" or a host:port for NDFS. </description> |
| 60 | </property> |
| 61 | <property> |
| 62 | <name>mapred.job.tracker</name> |
| 63 | <value>gm1.nchc.org.tw:9001</value> |
| 64 | <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> |
| 65 | </property> |
| 66 | </configuration> |
| 67 | }}} |
| 68 | === 3.3 nutch-site.xml === |
| 69 | {{{ |
| 70 | #!sh |
| 71 | <configuration> |
| 72 | <property> |
| 73 | <name>http.agent.name</name> |
| 74 | <value>waue</value> |
| 75 | <description>HTTP 'User-Agent' request header. </description> |
| 76 | </property> |
| 77 | <property> |
| 78 | <name>http.agent.description</name> |
| 79 | <value>MyTest</value> |
| 80 | <description>Further description</description> |
| 81 | </property> |
| 82 | <property> |
| 83 | <name>http.agent.url</name> |
| 84 | <value>gm1.nchc.org.tw</value> |
| 85 | <description>A URL to advertise in the User-Agent header. </description> |
| 86 | </property> |
| 87 | <property> |
| 88 | <name>http.agent.email</name> |
| 89 | <value>waue@nchc.org.tw</value> |
| 90 | <description>An email address |
| 91 | </description> |
| 92 | </property> |
| 93 | </configuration> |
| 94 | }}} |
| 95 | === 3.4 slaves === |
| 96 | 其實不用改,因為原本就是localhost |
| 97 | {{{ |
| 98 | #!sh |
| 99 | localhost |
| 100 | }}} |
| 101 | === 3.5 crawl-urlfilter.txt === |
| 102 | 將此檔的兩行改為下面內容 |
| 103 | {{{ |
| 104 | #!sh |
| 105 | # skip URLs containing certain characters as probable queries, etc. |
| 106 | -[*!@] |
| 107 | |
| 108 | # accept hosts in MY.DOMAIN.NAME |
| 109 | +^http://([a-z0-9]*\.)*.*/ |
| 110 | }}} |
| 111 | |
| 112 | |
| 113 | == step 4 執行 == |
| 114 | === 4.1 編輯url清單 === |
| 115 | {{{ |
| 116 | $ mkdir urls |
| 117 | $ vim urls.txt |
| 118 | }}} |
| 119 | |
| 120 | {{{ |
| 121 | #!sh |
| 122 | http://lucene.apache.org |
| 123 | }}} |
| 124 | |
| 125 | === 4.2 開啟HDFS === |
| 126 | {{{ |
| 127 | $ bin/hadoop namenode -format |
| 128 | $ bin/start-all.sh |
| 129 | }}} |
| 130 | === 4.3 上傳清單到HDFS === |
| 131 | {{{ |
| 132 | $ bin/hadoop -put urls urls |
| 133 | }}} |
| 134 | === 4.4 執行nutch crawl === |
| 135 | {{{ |
| 136 | $ bin/nutch crawl urls -dir crawl01 -depth 3 |
| 137 | }}} |
| 138 | == step 5 web瀏覽 == |
| 139 | |
| 140 | === 5.1 安裝tomcat === |
| 141 | * 下載 |
| 142 | {{{ |
| 143 | $ cd /opt/ |
| 144 | $ wget http://ftp.twaren.net/Unix/Web/apache/tomcat/tomcat-6/v6.0.18/bin/apache-tomcat-6.0.18.tar.gz |
| 145 | }}} |
| 146 | |
| 147 | * 解壓縮 |
| 148 | {{{ |
| 149 | $ tar -xzvf apache-tomcat-6.0.18.tar.gz |
| 150 | $ mv apache-tomcat-6.0.18 tomcat |
| 151 | }}} |
| 152 | |
| 153 | === 5.2 將crawl結果匯入tomcat === |
| 154 | |
| 155 | {{{ |
| 156 | $ cd /opt/nutch |
| 157 | $ mkdir web |
| 158 | $ cd web |
| 159 | $ jar -xvf nutch-1.0.war |
| 160 | $ rm nutch-1.0.war |
| 161 | $ mv /opt/tomcat/webapps/ROOT /opt/tomcat/webapps/ROOT-ori |
| 162 | $ cd /opt/nutch |
| 163 | $ mv /opt/nutch/web /opt/tomcat/webapps/ROOT |
| 164 | $ vim /opt/tomcat/webapps/ROOT/WEB-INF/classes/nutch-site.xml |
| 165 | }}} |
| 166 | |
| 167 | {{{ |
| 168 | #!sh |
| 169 | <configuration> |
| 170 | <property> |
| 171 | <name>searcher.dir</name> |
| 172 | <value>/opt/search</value> |
| 173 | </property> |
| 174 | </configuration> |
| 175 | }}} |
| 176 | |
| 177 | 並且修改 /opt/tomcat/conf/server.xml 以修正中文問題 |
| 178 | {{{ |
| 179 | #!sh |
| 180 | <Connector port="8080" protocol="HTTP/1.1" |
| 181 | connectionTimeout="20000" |
| 182 | redirectPort="8443" URIEncoding="UTF-8"/> |
| 183 | }}} |
| 184 | === 5.3 瀏覽crawl結果 === |
| 185 | {{{ |
| 186 | $ /opt/tomcat/bin/startup.sh |
| 187 | }}} |
| 188 | |
| 189 | |
| 190 | [http://gm1.nchc.org.tw:8080] |