Now that you've configured Hadoop, it's time to explore its main storage system, HDFS, or the Hadoop Distributed File System.
HDFS stores large amounts of data across a distributed cluster of nodes. The data is partitioned into smaller blocks, replicated for fault tolerance, and dispersed across the cluster. This architecture prevents data loss and enhances performance by breaking down large datasets into smaller, manageable blocks. Let's break down the key components of HDFS:
Key Takeaways
- HDFS is a distributed file system designed to store large datasets across a cluster.
- NameNode manages metadata and file system namespace, while DataNodes handle actual data storage.
- Understanding basic HDFS commands is essential for managing data within the Hadoop ecosystem.
- Starting and stopping HDFS involves formatting the NameNode and using shell scripts.
NameNode
A single server in the Hadoop cluster is designated as the NameNode. It is responsible for managing metadata, such as the file system namespace and permissions, and oversees all file operations.
DataNode
Other servers in the cluster operate as DataNodes. These nodes handle the actual data input/output operations, storing the data according to instructions from the NameNode.
Blocks
Larger datasets are divided into blocks, which are distributed across the file system. While earlier configurations used a default block size of 64MB, recent trends now consider 128MB or more as standard, adaptable to specific needs.
Starting HDFS
Before starting HDFS, format the NameNode with:
$ hadoop namenode -format
This command prepares the necessary paths defined in hdfs-site.xml for the HDFS environment.
After formatting, start HDFS by executing:
$ start-dfs.sh
HDFS Basic Commands
Interacting with HDFS is similar to any other file system. For example, listing directories in HDFS:
$ hdfs dfs -ls /
This command lists all files and directories within the specified HDFS directory.
Create a new directory using:
$ hdfs dfs -mkdir /test
To upload a file to this directory:
$ hdfs dfs -put testfile.txt /test
Reading Data from HDFS
To display a file's contents, use the cat command:
$ hdfs dfs -cat /test/testfile.txt
Stopping HDFS
To stop HDFS:
$ stop-dfs.sh
Other Useful Commands
For a comprehensive list of HDFS commands, run:
$ hdfs dfs
This command will reveal all available HDFS operations, resembling common file system commands like -tail, -mv, and -ls.
FAQ
What is a Namenode in HDFS?
The NameNode is responsible for managing the metadata and file system namespace within the Hadoop cluster, ensuring the coordinated storage of data across DataNodes.
How can I change the block size in HDFS?
The block size in HDFS can be adjusted in the hdfs-site.xml config file by modifying the dfs.blocksize property.
What are common HDFS commands I should know?
Essential HDFS commands include -ls for listing directories, -mkdir for creating directories, -put for uploading files, and -cat for reading file content.
Is it mandatory to format the NameNode before starting HDFS?
Yes, formatting the NameNode initializes the file system paths for the first time, a necessary step when setting up HDFS for the initial use.
