Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

An Introduction to HDFS

DZone 's Guide to

An Introduction to HDFS

In this article, a big data expert takes a look at how to use HDFS and how to use it to create create node HDFS clusters.

· Big Data Zone ·
Free Resource

We are going to start a series of blog on HDFS, Zookeeper, HBase, and OpenTSDB and will see How to setup an OpenTSDB cluster using these services. In this blog, we will study about HDFS.

HDFS

The Hadoop Distributed File System (HDFS) is a Java-based distributed file system that is fault-tolerant, scalable, and extremely easy to expand. It is designed to run on commodity hardware and can be deployed on low-cost hardware. HDFS is the primary distributed storage for Hadoop applications. It provides interfaces for applications to move closer to data.

Architecture

HDFS architecture contains a NameNode, DataNode, and Secondary NameNode.

HDFS has a master/slave architecture.

Image title

NameNode - An HDFS cluster consists of a single NameNode (Master Server), which manages the file system namespace and regulates access to files by clients. It maintains and manages the file system metadata; e.g. what blocks make up a file, and on which datanodes those blocks are stored.

DataNode - There are a number of DataNodes, usually one per node in the cluster, which manages storage attached to the nodes that they run on. DataNode in HDFS stores the actual data. We can add more datanodes to increase the space available.

Secondary NameNode - The secondary NameNode service is not a standby secondary NameNode, despite its name. Specifically, it does not offer High Availability (HA) for the NameNode.

Why Secondary NameNode?

  • The NameNode stores modifications to the file system as a log appended to a native file system file.
  • When a NameNode starts up, it reads the HDFS state from an image file, fsimage, and then applies edits from the edits log file.
  • It then writes new HDFS state to the fsimage and starts normal operation with an empty edits file.
  • Since NameNode merges fsimage and edits files only during start up, the edits log file could get very large over time on a busy cluster.
  • Another side effect of a larger edits file is that the next restart of NameNode takes longer.
  • The Secondary NameNode merges the fsimage and the edits log files periodically and keeps edits log size within a limit.
  • It is usually run on a different machine than the primary NameNode, since its memory requirements are on the same order as the primary NameNode.

Key Features

Failure tolerant - data is duplicated across multiple DataNodes to protect against machine failures. The default is a replication factor of 3 (every block is stored on three machines, if you have 3 datanodes avalible).

Scalability - data transfers happen directly with the DataNodes so your read/write capacity scales fairly well with the number of DataNodes.

Space - need more disk space? Just add more DataNodes and re-balance.

Industry standard - Other distributed applications are built on top of HDFS (HBase, Map-Reduce).

HDFS is designed to process large data sets with write-once-read-many semantics, it is not for low latency access.

Data Organization

  • Each file written into HDFS is split into 64 MB or 128 MB data blocks.
  • Each block is stored on one or more nodes.
  • Each copy of the block is called a replica.

Block Placement Policy

  • The first replica is placed on the local node.
  • The second replica is placed in a different rack.
  • The third replica is placed in the same rack as the second replica.

Setup an HDFS Cluster

For creating an HDFS cluster, we are going to use Docker. For Docker image details, see: https://hub.docker.com/u/uhopper/

Steps

  • Create a Docker Swarm Network.
docker swarm init --advertise-addr <Node1 IP>
$ docker swarm init --advertise-addr 192.168.99.100
Swarm initialized: current node (dxn1zf6l61qsb1josjja83ngz) is now a manager.

To add a worker to this swarm, run the following command:

    docker swarm join \
    --token SWMTKN-1-49nj1cmql0jkz5s954yi3oex3nedyz0fb0xx14ie39trti4wxv-8vxv8rssmk743ojnwacrr2e7c \
    192.168.99.100:2377

To add a manager to this swarm, run 'docker swarm join-token manager' and follow the instructions.


Copy "docker swarm join \......" returned by the above command and execute in other 2 node VM to join the Swarm.

After joining the swarm create a overlay Network:

$ docker network create -d overlay generic-class-net


*Follow https://docs.docker.com/network/network-tutorial-overlay/#walkthrough

View the code on Gist.

NameNode

  • Create Environtment Variable file (namenode_env) for NameNode in VM1

CLUSTER_NAME=GenericClasss
HDFS_CONF_dfs_namenode_datanode_registration_ip___hostname___check=false
HDFS_CONF_dfs_datanode_max_transfer_threads=16000
HDFS_CONF_dfs_replication=3
HDFS_CONF_dfs_namenode_avoid_read_stale_datanode=true
HDFS_CONF_dfs_namenode_avoid_write_stale_datanode=true
HDFS_CONF_dfs_namenode_write_stale_datanode_ratio=1.0f
HDFS_CONF_dfs_namenode_check_stale_datanode=true
CORE_CONF_fs_defaultFS=hdfs://namenode:8020

View the code on Gist.

  • Create NameNode on VM1:

docker run -dit  --name namenode -p 50070:50070 -p 8020:8020  --env-file namenode_env --network generic-class-net -h namenode uhopper/hadoop-namenode

View the code on Gist.

  • Create the Enviorment Vriable file (datanode_env) for DataNode in all 3 VMs.
CLUSTER_NAME=GenericClasss
HDFS_CONF_dfs_namenode_datanode_registration_ip___hostname___check=false
CORE_CONF_fs_defaultFS=hdfs://namenode:8020
HDFS_CONF_dfs_client_use_datanode_hostname=false
network.host=_eth0_
HDFS_CONF_dfs_namenode_avoid_read_stale_datanode=true
HDFS_CONF_dfs_namenode_avoid_write_stale_datanode=true
HDFS_CONF_dfs_namenode_write_stale_datanode_ratio=1.0f
HDFS_CONF_dfs_namenode_check_stale_datanode=true

View the code on Gist.

  • Create DataNode1 on VM1:
docker run -dit --env-file datanode_env -p 50075:50075 -p 50020:50020 -p 41430:41430 -p 50010:50010 --network generic-class-net -h datanode1 --name datanode1 uhopper/hadoop-datanode

View the code on Gist.

  • Create DataNode2 on VM2:
docker run -dit --env-file datanode_env -p 50075:50075 -p 50020:50020 -p 41430:41430 -p 50010:50010 --network generic-class-net -h datanode2 --name datanode2 uhopper/hadoop-datanode

View the code on Gist.

  • Create DataNode3 on VM3.
docker run -dit --env-file datanode_env -p 50075:50075 -p 50020:50020 -p 41430:41430 -p 50010:50010 --network generic-class-net -h datanode3 --name datanode3 uhopper/hadoop-datanode

View the code on Gist.

In all vms, check that all the containers are up and running by executing docker ps.

Once all the containers are up and running, go to your vm1, open a browser, and open http://localhost:50070/dfshealth.html#tab-datanode.

You will see output like:

HDFS CLI:

In this post, we studied HDFS and how to create 3 node HDFS clusters. In the next post, we will look at Zookeeper and will create a Zookeeper cluster.

References:

https://hadoop.apache.org/docs/stable/hadoop-project-dist/hadoop-hdfs/HdfsUserGuide.htmlhttps://hadoop.apache.org/docs/r2.4.1/hadoop-project-dist/hadoop-hdfs/HdfsUserGuide.htmlhttps://docs.docker.com/network/network-tutorial-overlay/#walkthroughhttps://hub.docker.com/u/uhopper/

This article was first published on the Generic Class blog. 

Topics:
big data ,hdfs ,hadoop ,data clustering

Published at DZone with permission of

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}