3.马士兵_hadoop入门

1.存储模块(hadoop),资源调度模块(yarn),计算引擎(mapreduce)

2.hdfs,看成一个由很多机器组成的大硬盘。支持动态扩展,动态增减。配置core-site.xml;slave文件记录了管理那些datanode,namenode可以集中管理。

172007_Gydb_1052786.png

3.本次是用java程序访问hdf,360,百度网盘。

4.如果机器跑不了那么多,就用伪分布式结构。

5. jps,hdfs dfsadmin -report,可以查看集群的启动情况。

6.hadoop默认存的路径是/tmp,如果没有修改过的话,linux重启不定时的会清除这个目录。有可能造成不正常,所以要进行一定的修改。hdfs namenode -formate。start[stop]-dfs.sh。

7.用程序访问hdfs。 

a.URL.

b.获得内容的简单方法:

URL.setURLStreamHandlerFactory(new FsUrlStreamHandlerFactory());
        URL url = new URL("hdfs://192.168.56.100:9000/hello.txt");
        InputStream in = url.openStream();
        IOUtils.copyBytes(in, System.out, 1024, true);

c.创建写入过程可能有用户权限问题。是因为:vi hdfs-site.xml中配置了权限的检查,内容,关闭检查:

<property>
        <name>dfs.permissions.enabled</name>
        <value>false</value>
</property>修改后只要重启namenode即可,如果重启集群,那生产环境的代价就太大了。另外说一句,delete文件默认只是放入垃圾堆中。
代码示例,基本的核心代码原理基本的baidu网盘就实现了:

import java.io.FileInputStream;
import java.io.InputStream;
import java.net.URL;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.FSDataOutputStream;
import org.apache.hadoop.fs.FileStatus;
import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.FsUrlStreamHandlerFactory;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.IOUtils;


public class HelloHDFS {

    public static void main(String[] args) throws Exception {
        /*URL url = new URL("http://www.baidu.com");
        InputStream in = url.openStream();
        IOUtils.copyBytes(in, System.out, 1024, true);*/
        /*URL.setURLStreamHandlerFactory(new FsUrlStreamHandlerFactory());
        URL url = new URL("hdfs://192.168.56.100:9000/hello.txt");
        InputStream in = url.openStream();
        IOUtils.copyBytes(in, System.out, 1024, true);*/
        Configuration conf = new Configuration();
        conf.set("fs.defaultFS", "hdfs://192.168.56.100:9000");
        FileSystem fileSys = FileSystem.get(conf);
        //这里能执行很多常规增删改查功能
        
        boolean suc = fileSys.mkdirs(new Path("/gxl"));
        System.out.println(suc);
        
        suc = fileSys.exists(new Path("/gxl"));
        System.out.println(suc);
        
//        suc = fileSys.delete(new Path("/gxl"),true);
//        System.out.println(suc);
        
        suc = fileSys.exists(new Path("/gxl"));
        System.out.println(suc);
        
        //上传windows文件
        FSDataOutputStream out = fileSys.create(new Path("/test.data"), true);
        FileInputStream in = new FileInputStream("F:/BaiduNetdiskDownload/Xftp.exe");
//        IOUtils.copyBytes(in, out, 4096,true);
        
        byte[] buf = new byte[4096];
        int len = in.read(buf);
        while(len != -1){
            out.write(buf,0,len);
            len = in.read(buf);
        }
        in.close();
        out.close();
        
        //读信息
        FileStatus[] fstatus = fileSys.listStatus(new Path("/"));
        for(FileStatus status:fstatus){
            System.out.println(status.getPath());
            System.out.println(status.getPermission());
            System.out.println(status.getReplication());
        }
    }
}
8.其实java写hdfs还是比较简单的,只不过实际中用的很少,有了hive,pig后,mapreduce也很少了。

9.hdf默认用linux权限系统来控制,kerberos,可以控制权限系统。

10.大数据的组件主要hdfs,yarn(资源管理调用),mapreduce到此,真个hdfs基础整个结束。这是个入门,如果你的技术能力比较强的,你已经可以开始你的大数据之旅了。

11.大数据过后就是就是云计算了,hdfs就是云计算基础了,比如spark内存计算,storm流式计算。yarn,mapreduce后有了云计算基础,textflow后ai基础就有了。wecker数据挖掘基础就有了。

总结:

1.权限可以用kerberos.

2.secondarynamenoe倒是叫check point name比较贴切。

3.ha可以实现超大规模集群,一台namenode根本装不下用Federation。

这些完全可以自动锻炼自己能力来搞定。

越学东西越多,越学越谦虚。

转载于:https://my.oschina.net/u/1052786/blog/880421

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值