Lab 4 - Installation of Hadoop and MapReduce WordCount Example
Lab 4 - Installation of Hadoop and MapReduce WordCount Example
1
CMPN451 Big Data Analytics Lab 4 - MapReduce with Hadoop
3. Install Hadoop by navigating to the following link and downloading the tar.gz file
for Hadoop version 3.3.0 (or a later version if you wish). (478 MB)
https://hadoop.apache.org/release/3.3.0.html
2
CMPN451 Big Data Analytics Lab 4 - MapReduce with Hadoop
You can now check that there is an extracted file named hadoop-3.3.0 by typing
the command “ls” or by visually inspecting the files.
5. Now, we move the extracted file to the location /usr/local/hadoop
At the end of the file, add the following lines: (Note: Replace the java version with the version
number you already have. You can navigate to the directory /usr/lib/jvm and check the file
name java-xx-openjdk-amd64)
export JAVA_HOME=/usr/lib/jvm/java-11-openjdk-amd64
export HADOOP_HOME=/usr/local/hadoop
export PATH=$PATH:$HADOOP_HOME/bin
export PATH=$PATH:$HADOOP_HOME/sbin
export HADOOP_MAPRED_HOME=$HADOOP_HOME
export HADOOP_COMMON_HOME=$HADOOP_HOME
export HADOOP_HDFS_HOME=$HADOOP_HOME
export YARN_HOME=$HADOOP_HOME
export HADOOP_COMMON_LIB_NATIVE_DIR=$HADOOP_HOME/native
export HADOOP_OPTS="-Djava.library.path=$HADOOP_HOME/native"
export PDSH_RCMD_TYPE=ssh
3
CMPN451 Big Data Analytics Lab 4 - MapReduce with Hadoop
source ~/.bashrc
export JAVA_HOME=/usr/lib/jvm/java-11-openjdk-amd64
4
CMPN451 Big Data Analytics Lab 4 - MapReduce with Hadoop
5
CMPN451 Big Data Analytics Lab 4 - MapReduce with Hadoop
6
CMPN451 Big Data Analytics Lab 4 - MapReduce with Hadoop
<name>yarn.nodemanager.aux-services.mapreduce.shuffle.class</name>
<value>org.apache.hadoop.mapred.ShuffleHandler</value>
</property>
7
CMPN451 Big Data Analytics Lab 4 - MapReduce with Hadoop
8
CMPN451 Big Data Analytics Lab 4 - MapReduce with Hadoop
14. Now, run the following commands on the terminal to create a directory for
hadoop space, name node and data node.
9
CMPN451 Big Data Analytics Lab 4 - MapReduce with Hadoop
16. Before starting the Hadoop Distributed File System (hdfs), we need to
make sure that the rcmd type is “ssh” not “rsh” when we type the following
command
pdsh -q -w localhost
17. If the rcmd type is “rsh” as in the above figure, type the following
commands:
export PDSH_RCMD_TYPE=ssh
cat $HOME/.ssh/id_rsa.pub >> $HOME/.ssh/authorized_keys
chmod 0600 ~/.ssh/authorized_keys
Run Step 16 again to check that the rcmd type is now ssh.
If not, skip that step.
10
CMPN451 Big Data Analytics Lab 4 - MapReduce with Hadoop
20. Type the following command. You should see an output similar to the one
in the following figure.
jps
21. Go to localhost:9870 from the browser. You should expect the following
11
CMPN451 Big Data Analytics Lab 4 - MapReduce with Hadoop
2. Create a directory on the Desktop named Lab and inside it create two folders;
one called “Input” and the other called “tutorial_classes”.
[You can do this step using GUI normally or through terminal commands]
cd Desktop
mkdir Lab
mkdir Lab/Input
mkdir Lab/classes
3. Add the file attached with this document “WordCount.java” in the directory Lab
4. Add the file attached with this document “input.txt” in the directory Lab/Input.
5. Type the following command to export the hadoop classpath into bash.
export HADOOP_CLASSPATH=$(hadoop classpath)
Make sure it is now exported.
echo $HADOOP_CLASSPATH
6. It is time to create these directories on HDFS rather than locally. Type the
following commands.
hadoop fs -mkdir /WordCount
hadoop fs -mkdir /WordCount/Input
hadoop fs -put Lab/Input/input.txt /WordCount/Input
7. Go to localhost:9870 from the browser, Open “Utilities → Browse File
System” and you should see the directories and files we placed in the
file system.
8. Then, back to local machine where we will compile the WordCount.java file.
Assuming we are currently in the Desktop directory.
cd Lab
javac -classpath $HADOOP_CLASSPATH -d classes WordCount.java
Put the output files in one jar file (There is a dot at the end). And execute below
command:
12
CMPN451 Big Data Analytics Lab 4 - MapReduce with Hadoop
Requirement:
13
CMPN451 Big Data Analytics Lab 4 - MapReduce with Hadoop
The data science team at Vodafone is analyzing the customers’ data which includes
the customer's personal information, the prepaid card they purchased, and the
timestamp they registered the prepaid amount on their Vodafone accounts, among
other information.
The details of the customers are omitted, and you are only provided with a file “in.csv”
which includes two columns.
1. Customer ID. (Each ID maps to a certain customer, whose data is hidden for
confidentiality).
2. Prepaid Card Amount.
Disclaimer: Thanks to the Vodafone DS team who provided us with this real customer
data.
14