https://hadoop.apache.org/docs/stable/hadoop-project-dist/hadoop-common/SingleCluster.html
Prerequisites
frank@ZZHPC:~$ sudo apt install ssh frank@ZZHPC:~$ sudo apt install pdsh
What is pdsh?
PDSH (Parallel Distributed Shell) is a high-performance, multithreaded remote shell client that allows you to execute commands on multiple remote hosts simultaneously.
While a standard SSH command connects you to one machine at a time, pdsh is designed for cluster management or sysadmins who need to run the same task across 10, 100, or even 1,000 servers at once.
Key Features
-
Parallel Execution: It uses a "sliding window" (fanout) of threads to run commands in parallel rather than one-by-one (serially).
-
Host Grouping: You can target hosts using ranges (e.g.,
web[01-10]) or groups defined in files like/etc/genders. -
Thread Safety: It is designed to be highly efficient, handling timeouts on specific nodes without hanging the entire process.
-
Companion Tools: It usually comes with
pdcp(parallel copy), which lets you copy files to multiple machines at once.
Important Prerequisites
To use pdsh effectively, you usually need:
-
SSH Keys: You should have passwordless SSH access to the target machines.
-
RCMD Module: On Ubuntu, you often need to specify the ssh module by adding
-R sshto your command, or by setting the environment variablePDSH_RCMD_TYPE=ssh.
Download
frank@ZZHPC:~/download$ wget https://dlcdn.apache.org/hadoop/common/stable/hadoop-3.4.2.tar.gz frank@ZZHPC:~/download$ tar -xzf hadoop-3.4.2.tar.gz
Prepare to Start the Hadoop Cluster
In the distribution, edit the file etc/hadoop/hadoop-env.sh to define some parameters as follows:
JAVA_HOME=/usr/lib/jvm/java-17-openjdk-amd64
.bashrc:
export HADOOP_HOME=~/download/hadoop-3.4.2 PATH=$PATH:$HADOOP_HOME/bin export PATH
frank@ZZHPC:~$ hadoop
Usage: hadoop [OPTIONS] SUBCOMMAND [SUBCOMMAND OPTIONS]
or hadoop [OPTIONS] CLASSNAME [CLASSNAME OPTIONS]
where CLASSNAME is a user-provided Java class
OPTIONS is none or any of:
--config dir Hadoop config directory
--debug turn on shell script debug mode
--help usage information
buildpaths attempt to add class files from build tree
hostnames list[,of,host,names] hosts to use in worker mode
hosts filename list of hosts to use in worker mode
loglevel level set the log4j level for this command
workers turn on worker mode
SUBCOMMAND is one of:
Admin Commands:
daemonlog get/set the log level for each daemon
Client Commands:
archive create a Hadoop archive
checknative check native Hadoop and compression libraries availability
classpath prints the class path needed to get the Hadoop jar and the required libraries
conftest validate configuration XML files
credential interact with credential providers
distch distributed metadata changer
distcp copy file or directories recursively
dtutil operations related to delegation tokens
envvars display computed Hadoop environment variables
fedbalance balance data between sub-clusters
fs run a generic filesystem user client
gridmix submit a mix of synthetic job, modeling a profiled from production load
jar <jar> run a jar file. NOTE: please use "yarn jar" to launch YARN applications, not this command.
jnipath prints the java.library.path
kdiag Diagnose Kerberos Problems
kerbname show auth_to_local principal conversion
key manage keys via the KeyProvider
rbfbalance move directories and files across router-based federation namespaces
rumenfolder scale a rumen input trace
rumentrace convert logs into a rumen trace
s3guard S3 Commands
version print the version
Daemon Commands:
kms run KMS, the Key Management Server
registrydns run the registry DNS server
SUBCOMMAND may print help when invoked w/o parameters or with -h.
This will display the usage documentation for the hadoop script.
Now you are ready to start your Hadoop cluster in one of the three supported modes:
Standalone Operation
By default, Hadoop is configured to run in a non-distributed mode, as a single Java process. This is useful for debugging.
The following example copies the unpacked conf directory to use as input and then finds and displays every match of the given regular expression. Output is written to the given output directory.
$ mkdir input $ cp etc/hadoop/*.xml input $ bin/hadoop jar share/hadoop/mapreduce/hadoop-mapreduce-examples-3.4.2.jar grep input output 'dfs[a-z.]+' $ cat output/*
Essentially, you are telling Hadoop to run a specific MapReduce program (a "job") using its built-in examples library.
Breaking Down the Command
$ bin/hadoop jar share/hadoop/mapreduce/hadoop-mapreduce-examples-3.4.2.jar grep input output 'dfs[a-z.]+'
| Component | Description |
| bin/hadoop | This is the Hadoop script that executes commands. Since you are in standalone mode, it runs as a single Java process on your local machine. |
| jar | This tells Hadoop that you want to run a program stored in a Java Archive (JAR) file. |
| share/hadoop/.../examples-3.4.2.jar | This is the file path to the compiled library that contains several pre-written MapReduce programs (like wordcount, pi, and grep). |
| grep | This is the specific "main class" or program inside the JAR file you want to execute. It mimics the Unix grep command but uses MapReduce. |
| input | The directory containing your source files (the .xml files you copied earlier). |
| output | The directory where Hadoop will save the results. Note: This directory must not exist before you run the command, or Hadoop will throw an error. |
| 'dfs[a-z.]+' | The regular expression (regex) the program is looking for. It searches for any string starting with "dfs" followed by letters or dots. |
How it Works (The MapReduce Flow)
Even in standalone mode, Hadoop follows the MapReduce logic to process your request:
-
Map Phase: Hadoop reads every line of every XML file in the
inputfolder. It looks for strings that match your regex (dfs...). -
Reduce Phase: It counts how many times each matching string appeared.
-
Output: It writes the final counts of those matches into the
outputdirectory.
What happens next?
After this command finishes, you use the fourth command (cat output/*) to view the results. You will likely see a list of configuration properties from the Hadoop XML files that start with "dfs," such as dfs.replication or dfs.permissions.
Pseudo-Distributed Operation
Hadoop can also be run on a single-node in a pseudo-distributed mode where each Hadoop daemon runs in a separate Java process.
Configuration
Use the following:
etc/hadoop/core-site.xml:
<configuration>
<property>
<name>fs.defaultFS</name>
<value>hdfs://localhost:9000</value>
</property>
</configuration>
etc/hadoop/hdfs-site.xml:
<configuration>
<property>
<name>dfs.replication</name>
<value>1</value>
</property>
</configuration>
Setup passphraseless ssh
Now check that you can ssh to the localhost without a passphrase:
$ ssh localhost
If you cannot ssh to localhost without a passphrase, execute the following commands:
$ ssh-keygen -t rsa -P '' -f ~/.ssh/id_rsa $ cat ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys $ chmod 0600 ~/.ssh/authorized_keys
Execution
The following instructions are to run a MapReduce job locally. If you want to execute a job on YARN, see YARN on Single Node.
-
Format the filesystem:
$ bin/hdfs namenode -format
-
Start NameNode daemon and DataNode daemon:
$ sbin/start-dfs.sh
The hadoop daemon log output is written to the
$HADOOP_LOG_DIRdirectory (defaults to$HADOOP_HOME/logs). -
Browse the web interface for the NameNode; by default it is available at:
- NameNode -
http://localhost:9870/
- NameNode -
-
Make the HDFS directories required to execute MapReduce jobs:
$ bin/hdfs dfs -mkdir -p /user/<username>
-
Copy the input files into the distributed filesystem:
$ bin/hdfs dfs -mkdir input $ bin/hdfs dfs -put etc/hadoop/*.xml input
-
Run some of the examples provided:
$ bin/hadoop jar share/hadoop/mapreduce/hadoop-mapreduce-examples-3.4.2.jar grep input output 'dfs[a-z.]+'
-
Examine the output files: Copy the output files from the distributed filesystem to the local filesystem and examine them:
$ bin/hdfs dfs -get output output $ cat output/*
or
View the output files on the distributed filesystem:
$ bin/hdfs dfs -cat output/*
-
When you’re done, stop the daemons with:
$ sbin/stop-dfs.sh
YARN on a Single Node
You can run a MapReduce job on YARN in a pseudo-distributed mode by setting a few parameters and running ResourceManager daemon and NodeManager daemon in addition.
The following instructions assume that 1. ~ 4. steps of the above instructions are already executed.
-
Configure parameters as follows:
etc/hadoop/mapred-site.xml:<configuration> <property> <name>mapreduce.framework.name</name> <value>yarn</value> </property> <property> <name>mapreduce.application.classpath</name> <value>$HADOOP_MAPRED_HOME/share/hadoop/mapreduce/*:$HADOOP_MAPRED_HOME/share/hadoop/mapreduce/lib/*</value> </property> </configuration>etc/hadoop/yarn-site.xml:<configuration> <property> <name>yarn.nodemanager.aux-services</name> <value>mapreduce_shuffle</value> </property> <property> <name>yarn.nodemanager.env-whitelist</name> <value>JAVA_HOME,HADOOP_COMMON_HOME,HADOOP_HDFS_HOME,HADOOP_CONF_DIR,CLASSPATH_PREPEND_DISTCACHE,HADOOP_YARN_HOME,HADOOP_HOME,PATH,LANG,TZ,HADOOP_MAPRED_HOME</value> </property> </configuration> -
Start ResourceManager daemon and NodeManager daemon:
$ sbin/start-yarn.sh
-
Browse the web interface for the ResourceManager; by default it is available at:
- ResourceManager -
http://localhost:8088/
- ResourceManager -
-
Run a MapReduce job.
-
When you’re done, stop the daemons with:
$ sbin/stop-yarn.sh
Fully-Distributed Operation
For information on setting up fully-distributed, non-trivial clusters see Cluster Setup.

浙公网安备 33010602011771号