CentOS 7
Sponsored Link

Install Apache Hadoop
2015/07/28
 
Install Apache Hadoop to build Distributed File System.
This example is based on the environment below.
1) dlp.srv.world (Master Node)
2) node01.srv.world (Slave Node)
3) node02.srv.world (Slave Node)
[1]
[2] Create a user for Hadoop on all Nodes.
[[email protected] ~]#
useradd -d /usr/hadoop hadoop

[[email protected] ~]#
chmod 755 /usr/hadoop

[[email protected] ~]#
passwd hadoop

Changing password for user hadoop.
New password:
Retype new password:
passwd: all authentication tokens updated successfully.
[3] Login as hadoop user to Master Node and create SSH key-pair (no-passphrase) and send it to other nodes.
[[email protected] ~]$
ssh-keygen

Generating public/private rsa key pair.
Enter file in which to save the key (/usr/hadoop/.ssh/id_rsa):
Created directory '/usr/hadoop/.ssh'.
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /usr/hadoop/.ssh/id_rsa.
Your public key has been saved in /usr/hadoop/.ssh/id_rsa.pub.
The key fingerprint is:
xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx [email protected]
The key's randomart image is:
# send key to nodes included localhost

[[email protected] ~]$
ssh-copy-id localhost

The authenticity of host 'localhost (::1)' can't be established.
ECDSA key fingerprint is xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx.
Are you sure you want to continue connecting (yes/no)?
yes

/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed
/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed -- if you are prompted now it is to install the new keys
[email protected]'s password:

Number of key(s) added: 1

Now try logging into the machine, with:   "ssh 'localhost'"
and check to make sure that only the key(s) you wanted were added.

[[email protected] ~]$
ssh-copy-id node01.srv.world

[[email protected] ~]$
ssh-copy-id node02.srv.world

[4] Install Hadoop on all Nodes. Work as hadoop user.
Make sure the latest version of Hadoop on the site below before downloading.
⇒ https://hadoop.apache.org/releases.html
[[email protected] ~]$
curl -O http://ftp.jaist.ac.jp/pub/apache/hadoop/common/hadoop-2.7.1/hadoop-2.7.1.tar.gz

[[email protected] ~]$
tar zxvf hadoop-2.7.1.tar.gz -C /usr/hadoop --strip-components 1

[[email protected] ~]$
vi ~/.bash_profile
# add follows to the end

export HADOOP_HOME=/usr/hadoop
export HADOOP_COMMON_HOME=$HADOOP_HOME
export HADOOP_HDFS_HOME=$HADOOP_HOME
export HADOOP_MAPRED_HOME=$HADOOP_HOME
export HADOOP_YARN_HOME=$HADOOP_HOME
export HADOOP_OPTS="-Djava.library.path=$HADOOP_HOME/lib/native"
export HADOOP_COMMON_LIB_NATIVE_DIR=$HADOOP_HOME/lib/native
export PATH=$PATH:$HADOOP_HOME/sbin:$HADOOP_HOME/bin
[had[email protected] ~]$
source ~/.bash_profile

[5] Configure Hadoop on Master Node. Work as hadoop user.
# create directory for data on all nodes.

[[email protected] ~]$
mkdir ~/datanode

[[email protected] ~]$
ssh node01.srv.world "mkdir ~/datanode"

[[email protected] ~]$
ssh node02.srv.world "mkdir ~/datanode"
[[email protected] ~]$
vi ~/etc/hadoop/hdfs-site.xml
# add into <configuration> - </configuration> section

<configuration>
  <property>
    <name>dfs.replication</name>
    <value>2</value>
  </property>
  <property>
    <name>dfs.datanode.data.dir</name>
    <value>file:///usr/hadoop/datanode</value>
  </property>
</configuration>
# send to slaves

[[email protected] ~]$
scp ~/etc/hadoop/hdfs-site.xml node01.srv.world:~/etc/hadoop/

[[email protected] ~]$
scp ~/etc/hadoop/hdfs-site.xml node02.srv.world:~/etc/hadoop/

[[email protected] ~]$
vi ~/etc/hadoop/core-site.xml
# add into <configuration> - </configuration> section

<configuration>
  <property>
    <name>fs.defaultFS</name>
    <value>hdfs://dlp.srv.world:9000/</value>
  </property>
</configuration>
# send to slaves

[[email protected] ~]$
scp ~/etc/hadoop/core-site.xml node01.srv.world:~/etc/hadoop/

[[email protected] ~]$
scp ~/etc/hadoop/core-site.xml node02.srv.world:~/etc/hadoop/

[[email protected] ~]$
sed -i -e 's/\${JAVA_HOME}/\/usr\/java\/default/' ~/etc/hadoop/hadoop-env.sh

# send to slaves

[[email protected] ~]$
scp ~/etc/hadoop/hadoop-env.sh node01.srv.world:~/etc/hadoop/

[[email protected] ~]$
scp ~/etc/hadoop/hadoop-env.sh node02.srv.world:~/etc/hadoop/
[[email protected] ~]$
mkdir ~/namenode

[[email protected] ~]$
vi ~/etc/hadoop/hdfs-site.xml
# add into <configuration> - </configuration> section

