spark运行错误集

目录

java.io.IOException: No FileSystem for scheme: hdfs

Exit code is 143


java.io.IOException: No FileSystem for scheme: hdfs

,用到hadoop(2.7.4)、spark(2.11),在做一个数据分片的时候,单独将程序打包提交任务到spark上执行没有任何问题,但是集成到web项目中后,就来问题了

Exception in thread "main" java.io.IOException: No FileSystem for scheme: hdfs

这个问题有两种解决方法,第一种就是修改集群配置文件

core-site.xml,添加属性
fs.hdfs.impl
org.apache.hadoop.hdfs.DistributedFileSystem
The FileSystem for hdfs: uris.

这种方法有个缺点就是集群都跑起来了,还不知道有多少任务正在跑着,你跟人家停了,那不歇菜了!!!

另一种方法,那就是修改自己的代码:

configuration.set("fs.hdfs.impl", "org.apache.hadoop.hdfs.DistributedFileSystem");

在使用FileSystem的地方,设置org.apache.hadoop.hdfs.DistributedFileSystem

需要知道为什么这样做,参考这位大兄弟的博客, 大致意思就是。。。呃也没什么说的就是找不到配置项fs.hdfs.impl

下面贴一个操作hadoop的常用方法

public static void append(String path, String line) throws IOException {
BufferedWriter writer = null;
FSDataOutputStream fsout = null;

try {
    conf = new Configuration();
    conf.setBoolean("dfs.support.append", true);// 允许追加
    conf.set("hadoop.user", "hadoop");//设置用户
    conf.setBoolean("mapreduce.app-submission.cross-platform", true);//设置跨平台提交
    conf.set("fs.hdfs.impl", "org.apache.hadoop.hdfs.DistributedFileSystem");//设置使用hdfs分布式文件系统

FileSystem fs = FileSystem.get(URI.create(path), conf);
Path pathpath = new Path(path);

if (!fs.exists(pathpath)) {
    fs.create(pathpath).close();// 创建完成后关闭
}

fsout = fs.append(pathpath);// 追加
    writer = new BufferedWriter(new OutputStreamWriter(fsout));
    writer.write(line);
    writer.newLine();
    writer.flush();
} catch (IllegalArgumentException | IOException e) {
    System.err.println("追加文件失败\t" + e.getMessage());
} finally {

if (fsout != null)
fsout.close();

if (writer != null)
writer.close();

}
}

/**

* 向hdfs中上传本地文件
*
* @param dst
* hdfs目录
* @param src
* 本地文件
* @return 上传是否成功,成功true,删除本地数据,否则失败;如果
*/

public static boolean put(String dst, String... src) {
try {
conf = new Configuration();
conf.set("hadoop.user", "hadoop");
conf.setBoolean("mapreduce.app-submission.cross-platform", true);
conf.set("fs.hdfs.impl", "org.apache.hadoop.hdfs.DistributedFileSystem");
FileSystem fs = FileSystem.get(URI.create(dst), conf);
Path[] srcs = new Path[src.length];

for (int i = 0; i < src.length; i++) {
    srcs[i] = new Path(src[i]);
}

fs.copyFromLocalFile(true, false, srcs, new Path(dst));
} catch (IllegalArgumentException | IOException e) {
    System.err.println("文件上传失败\t" + e.getMessage());
    return false;
}

return true;
}

/**

* 判断要给文件或者目录是否存在
*
* @param dir
* 文件或目录
* @return 是否存在
*/

public static boolean exist(String dir) {
if (StringUtils.isBlank(dir)) {
    return false;
}

if (!dir.startsWith(P_HDFS)) {
dir = HDFS_URI + dir;
}

Configuration conf = new Configuration();
conf.set("hadoop.user", "hadoop");
conf.setBoolean("mapreduce.app-submission.cross-platform", true);
conf.set("fs.hdfs.impl", "org.apache.hadoop.hdfs.DistributedFileSystem");
try {
FileSystem fs = FileSystem.get(URI.create(dir), conf);
    return fs.exists(new Path(dir));
} catch (IllegalArgumentException | IOException e) {
    System.err.println("错误\t" + e.getMessage());
    return false;

}
}

public static boolean createDir(String dir) {
if (StringUtils.isBlank(dir)) {
return false;
}

if (!dir.startsWith(P_HDFS)) {
dir = HDFS_URI + dir;
}

Configuration conf = new Configuration();
conf.set("hadoop.user", "hadoop");
conf.setBoolean("mapreduce.app-submission.cross-platform", true);
conf.set("fs.hdfs.impl", "org.apache.hadoop.hdfs.DistributedFileSystem");

try {
FileSystem fs = FileSystem.get(URI.create(dir), conf);
return fs.mkdirs(new Path(dir));
} catch (IllegalArgumentException | IOException e) {
System.err.println("错误\t" + e.getMessage());
return false;
}
}

/**
* 删除一个hdfs目录

* @param dir
* hdfs目录
* @return 删除是否成功
*/

public static boolean deleteDir(String dir) {

if (StringUtils.isBlank(dir)) {
return false;
}

if (!dir.startsWith(P_HDFS)) {
dir = HDFS_URI + dir;
}

Configuration conf = new Configuration();
conf.set("hadoop.user", "hadoop");
conf.setBoolean("mapreduce.app-submission.cross-platform", true);
conf.set("fs.hdfs.impl", "org.apache.hadoop.hdfs.DistributedFileSystem");
boolean ret = false;

try {
FileSystem fs = FileSystem.get(URI.create(dir), conf);
ret = fs.delete(new Path(dir), true);
fs.close();
} catch (IOException e) {
System.err.println("错误\t" + e.getMessage());
ret = false;
}

return ret;

}

Container killed on request. Exit code is 143

运行中发现有任务被kill掉,多半是因为内存分配不足造成,所有需要修改内存配置。

可先参考

<property>
    <name>yarn.nodemanager.resource.memory-mb</name>
    <value>22528</value>
    <discription>每个节点可用内存,单位MB</discription>
</property>
 
<property>
    <name>yarn.scheduler.minimum-allocation-mb</name>
    <value>1500</value>
    <discription>单个任务可申请最少内存,默认1024MB</discription>
</property>
 
<property>
    <name>yarn.scheduler.maximum-allocation-mb</name>
    <value>16384</value>
    <discription>单个任务可申请最大内存,默认8192MB</discription>
</property>

然后在mapred-site.xml中添加下面内容:

<property>
    <name>mapreduce.map.memory.mb</name>
    <value>1500</value>
    <description>每个Map任务的物理内存限制</description>
</property>
 
<property>
    <name>mapreduce.reduce.memory.mb</name>
    <value>3000</value>
    <description>每个Reduce任务的物理内存限制</description>
</property>
 
<property>
    <name>mapreduce.map.java.opts</name>
    <value>-Xmx1200m</value>
</property>
 
<property>
    <name>mapreduce.reduce.java.opts</name>
    <value>-Xmx2600m</value>
</property>
<property>
    <name>mapreduce.framework.name</name>
    <value>yarn</value>
</property>

重启yarn再启动mapreduce任务,就可以了

但实际我遇到问题是在spark提交任务时参数做了如下设置

--conf spark.memory.fraction=0.9 \
--conf spark.memory.storageFraction=0.9 \

改为

--conf spark.memory.fraction=0.2 \
--conf spark.memory.storageFraction=0.4 \

 

评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

大怀特

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值