12--配置IDEA远程调试Hadoop程序(Hadoop HA下)

来源:互联网 发布:mac写java 编辑:程序博客网 时间:2024/06/05 14:22

1. 设置hdfs-site.xml

试验环境下,可以把hdfs-site.xml中的dfs.permissions.enabled的值设置为false,从而关闭HDFS的访问权限限制,方便客户端远程调试。

但在生产环境,不要使用此方法。


2. 将core-site.xml,hdfs-site.xml,log4j.properties拷贝到代码工程的resource路径下

采用Hadoop HA配置时,因为core-site.xml中的 fs.defaultFS的value不是某台NameNode机器的路径,

而是在hdfs-site.xml中定义的dfs.nameservices,真实的两台NameNode在hdfs-site.xml中定义。

所以,也要把hdfs-site.xml拷贝到resource路径下。

如果没有配置HA,可能不需要拷贝hdfs-site.xml文件(但我没有试验这种情况,只是其他blog没有拷贝hdfs-site.xml)

注意:拷贝core-site.xml后一定要把hadoop.tmp.dir的配置注释掉,

否则远程运行mapreduce程序时,会把临时文件写到本机的${hadoop.tmp.dir}路径下


3. 在Run/Debug Configuration中,把HDFS路径加入到Program arguments中

4. 因为在MapReduce程序的context.write()方法在目标文件已创建的情况下,无法先删除再创建,
所以可以在创建文件的代码执行前,先将目标文件删除掉。例如调用此方法:
public class MyUtils {    public static void deleteDir(Configuration conf, String dirPath) throws IOException{        FileSystem fs=FileSystem.get(conf);        Path target=new Path(dirPath);        if(fs.exists(target)){            boolean delResult = fs.delete(target,true);            if(delResult){                System.out.println(target + " has been deleted sucessfullly.");            } else {                System.out.println(target + " deletion failed.");            }        }    }}

5. 运行程序进行验证

0 0
原创粉丝点击