<configuration>
  <property>
    <name>dfs.namenode.name.dir</name>
    <value>file:///usr/hadoop/namenode</value>
  </property>
</configuration>
[[email protected] ~]$
vi ~/etc/hadoop/mapred-site.xml
# create new

<configuration>
  <property>
    <name>mapreduce.framework.name</name>
    <value>yarn</value>
  </property>
</configuration>
[[email protected] ~]$
vi ~/etc/hadoop/yarn-site.xml
# add into <configuration> - </configuration> section

<configuration>
  <property>
    <name>yarn.resourcemanager.hostname</name>
    <value>dlp.srv.world</value>
  </property>
  <property>
    <name>yarn.nodemanager.hostname</name>
    <value>dlp.srv.world</value>
  </property>
  <property>
    <name>yarn.nodemanager.aux-services</name>
    <value>mapreduce_shuffle</value>
  </property>
</configuration>
[[email protected] ~]$
vi ~/etc/hadoop/slaves
# add all nodes (remove localhost)

dlp.srv.world
node01.srv.world
node02.srv.world
[6] Format NameNode and start Hadoop services.
[[email protected] ~]$
hdfs namenode -format

15/07/28 19:58:14 INFO namenode.NameNode: STARTUP_MSG:
/************************************************************
STARTUP_MSG: Starting NameNode
STARTUP_MSG:   host = dlp.srv.world/10.0.0.30
STARTUP_MSG:   args = [-format]
STARTUP_MSG:   version = 2.7.1
.....
.....
15/07/28 19:58:17 INFO namenode.NameNode: SHUTDOWN_MSG:
/************************************************************
SHUTDOWN_MSG: Shutting down NameNode at dlp.srv.world/10.0.0.30
************************************************************/

[[email protected] ~]$
start-dfs.sh

Starting namenodes on [dlp.srv.world]
dlp.srv.world: starting namenode, logging to /usr/hadoop/logs/hadoop-hadoop-namenode-dlp.srv.world.out
dlp.srv.world: starting datanode, logging to /usr/hadoop/logs/hadoop-hadoop-datanode-dlp.srv.world.out
node02.srv.world: starting datanode, logging to /usr/hadoop/logs/hadoop-hadoop-datanode-node02.srv.world.out
node01.srv.world: starting datanode, logging to /usr/hadoop/logs/hadoop-hadoop-datanode-node01.srv.world.out
Starting secondary namenodes [0.0.0.0]
0.0.0.0: starting secondarynamenode, logging to /usr/hadoop/logs/hadoop-hadoop-secondarynamenode-dlp.srv.world.out

[[email protected] ~]$
start-yarn.sh

starting yarn daemons
starting resourcemanager, logging to /usr/hadoop/logs/yarn-hadoop-resourcemanager-dlp.srv.world.out
dlp.srv.world: starting nodemanager, logging to /usr/hadoop/logs/yarn-hadoop-nodemanager-dlp.srv.world.out
node02.srv.world: starting nodemanager, logging to /usr/hadoop/logs/yarn-hadoop-nodemanager-node02.srv.world.out
node01.srv.world: starting nodemanager, logging to /usr/hadoop/logs/yarn-hadoop-nodemanager-node01.srv.world.out

# show status (it's OK if result is like follows)

[[email protected] ~]$
jps

2130 NameNode
2437 SecondaryNameNode
2598 ResourceManager
2710 NodeManager
3001 Jps
2267 DataNode
[7] Execute a sample program to make sure it works normally.
# create a directory

[[email protected] ~]$
hdfs dfs -mkdir /test
# copy a local file to /test

[[email protected] ~]$
hdfs dfs -copyFromLocal ~/NOTICE.txt /test
# show contents of a file

[[email protected] ~]$
hdfs dfs -cat /test/NOTICE.txt

This product includes software developed by The Apache Software
Foundation (http://www.apache.org/).

# execute a sample program

[[email protected] ~]$
hadoop jar ~/share/hadoop/mapreduce/hadoop-mapreduce-examples-2.7.1.jar wordcount /test/NOTICE.txt /output01

15/07/28 19:28:47 INFO client.RMProxy: Connecting to ResourceManager at dlp.srv.world/10.0.0.30:8032
15/07/28 19:28:48 INFO input.FileInputFormat: Total input paths to process : 1
15/07/28 19:28:48 INFO mapreduce.JobSubmitter: number of splits:1
.....
.....

# show results

[[email protected] ~]$
hdfs dfs -ls /output01

Found 2 items
-rw-r--r--   2 hadoop supergroup      0 2015-07-29 14:29 /output01/_SUCCESS
-rw-r--r--   2 hadoop supergroup    123 2015-07-29 14:29 /output01/part-r-00000

# show contents of a file of results (wordcounts is generated)

[[email protected] ~]$
hdfs dfs -cat /output01/part-r-00000

(http://www.apache.org/).       1
Apache          1
Foundation      1
Software        1
The             1
This            1
by              1
developed       1
includes        1
product         1
software        1
[8] Access to "http://(server's hostname or IP address):50070/", then it's possbile to see Hadoop cluster's summary.
[9] Access to http://(server's hostname or IP address):8088/", then then it's possbile to see Hadoop cluster's information.