<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Aditya Pal on Medium]]></title>
        <description><![CDATA[Stories by Aditya Pal on Medium]]></description>
        <link>https://medium.com/@aditya.pal?source=rss-51c4c0174d88------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*wubBWSQ5z-jRBhA6.</url>
            <title>Stories by Aditya Pal on Medium</title>
            <link>https://medium.com/@aditya.pal?source=rss-51c4c0174d88------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 06 Dec 2026 16:53:25 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@aditya.pal/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Setup a 3-node Hadoop-Spark-Hive cluster from scratch using Docker]]></title>
            <link>https://medium.com/@aditya.pal/setup-a-3-node-hadoop-spark-hive-cluster-from-scratch-using-docker-332dae6b98d0?source=rss-51c4c0174d88------2</link>
            <guid isPermaLink="false">https://medium.com/p/332dae6b98d0</guid>
            <category><![CDATA[hive]]></category>
            <category><![CDATA[hadoop]]></category>
            <category><![CDATA[docker]]></category>
            <category><![CDATA[spark]]></category>
            <dc:creator><![CDATA[Aditya Pal]]></dc:creator>
            <pubDate>Thu, 07 Mar 2019 17:53:08 GMT</pubDate>
            <atom:updated>2019-12-21T13:29:18.794Z</atom:updated>
            <content:encoded><![CDATA[<p>Hadoop is an open source distributed framework that manages data processing and storage for big data applications in clustered systems. Hadoop allows 3 different modes of installation :</p><ol><li><strong>Local (Standalone) Mode</strong> : Hadoop on a single machine using local filesystem as storage.</li><li><strong>Pseudo Distributed Mode</strong> : Hadoop mode in which Namenode and Datanode are on the same machine. It uses HDFS for file storage.</li><li><strong>Fully Distributed (Multi-node) Mode</strong> : Hadoop mode in which one machine is used as Master and one or more separate machines are used as workers. This mode offers fully distributed computing capability, reliability, fault tolerance and scalability.</li></ol><p>Installing hadoop in a local mode is not helpful (and half the fun!) to simulate the real challenges of configuring a multi-node cluster. To replicate a multi-node prod environment on a single PC, we have two major choices — <strong>Virtual Machines (VMs)</strong> and <strong>containers</strong>. A Virtual machine loads a full OS with its own memory management. Containers are however more efficient because there is no guest OS and they utilize a host’s operating system, share relevant libraries and resources as and when needed. Hence, Docker containers are a better choice for the setup. To setup docker in Debian based OS, use this <a href="https://askubuntu.com/questions/938700/how-do-i-install-docker-on-ubuntu-16-04-lts">link</a>. Once installed, make sure to run docker as a <a href="https://docs.docker.com/install/linux/linux-postinstall/">non-root user</a>.</p><p>There are a number of docker hub images that provide ready made hadoop namenode and datanode. In this article, I will share my approach of setting up a multi node hadoop cluster with spark and hive from scratch.</p><blockquote><strong>NOTE : </strong>I have tried to provide some of the reference links to articles/websites that have helped me in the setup. I have not added any code snippets here. You may want to reference <a href="https://github.com/sciencepal/dockers/tree/master/hadoop_hive_spark_docker">github.com/sciencepal/dockers/tree/master/hadoop_hive_spark_docker</a> while reading the article.</blockquote><p><strong>Architecture of the cluster :</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/801/1*VJXI20Vk37S323IECGQ7Ag.png" /></figure><blockquote>Docker network — hadoopnet</blockquote><blockquote>One Hadoop Master node — nodemaster</blockquote><blockquote>Two Hadoop Worker nodes — node2, node3</blockquote><blockquote>A PostgreSQL Hive Metastore (HMS)</blockquote><p><strong>Hadoop Setup</strong></p><p>I have used an ubuntu image as the base image of my Dockerfile. You may start with an OS of your choice like <a href="https://hub.docker.com/_/centos">CentOS</a>, <a href="https://hub.docker.com/r/richxsl/rhel7">RHEL</a> or <a href="https://hub.docker.com/_/fedora">Fedora</a>. First we need to get the prerequisite softwares for the hadoop installation :</p><blockquote>Java 8 (OpenJDK or Oracle JDK)</blockquote><blockquote>SSH (openssh-server)</blockquote><blockquote><a href="https://archive.apache.org/dist/hadoop/core/hadoop-3.2.0/hadoop-3.2.0.tar.gz">Hadoop 3.2.0 Binary</a></blockquote><p>Once these are downloaded and installed, we should create a separate user for the hadoop filesystem. Accessing hadoop via root is <a href="https://stackoverflow.com/questions/14785084/hdfs-start-all-sh-by-root-or-non-root-user">not recommended</a>. Next we need to configure SSH in the password-less configuration so that nodemaster and datanodes can log into each other without being asked a password every time. It can be done easily by <a href="https://www.tecmint.com/ssh-passwordless-login-using-ssh-keygen-in-5-easy-steps/">distributing <strong>SSH public keys</strong></a> to all the nodes. The default SSH port is 22 (it is <a href="https://www.tecmint.com/change-ssh-port-in-linux/">configurable</a>), hence the port should be opened on the Dockerfile before starting SSH.</p><p>We can now start with configuration of the hadoop nodes. These are some of the configurations needed :</p><ol><li><strong>Environment variables</strong> like JAVA_HOME and HADOOP_HOME should be set. You may also append their bin/sbin folder locations to the System Path for ease of access.</li><li><strong>hadoop-env.sh</strong> file contains the environment variables (like java, hadoop locations and namenode/datanode users) needed for hadoop scripts.</li><li>5 additional config files are used to run hadoop (Click each for details):</li></ol><blockquote>a. <a href="https://hadoop.apache.org/docs/r2.8.0/hadoop-project-dist/hadoop-common/core-default.xml"><strong>core-site.xml</strong></a> <strong>:</strong> This file informs Hadoop daemons where NameNode runs in the cluster. It contains the settings for Hadoop Core such as I/O settings.</blockquote><blockquote>b. <a href="https://hadoop.apache.org/docs/r2.4.1/hadoop-project-dist/hadoop-hdfs/hdfs-default.xml"><strong>hdfs-site.xml</strong></a><strong> : </strong>This file contains configuration settings for HDFS daemons such as specifying block replication factor and permission checking on HDFS.</blockquote><blockquote>c. <a href="https://hadoop.apache.org/docs/r2.7.2/hadoop-mapreduce-client/hadoop-mapreduce-client-core/mapred-default.xml"><strong>mapred-site.xml</strong></a><strong> : </strong>This file contains the configuration settings for MapReduce daemons. I have configured MapReduce framework as <a href="https://data-flair.training/blogs/hadoop-yarn-tutorial/">YARN</a>.</blockquote><blockquote>d. <a href="https://hadoop.apache.org/docs/r2.4.1/hadoop-yarn/hadoop-yarn-common/yarn-default.xml"><strong>yarn-site.xml</strong></a><strong> :</strong> This file specifies YARN configs such as location of logs and data, memory configs and number of CPU cores used by hadoop daemons.</blockquote><blockquote>e. <strong>workers : </strong>This file contains the list of datanode hostnames. <a href="https://stackoverflow.com/questions/51271404/hadoop-3-0-3-workers-file-vs-slaves">slaves file</a> was used in previous versions of hadoop.</blockquote><p>Besides the above, there are tons of <a href="https://hadoop.apache.org/docs/stable/hadoop-project-dist/hadoop-common/ClusterSetup.html">other</a> configurations which you can play with. Once the configs are set up, we need to change permissions of all the hadoop directories so that user hadoop can access them. As a final step, make sure that SSH runs after the Docker container starts. The CMD command available in Dockerfile does the trick.</p><p><strong>Spark setup</strong></p><p>We will add Spark to our cluster by installing it on the previously built hadoop Dockerfile. Apache Spark is an open-source lightning fast in-memory (10x — 100x faster than MapReduce) distributed cluster-computing framework. Spark uses Scala programming language, hence we need these binaries :</p><blockquote><a href="https://downloads.lightbend.com/scala/2.12.8/scala-2.12.8.tgz">Scala 2.12.8 Binary</a></blockquote><blockquote><a href="https://archive.apache.org/dist/spark/spark-2.4.0/spark-2.4.0-bin-without-hadoop.tgz">Spark 2.4.0 Binary</a></blockquote><p>Once the download and installation of Scala and Spark is done, we must perform the following spark configurations :</p><ol><li>Set the necessary <strong>environment variables</strong> like SCALA_HOME, SPARK_HOME etc. One observation that I came across was that SPARK_DIST_CLASSPATH as $(hadoop classpath) did not work with the ENV command, hence I needed to use the export command. Add spark bin location to System Path for easy access.</li><li>Necesssary environment variables must be appended in <a href="https://spark.apache.org/docs/latest/configuration.html"><strong>spark-env.sh</strong> file</a>.</li><li><a href="https://stackoverflow.com/questions/32001248/whats-the-difference-between-spark-eventlog-dir-and-spark-history-fs-logdirecto">Logging directories</a> and shuffling rules should be specified in <a href="https://spark.apache.org/docs/latest/configuration.html"><strong>spark-defaults.conf</strong></a> file.</li><li>The same workers file from the hadoop installation can be used as <strong>slaves</strong> file in spark conf directory.</li></ol><p>Finally, change permission of the spark directory so that user hadoop is able to access its contents.</p><p><strong>Hive Setup</strong></p><p><a href="https://github.com/apache/hive/blob/master/README.md">Apache Hive</a> is a data warehouse software built on top of Apache Hadoop that facilitates reading, writing, and managing large datasets residing in distributed storage using SQL.</p><p>Apache Hive requires a <a href="https://data-flair.training/blogs/apache-hive-metastore/"><strong>Hive metastore</strong></a><strong> (HMS)</strong> which is used to store metadata for Hive tables like their schema and location . HMS is implemented by using a relational database which can provide metadata storage (in local disk, not HDFS) and access. You may choose a database of your choice from MySQL, PostgreSQL, Oracle Database or MS SQL. I have chosen PostgreSQL.</p><p>Let us first create a Dockerfile for the HMS service. We can directly use <a href="https://hub.docker.com/_/postgres">postgreSQL </a>docker hub image (or <a href="https://hub.docker.com/_/mysql">MySQL</a>/<a href="https://hub.docker.com/_/oracle-database-enterprise-edition">Oracle DB</a>) as the start point of our image. Next we need to define the schema of hive tables in postgreSQL. Apache provides ready-made <a href="https://github.com/apache/hive/tree/master/metastore/scripts/upgrade">schemas</a> for supported databases. Specifically, for PostgreSQL (Hive Version 2.3.x) we need the following files :</p><blockquote><a href="https://github.com/apache/hive/blob/master/metastore/scripts/upgrade/postgres/hive-schema-2.3.0.postgres.sql">hive-schema-2.3.0.postgres.sql</a></blockquote><blockquote><a href="https://github.com/apache/hive/blob/master/metastore/scripts/upgrade/postgres/hive-txn-schema-2.3.0.postgres.sql">hive-txn-schema-2.3.0.postgres.sql</a></blockquote><p>Now, we need to create a script that initializes the HMS after PostgreSQL service starts. This script must create the metastore DB, a user and password (for accessing the DB via <a href="https://www.javatpoint.com/java-jdbc">JDBC</a>), and change the privileges of that user. Finally add the schema files to the database (just make sure to remove the last few lines of hive-schema-2.3.0.postgres.sql where the txn-schema is called.</p><p>Now that a metastore service is set up, we can start installing hive on our already built spark Dockerfile. We need the following softwares for install :</p><blockquote><a href="http://mirrors.estointernet.in/apache/hive/stable-2/apache-hive-2.3.4-bin.tar.gz">Hive 2.3.4 Binary</a> (There are newer versions, however this is stable)</blockquote><blockquote>libpostgresql-jdbc-java (From sources)</blockquote><p>After downloading and installing them, we can follow a similar approach of setting the environment variable (HIVE_HOME) and System Path. A few additional steps need to be implemented for Hive :</p><ol><li>Copy / Soft-link the <strong>postgres-jdbc4 jar</strong> from /usr/share/java folder to hive’s lib folder.</li><li>Append Hadoop Home environment variable to <strong>hive-env.sh</strong> and add it to hive’s bin folder.</li><li>Add the hive config file <strong>hive-site.xml</strong> to the conf folder. hive-site.xml must be edited to include these configs (at the least) — JDBC URL, username and password of the HMS DB, autoCreateSchema and schema verification must be set to false.</li></ol><p>Lastly, change permission of the hive folder to allow hadoop to access it. That’s it. We are all set to link these Dockerfiles together.</p><p><strong>Putting them all together !!</strong></p><p>Now, with the Dockerfiles ready, we will create two more scripts to build and manage our cluster : <strong>build.sh</strong> that will generate the ssh pubkeys and build the docker images, and <strong>cluster.sh</strong> that will be used to start/stop the processes of the cluster.</p><p><strong>build.sh</strong></p><p>This script will generate SSH keys and store them in configs directory (which will be distributed to the nodes during Docker build). We will then add the docker commands to build the hadoop, spark, HMS and hive images.</p><p><strong>cluster.sh</strong></p><p>This script will enable us to bring up/bring down the cluster services once the docker images are built. The following actions are needed to start services :</p><ol><li>Create a docker <strong>network</strong> and define the ip-range</li><li>Start <strong>nodemaster</strong> with defined network, ip, hostname and use add-host parameter to specify the datanodes. Remember to start the hive image (and not the spark image).</li><li>Start the <strong>datanodes</strong> with the spark image or hive image (if you want hive to be available on all nodes). Hive need not be installed on <a href="https://stackoverflow.com/questions/8456141/in-a-hadoop-cluster-should-hive-be-installed-on-all-nodes">all machines of the cluster</a>.</li><li>Start the <strong>PostgreSQL HMS</strong> container in the same network.</li><li><strong>Format</strong> the namenode.</li><li>Start all the <strong>services</strong> such as start-dfs, start-yarn, historyserver, spark master and workers, start-history-server.sh (spark)</li><li>Create <strong>hive metastore folder</strong> in HDFS and give it proper permissions.</li><li>Start the <strong>hive metastore service</strong>.</li></ol><p>Sorry for the awfully long post. If you have read the post, you can start implementing your own Hadoop-Spark-Hive cluster with these easy steps. This is my first Medium post. So, comment below if you find something worth sharing. Part 2 of this post will feature Hadoop, Spark and Hive examples on the cluster. Thank You !</p><p><strong>References</strong></p><p><a href="https://blog.newnius.com/how-to-quickly-setup-a-hadoop-cluster-in-docker.html#Start-Hadoop-Cluster">https://blog.newnius.com/how-to-quickly-setup-a-hadoop-cluster-in-docker.html#Start-Hadoop-Cluster</a></p><p><a href="https://medium.com/@rubenafo/some-tips-to-run-a-multi-node-hadoop-in-docker-9c7012dd4e26">https://medium.com/@rubenafo/some-tips-to-run-a-multi-node-hadoop-in-docker-9c7012dd4e26</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=332dae6b98d0" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>