Skip to main content

Hadoop / HBase and DNS


Hadoop and HBase (especially HBase) are very picky about DNS entries.  When setting  up a Hadoop cluster one doesn't always have access to a DNS server.  So  here is 'poor developers' guide to getting DNS correct.

Following these simple steps, can avoid a few thorny issues down the line.
set Hostname
verify hostname --> IP address resolution is working (DNS resolution)
verify IP address --> hostname resolution is working (reverse DNS)
DNS verification tool

1) HOSTNAME

I like to set these to FULLY QUALIFIED NAMES.
so ' hadoop1.lab.mycompany.com'   is good
just 'hadoop1'   is not.

on CENTOS
set this in  '/etc/sysconfig/network'
    HOSTNAME=hadoop1.lab.mycompany.com

on UBUNTU:
set this on '/etc/hostname'
      hadoop1.lab.mycompany.com

just reboot the host for hostname settings to take effect (to be safe)
Do this at every node.

2) DNS ENTRIES WHEN YOU DON'T HAVE DNS SERVER

So don't want to mess around (or can't) with DNS server?  No worries.  We can use   '/etc/hosts' file to make our own tiny DNS for our hadoop cluster

file : /etc/hosts
add the following *AFTER* the entries already present in /etc/hosts.

### hadoop cluster
# format
# ip_addres    fully_qualified_hostname     alias

10.1.1.101     hadoop1.lab.mycompna.com    hadoop1
10.1.1.102     hadoop2.lab.mycompny.com    hadoop2
# and so on....


Few things to note:
the content of this file has to be distributed across the cluster on all machines.  DO NOT copy the file onto target machines, the hadoop section needs to be APPENDED to /etc/hosts (see below for a quick script to do it)
the first entry is IP address (usually an internal IP address)
second entry is the FULLY QUALIFIED HOST NAME.   This makes sure reverse DNS lookup picks up the correct hostname
3rd entry is a shorthand alias;   It saves me some typing.  So I can just type 'ssh hadoop1'  rather than   'ssh  hadoop1.lab.mycompany.com'
One of common mistake that happens here is when host alias and fully qualified hostnames are swapped.
following isn't correct,
            10.1.1.101    hadoop1     hadoop1.lab.mycompany.com
aliases should follow, fully qualified host names.

The hadoop cluster section of /etc/hosts file has to be distributed on all cluster nodes.

HOW TO DISTRIBUTE THE DNS ENTRIES ACROSS THE CLUSTER?

There are  confguration managemnet systems (CMS) like Chef and Puppet that makes distributing config files on a cluster easy.   For a very large cluster, using  a CMS could be a recommended choice.

Here is a quick way to distribute the files:

If you have SSH password-less login setup between master and slaves, the following would work:

1) backup existing hosts file:  (do this only ONCE!)
run the following script with ROOT privileges

#!/bin/bash
hosts=$(cat $HADOOP_HOME/conf/slaves | grep -v '#')
for host in $hosts
do
    echo "------------------" $host "------------" 
    ssh -o StrictHostKeyChecking=no  root@$host "cp /etc/hosts  /etc/hosts.orig"
done


2) save the hadoop specific DNS entries into a file 

say 'hadoop_hosts' is our file that has the following content:
### hadoop cluster
10.1.1.101     hadoop1.lab.mycompna.com    hadoop1
10.1.1.102     hadoop2.lab.mycompny.com    hadoop2
# and so on....


3) run the following script;  it will copy the custom hosts files to destination and append it to the existing  /etc/hosts file

#!/bin/bash
hosts=$(cat $HADOOP_HOME/conf/slaves | grep -v '#')
for host in $hosts
do
    echo "------------------" $host "------------" 
    scp -o StrictHostKeyChecking=no  hadoop_hosts  $host:
    ssh -o StrictHostKeyChecking=no  root@$host "cat /etc/hosts.orig hadoop_hosts >> /etc/hosts"
done

CHECKING DNS ACROSS THE CLUSTER

Here is a simple Java utility  to verify that DNS is working ok in ALL cluster machines.  

Here are some features:

