1. 使用idea远程访问
我们先创建一个Maven工程,导入以下依赖(注意要和自己的hadoop版本对应,我的是2版本):
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
<dependency> <groupId>org.apache.hive</groupId> <artifactId>hive-jdbc</artifactId> <version> 2.1 . 1 </version> </dependency> <dependency> <groupId>org.apache.hbase</groupId> <artifactId>hbase-it</artifactId> <version> 1.2 . 6 </version> </dependency> <dependency> <groupId>org.apache.hadoop</groupId> <artifactId>hadoop-client</artifactId> <version> 2.7 . 3 </version> </dependency> <dependency> <groupId>org.apache.hadoop</groupId> <artifactId>hadoop-common</artifactId> <version> 2.7 . 3 </version> </dependency> |
接着编写代码:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
package com.fx.demo; import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.fs.FSDataInputStream; import org.apache.hadoop.fs.FileStatus; import org.apache.hadoop.fs.FileSystem; import org.apache.hadoop.fs.Path; import java.io.BufferedReader; import java.io.InputStreamReader; import java.net.URI; import java.util.Arrays; /** * @author: eureka * @date: 2022/4/27 12:06 * @Description: idea连接hadoop demo */ public class demo {
public static void main(String[] args) throws Exception {
System.setProperty( "HADOOP_USER_NAME"
|