windows上传文件到 linux的hdfs
一、windows上传文件到 linux的hdfs
1、先在 centos 上开启 hdfs, 用 jps 可以看到下面信息, 说明完成开启

2、在win上配置 hadoop (https://www.cnblogs.com/Jomini/p/11432484.html) 后,
要在 hadoop 的 bin 文件上放以下两个文件(网上找下载),

3、创建 maven 工程, 运行读写程序
pom 文件
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<version>2.8.2</version>
</dependency>
<dependency>
<groupId>org.apache.hadoop</groupId>
<artifactId>hadoop-common</artifactId>
<version>2.7.2</version>
</dependency>
<dependency>
<groupId>org.apache.hadoop</groupId>
<artifactId>hadoop-client</artifactId>
<version>2.7.2</version>
</dependency>
<dependency>
<groupId>org.apache.hadoop</groupId>
<artifactId>hadoop-hdfs</artifactId>
<version>2.7.2</version>
</dependency>
运行上传文件
import java.io.IOException;
import java.net.Socket;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.FileStatus;
import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path; public class Apptest {
public static void main(String[] args) throws Exception, IOException {
upload();
} public static void upload() throws IOException {
Configuration conf = new Configuration();
conf.set("fs.defaultFS", "hdfs://192.168.121.133:9000");
FileSystem fs = FileSystem.get(conf);
Path src = new Path("d://test.txt");
Path dest = new Path("/");
fs.copyFromLocalFile(src, dest);
FileStatus[] fileStatus = fs.listStatus(dest);
for (FileStatus file : fileStatus) {
System.out.println(file.getPath());
}
System.out.println("上传成功");
} }
运行使用 Run configuration, 要 配置 linux 上的用户,不然抛出用户权限问题

console

hdfs

二、在 hdfs 创建路径创建路径
2.1 在 hdfs 创建路径
程序
import java.io.IOException;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path;
public class Apptest {
public static void main(String[] args) throws Exception, IOException {
Configuration conf = new Configuration();
conf.set("fs.defaultFS", "hdfs://192.168.121.133:9000");
//获取hdfs 客户端对象
FileSystem fs = FileSystem.get(conf);
//在hdfs 上创建路径
fs.mkdirs(new Path("/testPath"));
//关闭资源
fs.close(); System.out.println("end");
}
}
运行结果

2.2 在上面创建的路径 "/testPath" 下面 再创建路径 file
程序
import java.io.IOException;
import java.net.URI;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path; public class Apptest {
public static void main(String[] args) throws Exception, IOException { Configuration conf = new Configuration(); //获取hdfs 客户端对象
FileSystem fs = FileSystem.get(new URI("hdfs://192.168.121.133:9000"),conf,"root"); //在 /testPath 下创建路径
fs.mkdirs(new Path("/testPath/file")); //关闭资源
fs.close(); System.out.println("end");
}
}
点击在hdfs上面的路径 /testPath 会出现 /file

windows上传文件到 linux的hdfs的更多相关文章
- Windows上传文件到linux 使用winscp
Windows上传文件到linux 使用winscp, winscp下载目录 https://sourceforge.net/projects/winscp/postdownload?source=d ...
- Xshell实现Windows上传文件到Linux主机
我是怎么操作的: 1.打开一台本地Linux虚拟机,使用mount 挂载Windows的共享文件夹到Linux上,然后拷贝数据到Linux虚拟机里面:(经常第一步都不顺利,无法挂载Windows的文件 ...
- linux安装lrzsz支持rz从windows上传文件到linux
1.下载lrzsz wget https://wangxuejin-data-1252194948.cos.ap-shanghai.myqcloud.com/lrzsz-0.12.20.tar.gz ...
- windows 上传文件到 Linux 服务器
方法一: pscp E:\javaWP\new11111.txt username@130.75.7.156:/home/
- windows上传文件到linux
1.在putty的网站上下载putty跟pscp 2.安装ssh跟putty sudo apt-get install openssh-server sudo apt-get install putt ...
- 使用FileZilla解决从Windows上传文件到Linux vsftpd的乱码问题!
日前将golang的开发环境从windows转移到了CentOS6上,为了把以前写得项目代码上传到centos,架设了vsftpd服务,设置为本地用户登录,然后用惯用的ftp软件flashfxp上传了 ...
- 利用Xshell从windows上传文件到linux
1.首先,打开你的xshell客户端. 2.我用的是ubuntu 所以用 apt-get install lrzsz 命令来安装这个上传软件. 安装成功以后,可以使用rz上传,sz下载. 然后等待上传 ...
- windows上传文件到linux云服务器上
安装putty,将pscp.exe移到 C:\Windows\System32 目录下. 在cmd 中执行,pscp -l rot -pw [password] -ls [ip]:/opt 查看目录 ...
- python 从windows上传文件到linux脚本
import paramiko import datetime import os hostname = '192.168.112.132' username = 'root' password = ...
随机推荐
- 题解 P2719 【搞笑世界杯】
其实懂了之后很简单,但是刚开始真的很难想.. d[a][b]表示剩a张A类票和b张B类票时,最后两张票相同的概率 那么此时的排队的第一个人只有两种选择 拿A类票或者B类票 抛硬币得到的可能性当然是二分 ...
- 10.7 csp-s模拟测试63 Median+Game+Park
我堕落了 我觉得任牛逼的问题也是我的问题 T1 Median T2 Game T3 Park
- IPv6 邻居状态迁移
- 【Java语言特性学习之二】反射
一.概念java加载class文件分两种情况:(1)类型是编译器已知的,这种文件的.class文件在编译的时候,编译器会把.class文件打开(不加载)检查,称为Run- Time Type Iden ...
- jQuery 源码解析(六) $.each和$.map的区别
$.each主要是用来遍历数组或对象的,例如: var arr=[11,12,13,14]; $.each(arr,function(element,index){ //遍历arr数组 console ...
- 升级 ASP.NET Core 3.0 设置 JSON 返回 PascalCase 格式与 SignalR 问题
由于一些 JS 组件要求 JSON 格式是 PascalCase 格式,新版本 ASP.NET Core 3.0 中默认移除了 Newtonsoft.Json ,使用了微软自己实现的 System.T ...
- Caused by: java.lang.IllegalArgumentException: Could not resolve placeholder 'jdbc.username' in string value "${jdbc.username}"
1.启动dubbo的引用dubbo服务时候报下面这个错误,这是由于去找dubbo的发布服务未找到报的错误,所以先启动dubbo的发布服务即可. [INFO] Scanning for projects ...
- 2019-11-25-win10-uwp-发布旁加载自动更新
原文:2019-11-25-win10-uwp-发布旁加载自动更新 title author date CreateTime categories win10 uwp 发布旁加载自动更新 lindex ...
- 分享windows 10 下部署 elasticsearch 和 logstash (二)
接上一篇,es部署很简单,很快就弄好了. 但是还是有很多不玩美. 比如说:主机是本地的IP或机器名,端口是固定的9200. 而且是只有一个节点,我要在一台机器上部署多个节点呢. 经过一段时间的摸索,做 ...
- SQL学习笔记之 数据库基础(一)
数据库基础 数据库系统的组成:由数据库,数据库管理软件,数据库管理员DBA,支持数据库系统的硬件和软件组成,其中数据库管理员是对数据库进行规划.设计.维护.和监视的专业管理人员,在数据库系统中起着非常 ...