It is written in Java, so it will resolve hostnames just like Hadoop / Hbase would (or at least close enough)
It is written in pure Java, doesn't use any third party libraries.  So it is very easy to compile and run.  If you are running Hadoop, you already have JDK installed anyway
it does both   IP lookup and reverse DNS lookup
will also check if machine's own hostname resolves correctly
it can run on a single machine 
it can run on machines across cluster (as long as passsword-less ssh is enabled)
To run this, say from hadoop master:
get the code (using git : git clone  git@github.com:sujee/hadoop-dns-checker.git)
compile:  ./compile.sh    it should create a jar file 'a.jar'
create a hosts file ('my_hosts')  containing all machines in your hadoop cluster:
hadoop1.domain.com
hadoop2.domain.com
hadoop3.domain.com
first run this in a single machine mode:
./run.sh   my_hosts
here is a sample output:

==== Running on : c2107.pcs.hds.com/172.17.34.99 =====
# self check...
-- host : c2107.pcs.hds.com
   host lookup : success (172.17.34.99)
   reverse lookup : success (c2107.pcs.hds.com)
   is reachable : yes
# end self check

-- host : c2107.pcs.hds.com
   host lookup : success (172.17.34.99)
   reverse lookup : success (c2107.pcs.hds.com)
   is reachable : yes

-- host : c2108.pcs.hds.com
   host lookup : success (172.17.34.100)
   reverse lookup : success (c2108.pcs.hds.com)
   is reachable : yes

great.  Now we can run this on cluster.  It will login to each machine specified in 'hosts' file, and run this script.
./run-on-cluster.sh hosts2
if any error is encountered it will print out '*** FAIL *** '.  So it is easy to spot any errors

Comments

Popular posts from this blog

Python and Parquet Performance

In Pandas, PyArrow, fastparquet, AWS Data Wrangler, PySpark and Dask. This post outlines how to use all common Python libraries to read and write Parquet format while taking advantage of  columnar storage ,  columnar compression  and  data partitioning . Used together, these three optimizations can dramatically accelerate I/O for your Python applications compared to CSV, JSON, HDF or other row-based formats. Parquet makes applications possible that are simply impossible using a text format like JSON or CSV. Introduction I have recently gotten more familiar with how to work with  Parquet  datasets across the six major tools used to read and write from Parquet in the Python ecosystem:  Pandas ,  PyArrow ,  fastparquet ,  AWS Data Wrangler ,  PySpark  and  Dask . My work of late in algorithmic trading involves switching between these tools a lot and as I said I often mix up the APIs. I use Pandas and PyArrow for in-RAM comput...

Kubernetes Configuration Provider to load data from Secrets and Config Maps

Using Kubernetes Configuration Provider to load data from Secrets and Config Maps When running Apache Kafka on Kubernetes, you will sooner or later probably need to use Config Maps or Secrets. Either to store something in them, or load them into your Kafka configuration. That is true regardless of whether you use Strimzi to manage your Apache Kafka cluster or something else. Kubernetes has its own way of using Secrets and Config Maps from Pods. But they might not be always sufficient. That is why in Strimzi, we created Kubernetes Configuration Provider for Apache Kafka which we will introduce in this blog post. Usually, when you need to use data from a Config Map or Secret in your Pod, you will either mount it as volume or map it to an environment variable. Both methods are configured in the spec section or the Pod resource or in the spec.template.spec section when using higher level resources such as Deployments or StatefulSets. When mounted as a volume, the contents of the Secr...

Andriod Bug

A bug that steals cash by racking up charges from sending premium rate text messages has been found in Google Play.  Security researchers have identified 32 apps on Google Play that harbour the bug called BadNews. A security firm Lookout, which uncovered BadNews, said that the malicious program lays dormant on handsets for weeks to escape detection.  The malware targeted Android owners in Russia, Ukraine, Belarus and other countries in eastern Europe. 32 apps were available through four separate developer accounts on Google Play. Google has now suspended those accounts and it has pulled all the affected apps from Google Play, it added. Half of the 32 apps seeded with BadNews are Russian and the version of AlphaSMS it installed is tuned to use premium rate numbers in Russia, Ukraine, Belarus, Armenia and Kazakhstan.