Hadoop Configuration

  • Hadoop use a collection of configuration properties and values
  • Configurations can be either defined in XML files (offline), or defined in programs (online)
    • Resources are XML files that define properties/values
  • XML format with name, value, description (optional):
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    <?xml version="1.0"?>
    <configuration>
    <property>
    <name>size</name>
    <value>12</value>
    <description>This is Size</description>
    </property>
    <property>
    <name>weight</name>
    <value>light</value>
    <!-- Cannot be overridden -->
    <final>true</final>
    </property>
    </configuration>
    Notice: Properties that are marked final cannot be overridden in later definitions
  • Add the resources in the program:
    1
    2
    3
    Configuration conf = new Configuration();
    conf.addResource("configuration-1.xml");
    conf.addResource("configuration-2.xml");

Configuration Files

Filename Description
core-site Configuration settings for Hadoop Core, such as I/O settings that are common to HDFS and MapReduce
hdfs-site Configuration settings for Hadoop Core, such as I/O settings that are common to HDFS, MapReduce, and YARN
mapred-site Configuration settings for MapReduce daemons: the job history server
yarn-site Configuration settings for YARN daemons: the resource manager, the web app proxy server, and the node managers

Setup

Create VMs

  • Set up 4 virtual machine instances in Google Cloud Platform using Ubuntu 20.04 LTS Operating system and 100GB balanced persistent disks with names vm-1, datanode-1, datanode-2, datanode-3

Create Users

  • For all instances, create a user named mhlam:
    sudo -i
    adduser mhlam (pwd=mhlam)

  • Advise the sshd configuration:
    vi /etc/ssh/sshd_config

    1
    2
    PasswordAuthentication yes
    ChallengeResponseAuthentication yes

    service sshd restart

  • Connect the instances:
    vi /etc/hosts

    1
    2
    3
    4
    10.128.0.2 namnode-1.us-central1-c.c.rare-bloom-398805.internal vm-1
    10.128.0.3 datanode-2.us-central1-c.c.rare-bloom-398805.internal datanode-2
    10.128.0.4 datanode-1.us-central1-c.c.rare-bloom-398805.internal datanode-1
    10.128.0.5 datanode-3.us-central1-c.c.rare-bloom-398805.internal datanode-3

10.138.0.23 vm-1.us-west1-b.c.nomadic-vine-412514.internal vm-1
10.138.0.24 datanode-2.us-west1-b.c.nomadic-vine-412514.internal datanode-2
10.138.0.25 datanode-3.us-west1-b.c.nomadic-vine-412514.internal datanode-3
10.138.0.26 datanode-4.us-west1-b.c.nomadic-vine-412514.internal datanode-4

10.182.0.50 vm-1.us-west4-b.c.nomadic-vine-412514.internal vm-1
10.182.0.51 vm-2.us-west4-b.c.nomadic-vine-412514.internal vm-2
10.182.0.52 vm-3.us-west4-b.c.nomadic-vine-412514.internal vm-3
10.182.0.53 vm-4.us-west4-b.c.nomadic-vine-412514.internal vm-4

Generate ssh key

  • Setup a ssh connection in Master instance:
    su mhlam
    cd ~
    ssh-keygen -t rsa -P ""

  • Copy the ssh id to the Worker instances:
    ssh-copy-id -i /home/mhlam/.ssh/id_rsa.pub mhlam@datanode-1
    ssh-copy-id -i /home/mhlam/.ssh/id_rsa.pub mhlam@datanode-2
    ssh-copy-id -i /home/mhlam/.ssh/id_rsa.pub mhlam@datanode-3
    ssh-copy-id -i /home/mhlam/.ssh/id_rsa.pub mhlam@vm-1

ssh-copy-id -i /home/mhlam/.ssh/id_rsa.pub mhlam@vm-1

  • Authorize:
    chmod 0600 ~/.ssh/authorized_keys

