hadoop运行java程序(jar包)并运行时动态指定参数

1)首先启动hadoop2个进程,进入hadoop/sbin目录下,依次启动如下命令

[root@node02 sbin]# pwd/usr/server/hadoop/hadoop-2.7.0/sbin
sh start-dfs.shsh start-yarn.shjps

2)通过jps查看是否正确启动,确保启动如下6个程序

[root@node02 sbin]# jps10096 DataNode6952 NodeManager9962 NameNode10269 SecondaryNameNode12526 Jps6670 ResourceManager

3)如果启动带有文件的话,将文件加入到hdfs 的 /input下,如果出现如下错误的话,

[root@node02 hadoop-2.7.0]# hadoop fs -put sample.txt /input21/01/02 01:13:15 WARN util.NativeCodeLoader: Unable to load native-hadoop library for atform... using builtin-java classes where applicable

在环境变量中添加如下字段

[root@node02 ~]# vim /etc/profile
export HADOOP_COMMON_LIB_NATIVE_DIR=${HADOOP_PREFIX}/lib/nativeexport HADOOP_OPTS="-Djava.library.path=$HADOOP_PREFIX/lib"

4)进入到hadoop根目录,根据存放位置决定

[root@node02 hadoop-2.7.0]# pwd/usr/server/hadoop/hadoop-2.7.0

5)新建hadoop hdfs 文件系统上的 /input 文件夹(用于存放输入文件)

hadoop fs -mkdir /input

6)传入测试文件,测试文件需要自己上传到根目录下(仅供测试,生产环境下存放到指定目录)

[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包到根目录下(生产环境下,放入指定目录下),测试jar包为study_demo.jar

[root@node02 hadoop-2.7.0]# ll总用量 1968drwxr-xr-x. 2 10021 10021    4096 4月  11 2015 bindrwxr-xr-x. 3 10021 10021    4096 4月  11 2015 etcdrwxr-xr-x. 2 10021 10021    4096 4月  11 2015 includedrwxr-xr-x. 3 10021 10021    4096 4月  11 2015 libdrwxr-xr-x. 2 10021 10021    4096 4月  11 2015 libexec-rw-r--r--. 1 10021 10021   15429 4月  11 2015 LICENSE.txtdrwxr-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.txtdrwxr-xr-x. 2 10021 10021    4096 4月  11 2015 sbindrwxr-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函数一定要加上全限定类名

hadoop jar study_demo.jar com.ncst.hadoop.MaxTemperature /input/sample.txt /output

10)运行结果缩略图

21/01/02 01:37:54 INFO mapreduce.Job: Counters: 49File System CountersFILE: Number of bytes read=61FILE: Number of bytes written=342877FILE: Number of read operations=0FILE: Number of large read operations=0FILE: Number of write operations=0HDFS: Number of bytes read=974HDFS: Number of bytes written=17HDFS: Number of read operations=9HDFS: Number of large read operations=0HDFS: Number of write operations=2Job Counters Launched map tasks=2Launched reduce tasks=1Data-local map tasks=2Total time spent by all maps in occupied slots (ms)=14668Total time spent by all reduces in occupied slots (ms)=4352Total time spent by all map tasks (ms)=14668Total time spent by all reduce tasks (ms)=4352Total vcore-seconds taken by all map tasks=14668Total vcore-seconds taken by all reduce tasks=4352Total megabyte-seconds taken by all map tasks=15020032Total megabyte-seconds taken by all reduce tasks=4456448Map-Reduce FrameworkMap input records=5Map output records=5Map output bytes=45Map output materialized bytes=67Input split bytes=180Combine input records=0Combine output records=0Reduce input groups=2Reduce shuffle bytes=67Reduce input records=5Reduce output records=2Spilled Records=10Shuffled Maps =2Failed Shuffles=0Merged Map outputs=2GC time elapsed (ms)=525CPU time spent (ms)=2510Physical memory (bytes) snapshot=641490944Virtual memory (bytes) snapshot=6241415168Total committed heap usage (bytes)=476053504Shuffle ErrorsBAD_ID=0CONNECTION=0IO_ERROR=0WRONG_LENGTH=0WRONG_MAP=0WRONG_REDUCE=0File Input Format Counters Bytes Read=794File Output Format Counters Bytes Written=17

10)运行成功后执行命令查看,此时多出一个 /output 文件夹

[root@node02 hadoop-2.7.0]# hadoop fs -ls /drwxr-xr-x   - root supergroup          0 2021-01-02 01:13 /inputdrwxr-xr-x   - root supergroup          0 2021-01-02 01:37 /outputdrwx------   - 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 文件夹中的内容,我这个测试用例用来获取1949年和1950年的最高气温(华氏度)

[root@node02 hadoop-2.7.0]# hadoop fs -cat /output/part-000001949111195022

13)在浏览器端访问端口可以观看可视化界面,对应的是hadoop服务器地址和自己设置的端口,通过可视化界面查看input文件夹面刚刚上传的sample.txt文件http://192.168.194.XXX:50070/

14)测试程序jar包和测试文件已上传到github上面,此目录有面经和我自己总结的面试题

GitHub如有兴趣的同学也可以查阅我的秒杀系统秒杀系统

以上就是hadoop如何运行java程序(jar包)运行时动态指定参数的详细内容,更多关于hadoop运行java程序的资料请关注其它相关文章!

只有一条路不能选择——那就是放弃的路;

hadoop运行java程序(jar包)并运行时动态指定参数

相关文章:

你感兴趣的文章:

标签云: