启动YARN后,将会启动ResourceManager以及NodeManager历程,可以通过jps呼吁举办查察。
当YARN启动完毕后,可以会见http://localhost:8088进入YARN的可视化打点界面,可以在此页面中查察使命的执行环境以及资源的分派。
3.5 行使Shell呼吁操纵HDFS
HDFS中的文件体系与Linux相同,由/代表根目次。
假如想进修Java工程化、高机能及漫衍式、深入浅出。微处事、Spring,MyBatis,Netty源码说明的伴侣可以加我的Java高级交换:854630135,群里有阿里大牛直播讲授技能,以及Java大型互联网技能的视频免费分享给各人。
- hadoop fs -cat <src>:表现文件中的内容。
- hadoop fs -copyFromLocal <localsrc> <dst>:将当地中的文件上传到HDFS。
- hadoop fs -copyToLocal <src> <localdst>:将HDFS中的文件下载到当地。
- hadoop fs -count <path>:查询指定路径下文件的个数。
- hadoop fs -cp <src> <dst>:在HDFS内对文件举办复制。
- hadoop fs -get <src> <localdst>:将HDFS中的文件下载到当地。
- hadoop fs -ls <path>:表现指定目次下的内容。
- hadoop fs -mkdir <path>:建设目次。
- hadoop fs -moveFromLocal <localsrc> <dst>:将当地中的文件剪切到HDFS中。
- hadoop fs -moveToLocal <src> <localdst> :将HDFS中的文件剪切到当地中。
- hadoop fs -mv <src> <dst> :在HDFS内对文件举办移动。
- hadoop fs -put <localsrc> <dst>:将当地中的文件上传到HDFS。
- hadoop fs -rm <src>:删除HDFS中的文件。
3.6 JAVA中操纵HDFS
- /**
- * @Auther: ZHUANGHAOTANG
- * @Date: 2018/11/6 11:49
- * @Description:
- */
- public class HDFSUtils {
- private static Logger logger = LoggerFactory.getLogger(HDFSUtils.class);
- /**
- * NameNode URL
- */
- private static final String NAMENODE_URL = "192.168.1.80:8020";
- /**
- * HDFS文件辖档同接工具
- */
- private static FileSystem fs = null;
- static {
- Configuration conf = new Configuration();
- try {
- fs = FileSystem.get(URI.create(NAMENODE_URL), conf);
- } catch (IOException e) {
- logger.info("初始化HDFS毗连失败:{}", e);
- }
- }
- /**
- * 建设目次
- */
- public static void mkdir(String dir) throws Exception {
- dir = NAMENODE_URL + dir;
- if (!fs.exists(new Path(dir))) {
- fs.mkdirs(new Path(dir));
- }
- }
- /**
- * 删除目次或文件
- */
- public static void delete(String dir) throws Exception {
- dir = NAMENODE_URL + dir;
- fs.delete(new Path(dir), true);
- }
- /**
- * 遍历指定路径下的目次和文件
- */
- public static List<String> listAll(String dir) throws Exception {
- List<String> names = new ArrayList<>();
- dir = NAMENODE_URL + dir;
- FileStatus[] files = fs.listStatus(new Path(dir));
- for (FileStatus file : files) {
- if (file.isFile()) { //文件
- names.add(file.getPath().toString());
- } else if (file.isDirectory()) { //目次
- names.add(file.getPath().toString());
- } else if (file.isSymlink()) { //软或硬链接
- names.add(file.getPath().toString());
- }
- }
- return names;
- }
- /**
- * 上传当前处事器的文件到HDFS中
- */
- public static void uploadLocalFileToHDFS(String localFile, String hdfsFile) throws Exception {
- hdfsFile = NAMENODE_URL + hdfsFile;
- Path src = new Path(localFile);
- Path dst = new Path(hdfsFile);
- fs.copyFromLocalFile(src, dst);
- }
- /**
- * 通过流上传文件
- */
- public static void uploadFile(String hdfsPath, InputStream inputStream) throws Exception {
- hdfsPath = NAMENODE_URL + hdfsPath;
- FSDataOutputStream os = fs.create(new Path(hdfsPath));
- BufferedInputStream bufferedInputStream = new BufferedInputStream(inputStream);
- byte[] data = new byte[1024];
- int len;
- while ((len = bufferedInputStream.read(data)) != -1) {
- if (len == data.length) {
- os.write(data);
- } else { //最后一次读取
- byte[] lastData = new byte[len];
- System.arraycopy(data, 0, lastData, 0, len);
- os.write(lastData);
- }
- }
- inputStream.close();
- bufferedInputStream.close();
- os.close();
- }
- /**
- * 从HDFS中下载文件
- */
- public static byte[] readFile(String hdfsFile) throws Exception {
- hdfsFile = NAMENODE_URL + hdfsFile;
- Path path = new Path(hdfsFile);
- if (fs.exists(path)) {
- FSDataInputStream is = fs.open(path);
- FileStatus stat = fs.getFileStatus(path);
- byte[] data = new byte[(int) stat.getLen()];
- is.readFully(0, data);
- is.close();
- return data;
- } else {
- throw new Exception("File Not Found In HDFS");
- }
- }
- }
3.7 执行一个MapReduce使命 (编辑:湖南网)
【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!
|