亚洲av成人无遮挡网站在线观看,少妇性bbb搡bbb爽爽爽,亚洲av日韩精品久久久久久,兔费看少妇性l交大片免费,无码少妇一区二区三区

  免費(fèi)注冊 查看新帖 |

Chinaunix

  平臺(tái) 論壇 博客 文庫
最近訪問板塊 發(fā)新帖
查看: 2843 | 回復(fù): 0
打印 上一主題 下一主題

[Hadoop&HBase] Hadoop命令行接口運(yùn)行自己編寫的類 [復(fù)制鏈接]

論壇徽章:
0
跳轉(zhuǎn)到指定樓層
1 [收藏(0)] [報(bào)告]
發(fā)表于 2011-12-22 08:52 |只看該作者 |倒序?yàn)g覽
<DIV><FONT size=3 face=宋體>&nbsp;&nbsp;&nbsp; 最近學(xué)習(xí)Hadoop,可以使用命令行來簡單的管理Hadoop,例如使用:</FONT></DIV>
<DIV><FONT size=3 face=宋體>
<DIV style="WIDTH: 92.94%; HEIGHT: 122px" id=codeText class=codeText>
<OL style="PADDING-BOTTOM: 5px; MARGIN: 0px 1px 0px 0px; PADDING-LEFT: 0px; PADDING-RIGHT: 0px; PADDING-TOP: 5px" class=dp-css>
<LI>#查看hadoop的HDFS根節(jié)點(diǎn)情況</LI>
<LI>hadoop fs -ls /</LI>
<LI></LI>
<LI>#創(chuàng)建文件夾LGG</LI>
<LI>hadoop fs mkdir /user/root/LGG</LI></OL></DIV></FONT></DIV>
<DIV><FONT size=3 face=宋體>通過命令行接口來進(jìn)行操作。</FONT></DIV>
<DIV><FONT size=3 face=宋體>&nbsp;&nbsp;&nbsp; 當(dāng)然,hadoop命令行接口同樣支持自己編寫的類的參數(shù),例如在Hadoop權(quán)威指南中的一個(gè)例子如下:</FONT></DIV>
<DIV><FONT size=3 face=宋體>
<DIV id=codeText class=codeText>
<OL style="PADDING-BOTTOM: 5px; MARGIN: 0px 1px 0px 0px; PADDING-LEFT: 0px; PADDING-RIGHT: 0px; PADDING-TOP: 5px" class=dp-css>
<LI><SPAN style="COLOR: #000000"><SPAN style="COLOR: #0000ff">import</SPAN> <SPAN style="COLOR: #ff0000">java</SPAN><SPAN style="COLOR: #0000cc">.</SPAN><SPAN style="COLOR: #ff0000">io</SPAN><SPAN style="COLOR: #0000cc">.</SPAN><SPAN style="COLOR: #ff0000">InputStream</SPAN><SPAN style="COLOR: #0000cc">;</SPAN><BR></LI>
<LI><SPAN style="COLOR: #0000ff">import</SPAN> <SPAN style="COLOR: #ff0000">java</SPAN><SPAN style="COLOR: #0000cc">.</SPAN><SPAN style="COLOR: #ff0000">net</SPAN><SPAN style="COLOR: #0000cc">.</SPAN><SPAN style="COLOR: #ff0000">URL</SPAN><SPAN style="COLOR: #0000cc">;</SPAN><BR></LI>
<LI><SPAN style="COLOR: #0000ff">import</SPAN> <SPAN style="COLOR: #ff0000">org</SPAN><SPAN style="COLOR: #0000cc">.</SPAN>apache<SPAN style="COLOR: #0000cc">.</SPAN>hadoop<SPAN style="COLOR: #0000cc">.</SPAN>fs<SPAN style="COLOR: #0000cc">.</SPAN>FsUrlStreamHandlerFactory<SPAN style="COLOR: #0000cc">;</SPAN><BR></LI>
<LI><SPAN style="COLOR: #0000ff">import</SPAN> <SPAN style="COLOR: #ff0000">org</SPAN><SPAN style="COLOR: #0000cc">.</SPAN>apache<SPAN style="COLOR: #0000cc">.</SPAN>hadoop<SPAN style="COLOR: #0000cc">.</SPAN><SPAN style="COLOR: #ff0000">io</SPAN><SPAN style="COLOR: #0000cc">.</SPAN>IOUtils<SPAN style="COLOR: #0000cc">;</SPAN><BR></LI>
<LI><BR></LI>
<LI><SPAN style="COLOR: #ff9900">/**<BR></LI>
<LI>&nbsp;* <BR></LI>
<LI>&nbsp;* @author LGG<BR></LI>
<LI>&nbsp;*<BR></LI>
<LI>&nbsp;*/</SPAN><BR></LI>
<LI><SPAN style="COLOR: #0000ff">public</SPAN> <SPAN style="COLOR: #0000ff">class</SPAN> URLCat <SPAN style="COLOR: #0000cc">{</SPAN><BR></LI>
<LI>&nbsp;&nbsp;&nbsp;&nbsp;<SPAN style="COLOR: #0000ff">static</SPAN><SPAN style="COLOR: #0000cc">{</SPAN><BR></LI>
<LI>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<SPAN style="COLOR: #ff0000">URL</SPAN><SPAN style="COLOR: #0000cc">.</SPAN><SPAN style="COLOR: #ff0000">setURLStreamHandlerFactory</SPAN><SPAN style="COLOR: #0000cc">(</SPAN><SPAN style="COLOR: #0000ff">new</SPAN> FsUrlStreamHandlerFactory<SPAN style="COLOR: #0000cc">(</SPAN><SPAN style="COLOR: #0000cc">)</SPAN><SPAN style="COLOR: #0000cc">)</SPAN><SPAN style="COLOR: #0000cc">;</SPAN><BR></LI>
<LI>&nbsp;&nbsp;&nbsp;&nbsp;<SPAN style="COLOR: #0000cc">}</SPAN><BR></LI>
<LI>&nbsp;&nbsp;&nbsp;&nbsp;<SPAN style="COLOR: #0000ff">public</SPAN> <SPAN style="COLOR: #0000ff">static</SPAN> <SPAN style="COLOR: #0000ff">void</SPAN> main<SPAN style="COLOR: #0000cc">(</SPAN><SPAN style="COLOR: #ff0000">String</SPAN><SPAN style="COLOR: #0000cc">[</SPAN><SPAN style="COLOR: #0000cc">]</SPAN> args<SPAN style="COLOR: #0000cc">)</SPAN> <SPAN style="COLOR: #0000ff">throws</SPAN> <SPAN style="COLOR: #ff0000">Exception</SPAN><SPAN style="COLOR: #0000cc">{</SPAN><BR></LI>
<LI>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<SPAN style="COLOR: #ff0000">InputStream</SPAN> <SPAN style="COLOR: #ff0000">in</SPAN> <SPAN style="COLOR: #0000cc">=</SPAN> <SPAN style="COLOR: #0000ff">null</SPAN><SPAN style="COLOR: #0000cc">;</SPAN><BR></LI>
<LI>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<SPAN style="COLOR: #0000ff">try</SPAN><SPAN style="COLOR: #0000cc">{</SPAN><BR></LI>
<LI>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<SPAN style="COLOR: #ff0000">in</SPAN> <SPAN style="COLOR: #0000cc">=</SPAN> <SPAN style="COLOR: #0000ff">new</SPAN> <SPAN style="COLOR: #ff0000">URL</SPAN><SPAN style="COLOR: #0000cc">(</SPAN>args<SPAN style="COLOR: #0000cc">[</SPAN>0<SPAN style="COLOR: #0000cc">]</SPAN><SPAN style="COLOR: #0000cc">)</SPAN><SPAN style="COLOR: #0000cc">.</SPAN><SPAN style="COLOR: #ff0000">openStream</SPAN><SPAN style="COLOR: #0000cc">(</SPAN><SPAN style="COLOR: #0000cc">)</SPAN><SPAN style="COLOR: #0000cc">;</SPAN><BR></LI>
<LI>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;IOUtils<SPAN style="COLOR: #0000cc">.</SPAN>copyBytes<SPAN style="COLOR: #0000cc">(</SPAN><SPAN style="COLOR: #ff0000">in</SPAN><SPAN style="COLOR: #0000cc">,</SPAN> <SPAN style="COLOR: #ff0000">System</SPAN><SPAN style="COLOR: #0000cc">.</SPAN>out<SPAN style="COLOR: #0000cc">,</SPAN> 4096<SPAN style="COLOR: #0000cc">,</SPAN>false<SPAN style="COLOR: #0000cc">)</SPAN><SPAN style="COLOR: #0000cc">;</SPAN><BR></LI>
<LI>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<SPAN style="COLOR: #0000cc">}</SPAN><SPAN style="COLOR: #0000ff">finally</SPAN><SPAN style="COLOR: #0000cc">{</SPAN><BR></LI>
<LI>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;IOUtils<SPAN style="COLOR: #0000cc">.</SPAN>closeStream<SPAN style="COLOR: #0000cc">(</SPAN><SPAN style="COLOR: #ff0000">in</SPAN><SPAN style="COLOR: #0000cc">)</SPAN><SPAN style="COLOR: #0000cc">;</SPAN><BR></LI>
<LI>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<SPAN style="COLOR: #0000cc">}</SPAN><BR></LI>
<LI>&nbsp;&nbsp;&nbsp;&nbsp;<SPAN style="COLOR: #0000cc">}</SPAN><BR></LI>
<LI><SPAN style="COLOR: #0000cc">}</SPAN></SPAN></LI></OL></DIV></FONT></DIV>
<DIV><FONT size=3 face=宋體>&nbsp;&nbsp;&nbsp; 將URLCat.java編譯后生成class文件,然后可以將此類作為一個(gè)hadoop命令行接口的參數(shù)進(jìn)行使用,如下:
<DIV id=codeText class=codeText>
<OL style="PADDING-BOTTOM: 5px; MARGIN: 0px 1px 0px 0px; PADDING-LEFT: 0px; PADDING-RIGHT: 0px; PADDING-TOP: 5px" class=dp-css>
<LI>hadoop URLCat hdfs://localhost/user/tom/readme.txt</LI></OL></DIV></FONT></DIV>
<DIV><FONT size=3 face=宋體>作用是將HDFS文件里面的readme.txt輸出到System.out中,就是標(biāo)準(zhǔn)輸出。但是在執(zhí)行的時(shí)候會(huì)報(bào)以下錯(cuò)誤:</FONT></DIV>
<DIV>
<DIV id=codeText class=codeText>
<OL style="PADDING-BOTTOM: 5px; MARGIN: 0px 1px 0px 0px; PADDING-LEFT: 0px; PADDING-RIGHT: 0px; PADDING-TOP: 5px" class=dp-css>
<LI><SPAN style="COLOR: #000000"><SPAN style="COLOR: #ff0000">Exception</SPAN> <SPAN style="COLOR: #ff0000">in</SPAN> <SPAN style="COLOR: #ff0000">thread</SPAN> <SPAN style="COLOR: #ff00ff">"main"</SPAN> <SPAN style="COLOR: #ff0000">java</SPAN><SPAN style="COLOR: #0000cc">.</SPAN><SPAN style="COLOR: #ff0000">lang</SPAN><SPAN style="COLOR: #0000cc">.</SPAN><SPAN style="COLOR: #ff0000">NoClassDefFoundError</SPAN><SPAN style="COLOR: #0000cc">:</SPAN> URLCat<BR></LI>
<LI>Caused by<SPAN style="COLOR: #0000cc">:</SPAN> <SPAN style="COLOR: #ff0000">java</SPAN><SPAN style="COLOR: #0000cc">.</SPAN><SPAN style="COLOR: #ff0000">lang</SPAN><SPAN style="COLOR: #0000cc">.</SPAN><SPAN style="COLOR: #ff0000">ClassNotFoundException</SPAN><SPAN style="COLOR: #0000cc">:</SPAN> URLCat<BR></LI>
<LI>&nbsp;&nbsp;&nbsp;&nbsp;at <SPAN style="COLOR: #ff0000">java</SPAN><SPAN style="COLOR: #0000cc">.</SPAN><SPAN style="COLOR: #ff0000">net</SPAN><SPAN style="COLOR: #0000cc">.</SPAN><SPAN style="COLOR: #ff0000">URLClassLoader</SPAN><SPAN style="COLOR: #ff0000">$</SPAN>1<SPAN style="COLOR: #0000cc">.</SPAN><SPAN style="COLOR: #ff0000">run</SPAN><SPAN style="COLOR: #0000cc">(</SPAN><SPAN style="COLOR: #ff0000">URLClassLoader</SPAN><SPAN style="COLOR: #0000cc">.</SPAN><SPAN style="COLOR: #ff0000">java</SPAN><SPAN style="COLOR: #0000cc">:</SPAN>217<SPAN style="COLOR: #0000cc">)</SPAN><BR></LI>
<LI>&nbsp;&nbsp;&nbsp;&nbsp;at <SPAN style="COLOR: #ff0000">java</SPAN><SPAN style="COLOR: #0000cc">.</SPAN><SPAN style="COLOR: #ff0000">security</SPAN><SPAN style="COLOR: #0000cc">.</SPAN><SPAN style="COLOR: #ff0000">AccessController</SPAN><SPAN style="COLOR: #0000cc">.</SPAN>doPrivileged<SPAN style="COLOR: #0000cc">(</SPAN><SPAN style="COLOR: #0000ff">Native</SPAN> <SPAN style="COLOR: #ff0000">Method</SPAN><SPAN style="COLOR: #0000cc">)</SPAN><BR></LI>
<LI>&nbsp;&nbsp;&nbsp;&nbsp;at <SPAN style="COLOR: #ff0000">java</SPAN><SPAN style="COLOR: #0000cc">.</SPAN><SPAN style="COLOR: #ff0000">net</SPAN><SPAN style="COLOR: #0000cc">.</SPAN><SPAN style="COLOR: #ff0000">URLClassLoader</SPAN><SPAN style="COLOR: #0000cc">.</SPAN><SPAN style="COLOR: #ff0000">findClass</SPAN><SPAN style="COLOR: #0000cc">(</SPAN><SPAN style="COLOR: #ff0000">URLClassLoader</SPAN><SPAN style="COLOR: #0000cc">.</SPAN><SPAN style="COLOR: #ff0000">java</SPAN><SPAN style="COLOR: #0000cc">:</SPAN>205<SPAN style="COLOR: #0000cc">)</SPAN><BR></LI>
<LI>&nbsp;&nbsp;&nbsp;&nbsp;at <SPAN style="COLOR: #ff0000">java</SPAN><SPAN style="COLOR: #0000cc">.</SPAN><SPAN style="COLOR: #ff0000">lang</SPAN><SPAN style="COLOR: #0000cc">.</SPAN><SPAN style="COLOR: #ff0000">ClassLoader</SPAN><SPAN style="COLOR: #0000cc">.</SPAN><SPAN style="COLOR: #ff0000">loadClass</SPAN><SPAN style="COLOR: #0000cc">(</SPAN><SPAN style="COLOR: #ff0000">ClassLoader</SPAN><SPAN style="COLOR: #0000cc">.</SPAN><SPAN style="COLOR: #ff0000">java</SPAN><SPAN style="COLOR: #0000cc">:</SPAN>321<SPAN style="COLOR: #0000cc">)</SPAN><BR></LI>
<LI>&nbsp;&nbsp;&nbsp;&nbsp;at sun<SPAN style="COLOR: #0000cc">.</SPAN>misc<SPAN style="COLOR: #0000cc">.</SPAN>Launcher$AppClassLoader<SPAN style="COLOR: #0000cc">.</SPAN><SPAN style="COLOR: #ff0000">loadClass</SPAN><SPAN style="COLOR: #0000cc">(</SPAN>Launcher<SPAN style="COLOR: #0000cc">.</SPAN><SPAN style="COLOR: #ff0000">java</SPAN><SPAN style="COLOR: #0000cc">:</SPAN>294<SPAN style="COLOR: #0000cc">)</SPAN><BR></LI>
<LI>&nbsp;&nbsp;&nbsp;&nbsp;at <SPAN style="COLOR: #ff0000">java</SPAN><SPAN style="COLOR: #0000cc">.</SPAN><SPAN style="COLOR: #ff0000">lang</SPAN><SPAN style="COLOR: #0000cc">.</SPAN><SPAN style="COLOR: #ff0000">ClassLoader</SPAN><SPAN style="COLOR: #0000cc">.</SPAN><SPAN style="COLOR: #ff0000">loadClass</SPAN><SPAN style="COLOR: #0000cc">(</SPAN><SPAN style="COLOR: #ff0000">ClassLoader</SPAN><SPAN style="COLOR: #0000cc">.</SPAN><SPAN style="COLOR: #ff0000">java</SPAN><SPAN style="COLOR: #0000cc">:</SPAN>266<SPAN style="COLOR: #0000cc">)</SPAN><BR></LI>
<LI>Could <SPAN style="COLOR: #ff0000">not</SPAN> <SPAN style="COLOR: #ff0000">find</SPAN> the main <SPAN style="COLOR: #0000ff">class</SPAN><SPAN style="COLOR: #0000cc">:</SPAN> URLCat<SPAN style="COLOR: #0000cc">.</SPAN> Program will <SPAN style="COLOR: #ff0000">exit</SPAN><SPAN style="COLOR: #0000cc">.</SPAN></SPAN></LI></OL></DIV></DIV>
<DIV><FONT size=3 face=宋體>這個(gè)異常是典型的類裝入問題的異常,異常表明在類裝入的過程中,沒有找到URLCat這個(gè)類的定義。于是LGG查閱了相關(guān)資料,發(fā)現(xiàn)hadoop腳本執(zhí)行的時(shí)候,classpath的搜索路徑默認(rèn)會(huì)在當(dāng)前系統(tǒng)變量$HADOOP_CLASSPATH中去尋找,于是echo查看之,發(fā)現(xiàn)竟然顯示為空!</FONT></DIV>
<DIV><FONT size=3 face=宋體>&nbsp;&nbsp;&nbsp; 問題找到了,因?yàn)橄到y(tǒng)指定了classpath,所以回去這個(gè)環(huán)境變量中去尋找,但是在當(dāng)前路徑下找不到類URLCat(廢話,都是空的了)。使用export命令就可以解決了:</FONT></DIV>
<DIV><FONT size=3 face=宋體>
<DIV id=codeText class=codeText>
<OL style="PADDING-BOTTOM: 5px; MARGIN: 0px 1px 0px 0px; PADDING-LEFT: 0px; PADDING-RIGHT: 0px; PADDING-TOP: 5px" class=dp-css>
<LI>#.表示當(dāng)前目錄,即類所在目錄,只有這樣才能讓hadoop找到這個(gè)類</LI>
<LI></LI>
<LI>export HADOOP_CLASSPATH=.</LI></OL></DIV></FONT></DIV>
<DIV><FONT size=3 face=宋體>然后再執(zhí)行:</FONT></DIV>
<DIV><FONT size=3 face=宋體>
<DIV id=codeText class=codeText>
<OL style="PADDING-BOTTOM: 5px; MARGIN: 0px 1px 0px 0px; PADDING-LEFT: 0px; PADDING-RIGHT: 0px; PADDING-TOP: 5px" class=dp-css>
<LI>hadoop URLCat hdfs://localhost/user/tom/readme.txt</LI></OL></DIV></FONT></DIV>
<DIV><FONT size=3 face=宋體>就搞定了~~</FONT></DIV>
<DIV><FONT size=3 face=宋體></FONT>&nbsp;</DIV>
<DIV><FONT size=3 face=宋體></FONT>&nbsp;</DIV>
<DIV><FONT size=3 face=宋體></FONT>&nbsp;</DIV>
<DIV><FONT size=3 face=宋體></FONT>&nbsp;</DIV>
您需要登錄后才可以回帖 登錄 | 注冊

本版積分規(guī)則 發(fā)表回復(fù)

  

北京盛拓優(yōu)訊信息技術(shù)有限公司. 版權(quán)所有 京ICP備16024965號(hào)-6 北京市公安局海淀分局網(wǎng)監(jiān)中心備案編號(hào):11010802020122 niuxiaotong@pcpop.com 17352615567
未成年舉報(bào)專區(qū)
中國互聯(lián)網(wǎng)協(xié)會(huì)會(huì)員  聯(lián)系我們:huangweiwei@itpub.net
感謝所有關(guān)心和支持過ChinaUnix的朋友們 轉(zhuǎn)載本站內(nèi)容請注明原作者名及出處

清除 Cookies - ChinaUnix - Archiver - WAP - TOP