hadoop運行java程序(jar包)并運行時動態(tài)指定參數(shù)
1)首先啟動hadoop2個進程,進入hadoop/sbin目錄下,依次啟動如下命令
[root@node02 sbin]# pwd /usr/server/hadoop/hadoop-2.7.0/sbin
sh start-dfs.sh sh start-yarn.sh jps
2)通過jps查看是否正確啟動,確保啟動如下6個程序
[root@node02 sbin]# jps 10096 DataNode 6952 NodeManager 9962 NameNode 10269 SecondaryNameNode 12526 Jps 6670 ResourceManager
3)如果啟動帶有文件的話,將文件加入到hdfs 的 /input下,如果出現(xiàn)如下錯誤的話,
[root@node02 hadoop-2.7.0]# hadoop fs -put sample.txt /input 21/01/02 01:13:15 WARN util.NativeCodeLoader: Unable to load native-hadoop library for atform... using builtin-java classes where applicable
在環(huán)境變量中添加如下字段
[root@node02 ~]# vim /etc/profile
export HADOOP_COMMON_LIB_NATIVE_DIR=${HADOOP_PREFIX}/lib/native export HADOOP_OPTS="-Djava.library.path=$HADOOP_PREFIX/lib"
4)進入到hadoop根目錄,根據(jù)存放位置決定
[root@node02 hadoop-2.7.0]# pwd /usr/server/hadoop/hadoop-2.7.0
5)新建hadoop hdfs 文件系統(tǒng)上的 /input 文件夾(用于存放輸入文件)
hadoop fs -mkdir /input
6)傳入測試文件,測試文件需要自己上傳到根目錄下(僅供測試,生產(chǎn)環(huán)境下存放到指定目錄)
[root@node02 hadoop-2.7.0]# hadoop fs -put sample.txt /input
7)查看傳入文件是否存在
[root@node02 hadoop-2.7.0]# hadoop fs -ls /input -rw-r--r-- 1 root supergroup 529 2021-01-02 01:13 /input/sample.txt
8)上傳jar包到根目錄下(生產(chǎn)環(huán)境下,放入指定目錄下),測試jar包為study_demo.jar
[root@node02 hadoop-2.7.0]# ll 總用量 1968 drwxr-xr-x. 2 10021 10021 4096 4月 11 2015 bin drwxr-xr-x. 3 10021 10021 4096 4月 11 2015 etc drwxr-xr-x. 2 10021 10021 4096 4月 11 2015 include drwxr-xr-x. 3 10021 10021 4096 4月 11 2015 lib drwxr-xr-x. 2 10021 10021 4096 4月 11 2015 libexec -rw-r--r--. 1 10021 10021 15429 4月 11 2015 LICENSE.txt drwxr-xr-x. 3 root root 4096 1月 2 01:36 logs -rw-r--r--. 1 10021 10021 101 4月 11 2015 NOTICE.txt -rw-r--r--. 1 10021 10021 1366 4月 11 2015 README.txt drwxr-xr-x. 2 10021 10021 4096 4月 11 2015 sbin drwxr-xr-x. 4 10021 10021 4096 4月 11 2015 share -rw-r--r--. 1 root root 1956989 6月 14 2021 study_demo.jar
9)使用hadoop 運行 java jar包,Main函數(shù)一定要加上全限定類名
hadoop jar study_demo.jar com.ncst.hadoop.MaxTemperature /input/sample.txt /output
10)運行結(jié)果縮略圖
21/01/02 01:37:54 INFO mapreduce.Job: Counters: 49 File System Counters FILE: Number of bytes read=61 FILE: Number of bytes written=342877 FILE: Number of read operations=0 FILE: Number of large read operations=0 FILE: Number of write operations=0 HDFS: Number of bytes read=974 HDFS: Number of bytes written=17 HDFS: Number of read operations=9 HDFS: Number of large read operations=0 HDFS: Number of write operations=2 Job Counters Launched map tasks=2 Launched reduce tasks=1 Data-local map tasks=2 Total time spent by all maps in occupied slots (ms)=14668 Total time spent by all reduces in occupied slots (ms)=4352 Total time spent by all map tasks (ms)=14668 Total time spent by all reduce tasks (ms)=4352 Total vcore-seconds taken by all map tasks=14668 Total vcore-seconds taken by all reduce tasks=4352 Total megabyte-seconds taken by all map tasks=15020032 Total megabyte-seconds taken by all reduce tasks=4456448 Map-Reduce Framework Map input records=5 Map output records=5 Map output bytes=45 Map output materialized bytes=67 Input split bytes=180 Combine input records=0 Combine output records=0 Reduce input groups=2 Reduce shuffle bytes=67 Reduce input records=5 Reduce output records=2 Spilled Records=10 Shuffled Maps =2 Failed Shuffles=0 Merged Map outputs=2 GC time elapsed (ms)=525 CPU time spent (ms)=2510 Physical memory (bytes) snapshot=641490944 Virtual memory (bytes) snapshot=6241415168 Total committed heap usage (bytes)=476053504 Shuffle Errors BAD_ID=0 CONNECTION=0 IO_ERROR=0 WRONG_LENGTH=0 WRONG_MAP=0 WRONG_REDUCE=0 File Input Format Counters Bytes Read=794 File Output Format Counters Bytes Written=17
10)運行成功后執(zhí)行命令查看,此時多出一個 /output 文件夾
[root@node02 hadoop-2.7.0]# hadoop fs -ls / drwxr-xr-x - root supergroup 0 2021-01-02 01:13 /input drwxr-xr-x - root supergroup 0 2021-01-02 01:37 /output drwx------ - root supergroup 0 2021-01-02 01:37 /tmp
11)查看 /output文件夾的文件
[root@node02 hadoop-2.7.0]# hadoop fs -ls /output -rw-r--r-- 1 root supergroup 0 2021-01-02 01:37 /output/_SUCCESS -rw-r--r-- 1 root supergroup 17 2021-01-02 01:37 /output/part-00000
12)查看part-r-00000 文件夾中的內(nèi)容,我這個測試用例用來獲取1949年和1950年的最高氣溫(華氏度)
[root@node02 hadoop-2.7.0]# hadoop fs -cat /output/part-00000 1949 111 1950 22
13)在瀏覽器端訪問端口可以觀看可視化界面,對應(yīng)的是hadoop服務(wù)器地址和自己設(shè)置的端口,通過可視化界面查看input文件夾面剛剛上傳的sample.txt文件
http://192.168.194.XXX:50070/
14)測試程序jar包和測試文件已上傳到github上面,此目錄有面經(jīng)和我自己總結(jié)的面試題
GitHub
如有興趣的同學(xué)也可以查閱我的秒殺系統(tǒng)
秒殺系統(tǒng)
以上就是hadoop如何運行java程序(jar包)運行時動態(tài)指定參數(shù)的詳細內(nèi)容,更多關(guān)于hadoop運行java程序的資料請關(guān)注腳本之家其它相關(guān)文章!
- java結(jié)合HADOOP集群文件上傳下載
- Java訪問Hadoop分布式文件系統(tǒng)HDFS的配置說明
- java使用hadoop實現(xiàn)關(guān)聯(lián)商品統(tǒng)計
- Java執(zhí)行hadoop的基本操作實例代碼
- 深入淺析Java Object Serialization與 Hadoop 序列化
- hadoop中實現(xiàn)java網(wǎng)絡(luò)爬蟲(示例講解)
- Java/Web調(diào)用Hadoop進行MapReduce示例代碼
- Hadoop運行時遇到j(luò)ava.io.FileNotFoundException錯誤的解決方法
- java實現(xiàn)對Hadoop的操作
- 利用Java連接Hadoop進行編程
相關(guān)文章
使用javaweb項目對數(shù)據(jù)庫增、刪、改、查操作的實現(xiàn)方法
這篇文章主要給大家介紹了關(guān)于使用javaweb項目對數(shù)據(jù)庫增、刪、改、查操作的實現(xiàn)方法,avaWeb是指使用Java語言進行Web應(yīng)用程序開發(fā)的技術(shù),可以利用Java編寫一些動態(tài)網(wǎng)頁、交互式網(wǎng)頁、企業(yè)級應(yīng)用程序等,需要的朋友可以參考下2023-07-07JDK動態(tài)代理之WeakCache緩存的實現(xiàn)機制
這篇文章主要介紹了JDK動態(tài)代理之WeakCache緩存的實現(xiàn)機制2018-02-02Java面向?qū)ο蠡A(chǔ)知識之委托和lambda
這篇文章主要介紹了Java面向?qū)ο蟮闹泻?lambda,文中有非常詳細的代碼示例,對正在學(xué)習(xí)java基礎(chǔ)的小伙伴們有很好的幫助,需要的朋友可以參考下2021-11-11Springboot基于Redisson實現(xiàn)Redis分布式可重入鎖源碼解析
這篇文章主要介紹了Springboot基于Redisson實現(xiàn)Redis分布式可重入鎖,本文通過案例源碼分析給大家介紹的非常詳細,對大家的學(xué)習(xí)或工作具有一定的參考借鑒價值,需要的朋友可以參考下2022-03-03Java通過動態(tài)代理實現(xiàn)一個簡單的攔截器操作
這篇文章主要介紹了Java通過動態(tài)代理實現(xiàn)一個簡單的攔截器操作,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教2021-07-07mybatis-plus批量更新updateBatchById問題
這篇文章主要介紹了mybatis-plus批量更新updateBatchById問題,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教2023-07-07spring boot使用自定義配置的線程池執(zhí)行Async異步任務(wù)
這篇文章主要介紹了spring boot使用自定義配置的線程池執(zhí)行Async異步任務(wù),小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧2018-01-01