Hadoop and Java Installation

  1. Install Hadoop:

    1
    2
    3
    4
    cd /opt/
    wget https://archive.apache.org/dist/hadoop/core/hadoop-2.9.2/hadoop-2.9.2.tar.gz
    tar zxf hadoop-2.9.2.tar.gz
    mv hadoop-2.9.2 /usr/local/hadoop
  2. Install Java:

    1
    2
    3
    4
    5
    6
    wget --no-cookies --no-check-certificate --header "Cookie: gpw_e24=http%3A%2F%2Fwww.oracle.com%2F; oraclelicense=accept-securebackup-cookie" http://download.oracle.com/otn-pub/java/jdk/8u131-b11/d54c1d3a095b4ff2b6607d096fa80163/jdk-8u131-linux-x64.tar.gz
    tar xzf jdk-8u131-linux-x64.tar.gz
    cd /opt/jdk1.8.0_131
    update-alternatives --install /usr/bin/java java /opt/jdk1.8.0_131/bin/java 2
    update-alternatives --config java
    java -version

sudo apt update
sudo apt install openjdk-8-jdk -y

  • Openjdk8 (/usr/lib/jvm/java-8-openjdk-amd64)

Configure Hadoop

Do the cofiguration in the Master instance

  1. Make directory:
    1
    2
    3
    4
    5
    6
    chown -R mhlam:mhlam /usr/local/hadoop
    mkdir -p /usr/local/hadoop_store/tmp
    mkdir -p /usr/local/hadoop_store/hdfs/namenode
    mkdir -p /usr/local/hadoop_store/hdfs/datanode
    mkdir -p /usr/local/hadoop_store/hdfs/secondarynamenode
    chown -R mhlam:mhlam /usr/local/hadoop_store

su mhlam

  1. Configuate hdfs-site.xml:
    vi /usr/local/hadoop/etc/hadoop/hdfs-site.xml

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    <configuration>
    <property>
    <name>dfs.replication</name>
    <value>3</value>
    <description>Default block replication.
    The actual number of replications can be specified when the file is created. The default is used if replication is not specified in create time. </description>
    </property>
    <property>
    <name>dfs.namenode.name.dir</name>
    <value>file:/usr/local/hadoop_store/hdfs/namenode</value>
    </property>
    <property>
    <name>dfs.datanode.data.dir</name>
    <value>file:/usr/local/hadoop_store/hdfs/datanode</value>
    </property>
    <property>
    <name>dfs.namenode.checkpoint.dir</name>
    <value>file:/usr/local/hadoop_store/hdfs/secondarynamenode</value>
    </property>
    <property>
    <name>dfs.namenode.checkpoint.period</name>
    <value>3600</value>
    </property>
    </configuration>
  2. Configuate core-site.xml:
    vi /usr/local/hadoop/etc/hadoop/core-site.xml

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    <configuration>
    <property>
    <name>hadoop.tmp.dir</name>
    <value>/usr/local/hadoop_store/tmp</value>
    <description>A base for other temporary directories.</description>
    </property>
    <property>
    <name>fs.default.name</name>
    <value>hdfs://vm-1:54310</value>
    <description>The name of the default file system. A URI whose scheme and authority determine the FileSystem implementation. The uri's scheme determines the config property fs.SCHEME.impl) naming the FileSystem implementation class. The uri's authority is used to determine the host, port, etc. for a filesystem.</description>
    </property>
    </configuration>
  3. Configuate mapred-site.xml:
    vi /usr/local/hadoop/etc/hadoop/mapred-site.xml

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    <configuration>
    <property>
    <name>mapreduce.framework.name</name>
    <value>yarn</value>
    </property>
    <property>
    <name>mapred.job.tracker</name>
    <value>vm-1:54311</value>
    <description>The host and port that the MapReduce job tracker runs at. If "local", then jobs are run in-process as a single mapand reduce task.</description>
    </property>
    </configuration>
  4. Configuate yarn-site.xml:
    vi /usr/local/hadoop/etc/hadoop/yarn-site.xml

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    <configuration>
    <property>
    <name>yarn.resourcemanager.hostname</name>
    <value>vm-1</value>
    </property>
    <property>
    <name>yarn.nodemanager.aux-services</name>
    <value>mapreduce_shuffle</value>
    </property>
    <property>
    <name>yarn.nodemanager.aux-services.mapreduce.shuffle.class</name>
    <value>org.apache.hadoop.mapred.ShuffleHandler</value>
    </property>
    </configuration>
  5. Add java path in hadoop-env.sh file:
    echo 'export JAVA_HOME=/opt/jdk1.8.0_131' >> /usr/local/hadoop/etc/hadoop/hadoop-env.sh
    echo 'export JAVA_HOME=/usr/lib/jvm/java-8-openjdk-amd64' >> /usr/local/hadoop/etc/hadoop/hadoop-env.sh (openjdk-8-jdk)

  6. add hadoop and java path in the .bashrc file:
    vi /home/mhlam/.bashrc

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    export HADOOP_PREFIX=/usr/local/hadoop
    export HADOOP_HOME=/usr/local/hadoop
    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_CONF_DIR=${HADOOP_HOME}/etc/hadoop
    # Native Path
    export HADOOP_COMMON_LIB_NATIVE_DIR=${HADOOP_PREFIX}/lib/native
    export HADOOP_OPTS="-Djava.library.path=$HADOOP_PREFIX/lib"
    export PATH=$PATH:$HADOOP_HOME/bin:$HADOOP_HOME/sbin
    export JAVA_HOME=/usr/lib/jvm/java-8-openjdk-amd64
    export JRE_HOME=/usr/lib/jvm/java-8-openjdk-amd64/jre
    export PATH=$PATH:/usr/lib/jvm/java-8-openjdk-amd64/bin:/usr/lib/jvm/java-8-openjdk-amd64jre/bin

    source ~/.bashrc

Copy to Workers and Setup

  1. Copy Java:
    su mhlam
    cd /opt/
    scp jdk-8u131-linux-x64.tar.gz vm-1:/home/mhlam/
    scp jdk-8u131-linux-x64.tar.gz vm-2:/home/mhlam/
    scp jdk-8u131-linux-x64.tar.gz vm-3:/home/mhlam/

  2. Copy hadoop:

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    cd /usr/local
    scp -r hadoop vm-2:/home/mhlam/
    scp -r hadoop_store vm-2:/home/mhlam/
    scp -r /home/mhlam/.bashrc vm-2:/home/mhlam/

    scp -r hadoop vm-3:/home/mhlam/
    scp -r hadoop_store vm-3:/home/mhlam/
    scp -r /home/mhlam/.bashrc vm-3:/home/mhlam/

    scp -r hadoop vm-4:/home/mhlam/
    scp -r hadoop_store vm-4:/home/mhlam/
    scp -r /home/mhlam/.bashrc vm-4:/home/mhlam/

Setup Hadoop and Java in Workers

  1. Move folders:
    sudo -i

    1
    2
    3
    4
    5
    mv /home/mhlam/jdk-8u131-linux-x64.tar.gz /opt/
    mv /home/mhlam/hadoop /usr/local/
    mv /home/mhlam/hadoop_store /usr/local/
    chown -R mhlam:mhlam /usr/local/hadoop
    chown -R mhlam:mhlam /usr/local/hadoop_store
  2. Setup Java:

    1
    2
    3
    4
    5
    cd /opt
    tar xzf jdk-8u131-linux-x64.tar.gz
    cd jdk1.8.0_131
    update-alternatives --install /usr/bin/java java /opt/jdk1.8.0_131/bin/java 2
    update-alternatives --config java

Format namenode and start all Hadoop services (namenode)

  1. Setup datanode:
    vi /usr/local/hadoop/etc/hadoop/slaves

    1
    2
    3
    4
    vm-1
    datanode-1
    datanode-2
    datanode-3
  2. Format namenode:
    su mhlam
    hadoop namenode -format

  3. Start storage and yarn services:
    start-dfs.sh
    start-yarn.sh

Reference

  1. Hadoop multi-node cluster setup in Google cloud platform (Video)

./bin/docker-image-tool.sh -r docker.io/manholam8 -t mhlam build
./bin/docker-image-tool.sh -r manholam8 -t mhlam push