HortonWorks (HDP) - Hadoop Cluster Installation steps


Steps to Install Hortonworks (HDP) - Hadoop cluster

(with continution to my previous post)

Hortonworks

  -- Install Ambari-Server          
    -- WebUI of Ambari
     * Install and configure all the ecosystem components and services
    -- HDP ( Hortonworks distribution of Hadoop)
     Note: need fully qualified domain name (fqdn) of all the hosts
-----------------------------------------------

What is Ambari ?

Ambari enables Hadoop Administrators to:

Provision the Hadoop Cluster

  * Ambari provides a step-by-step wizard for installing Hadoop services across any number of hosts.
  * Ambari handles configuration of Hadoop services for the cluster.

Manage the Hadoop Cluster

  * Ambari provides central management for starting, stopping, and reconfiguring Hadoop services across the entire cluster.

Monitor the Hadoop Cluster

  * Ambari provides a dashboard for monitoring health and status of the Hadoop cluster.

--------------------------------------------------------------------------------------------


AMBARI :

 * components of ambari

  - ambari-server
  - ambari-agent

 Step1: Installing Ambari-server and Ambari-agent:

(Add ambari repositories to ubuntu repositories)
        * sudo apt-get -y update
* cd /etc/apt/sources.list.d
* sudo wget http://public-repo-1.hortonworks.com/ambari/ubuntu12/2.x/updates/2.1.2/ambari.list
* sudo apt-key adv --recv-keys --keyserver keyserver.ubuntu.com B9733A7A07513CAD
* sudo apt-key adv --recv-keys --keyserver hkp://keyserver.ubuntu.com:80 B9733A7A07513CAD
* sudo apt-get -y update
        * sudo apt-get -y install ambari-server
* sudo apt-get -y install ambari-agent

Note: dependencies for ambari-server
       -- python (all the scripts to cluster installation is in python)
   -- postgress sql (ambari based configurations would be saved in postgress)
   ( both would be installed automatically, if not there)
 

Step 2: Setup ambari-server.

     * sudo ambari-server setup
      (custom configurations on username, passwords for ambari, java version to be used)
 
or

     * sudo ambari-server setup -s
      (default configuration on username, passwords for ambari, java version to be used)
       default username : admin 
       default password : admin

Check the Ambari server status:

     * sudo ambari-server status
     * sudo ambari-agent status

If the services are not running, Start the ambari-server and ambari-agent
     * sudo ambari-server start
     * sudo ambari-agent start
 
note: start ambari-agent in all machines which are needed to create the Hadoop cluster.

Check: once ambari-server is running, check in UI on 8080 port.
 
Ambari UI  :  http://<hostIP>:8080
      username: admin
      password: admin

Then, you can create and deploy the Hadoop cluster through the AMBARI UI.
 
   

Problems associated with self managed Apache Hadoop cluster

Problems associated with self managed Apache Hadoop cluster


Below are the few points which we need to consider while building a self managed Apache Hadoop cluster.

Ensure password less SSH connectivity between all machines

   -- If 5 node cluster .. add private keys of all machines to each other

Install Hadoop Component in all 5 machines

   b. Configure masters and slaves among 5 machines
   c. Make sure, proper path is given to namenode and datanodes to store the meatdata & blocks respectively.

Cluster Scalablity  -- scaling up/scaling down

   Commisioning and Decommisioning
   steps: Commisioning
     -- stop cluster
-- install hadoop in new machine & edit configs 
-- add machine ips/hosts in slaves file
-- start the cluster
   steps: DeCommisioning 
    -- do a LoadBalancer/ decomissioning script
    -- stop cluster
-- remove machine ips/hosts in slaves file
-- start the cluster


IMPORTANT: Make sure all the masters and slaves in cluster are sync with same time. Use, network time (ntpd) to synchronize the time

While installing other ecosystem components (hive, Sqoop, etc.,)to cluster:

    -- ensure Port connections
-- proper firewall settings (inbound/outbound rules)
-- every service of other components should be able to interact with other services
-- Components version matching

Starting and stopping different component services in different machines manually.


Monitoring the services / Service metrics / health checkup



To overcome these problems, we choose any Hadoop distributions like Cloudera, Hortonworks or MapR to build and manage the Hadoop cluster.

Here are the installation steps for common Apache Hadoop Distributions.


Cloudera

  -- Install Cloudera Manager           
    -- WebUI of cloudera manager 
     * Install and configure all the ecosystem components and services
-- CDH ( cloudera distribution of hadoop)  can be installed through cloudera manager UI

Hortonworks

  -- Install Ambari-Server          
    -- WebUI of Ambari
     * Install and configure all the ecosystem components and services
-- HDP ( Hortonworks distribution of hadoop)  
note: need fully qualified domain name...
Important: Add the hostnames and fqdn in machine where you access ambari server through UI.

Follow my next post in the below link to get Hortonworks cluster installation steps.

Hortonworks Cluster Installation steps

BlockChain Network validation concept using simple Java program.


# Understanding the BlockChain Network validation concept using simple Java program.


With the continuation of my previous post,

Understanding BlockChain using simple Java Program (It explains the working of block chain network in a simple and easy way using java program)


Here is my another article to understand , why the block chain network is difficult to hack or modify the content of block data.

Added the demonstration (in BlockChainNetwork.java) for validating Block Chain network
Also, demonstrated what happens, if the data is tampered in any block.

note:  below are some of the conditions to validate the blockchain network
1.The hash of current block is valid.
2.The hash of current block is equal to the previous hash of succeeded block.

So, If the data is tampered in any block
  * The hash becomes invalid, this in turn makes the network invalid
  * Even if the hash is updated, it is difficult to update the same in previous hash of every succeeded block.
      (can be tried if the intruder have the compute power more than 50 % of peers in the block chain network.. definitely not possible.. 😝 😝!!!.. so make your hashing algorithm stronger..)

BlockChain Network Validation Concept:

------------------------------------------------------------------------------------------------------

public String isBlockChainNetworkValid(List<Block> blockChainNetwork){
Block currentBlock=null;
Block previousBlock=null;
String message="";
for(int i=1;i<blockChainNetwork.size();i++){
currentBlock = (Block) blockChainNetwork.toArray()[i];
previousBlock = (Block) blockChainNetwork.toArray()[i-1];
if(currentBlock.getCurrentBlockHash().equals(currentBlock.calculateHash(currentBlock.getBlockData()))){
if(currentBlock.getPreviousBlockHash().equals(previousBlock.getCurrentBlockHash())){
message = "Valid";
}
else{
message = "Invalid...\n Because the previous hash of block index : "+currentBlock.getIndex()+" is not equal to hash of block index "+previousBlock.getIndex();
break;
}
}  
else{
message = "Invalid... \n Because the hash of block index : "+currentBlock.getIndex()+ " is not valid. The data might have been tampered..!!"
+"\n The actual valid hash is : "+currentBlock.calculateHash(currentBlock.getBlockData())
+"\n But the available hash in network is : "+currentBlock.getCurrentBlockHash();
     break;
}
}
return message;
}
-------------------------------------------------------------------------------------------------------------------------

**** Introducing nonce and proof of work…… [ follow the next posts !!! ]
 
Hence, Block Chain becomes secure..! It is quite difficult to hack & update the data in any block and make it valid without the peer's concern.

Sample output of validation code is also attached..(closely monitor the previousHash & currentHash of each block)

So, the Questions arise of

  • What if the data is tampered & hash is updated in the last block of network. Since, the last block in the network doesn’t have any succeeded block to check the previous hash
Get the complete source code here,


**** Introducing cryptographic nonce and proof of work in my upcoming post.

Understanding Block Chain Concept using Simple Java Program


# Are you a Block Chain geek ?



The Block Chain is a decentralized and distributed digital ledger that is used to record transactions across many computers so that the record cannot be altered retroactively without the alteration of all subsequent blocks and the collusion of the network.

Here is the easy way of understanding Block Chain concept using a simple java program for you.

A Java program to understand the simple BLOCKCHAIN network.

( how blocks are added with previous hash & current hash)

---------------- BlockChainNetwork.java ------------------------------------------------------

package com.dharani.blockchain.simplenetwork;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.LinkedHashSet;
import java.util.Set;

public class BlockChainNetwork {

public static Set <Block> blockChain;
public BlockChainNetwork() {
blockChain = new LinkedHashSet<Block>();
blockChain.add(createTheGenesisBlock());
}
    
public Block createTheGenesisBlock(){
// The Genesis block is the first block created while creating the blockchain network.
String timestamp =new SimpleDateFormat("MMM dd,yyyy HH:mm:ss.SSS").format(new Date());
int index=0;
String previousHash="null"; // consider previous hash of Genesis block is zero
String data = "This is the Genesis Block";
return new Block(index,timestamp,previousHash,data);
}
public Block getTheLatestBlock(){
return (Block) blockChain.toArray()[blockChain.size()-1]; 
}
public void addNewBlock(Block newBlock){
Block latestBlock = getTheLatestBlock();
newBlock.setIndex(latestBlock.getIndex()+1);
newBlock.setTimeStamp(getCurrentTime());
newBlock.setPreviousBlockHash(latestBlock.getCurrentBlockHash());
newBlock.setCurrentBlockHash(newBlock.calculateHash(newBlock.getBlockData()));
/*
 To make the hash more stronger, we can calculate it along with index, time stamp and previous hash. 
 i.e., this.calculateHash(timeStamp+previousBlockHash+blockData)
*/
blockChain.add(newBlock);
}

public static String getCurrentTime(){
return new SimpleDateFormat("MMM dd,yyyy HH:mm:ss.SSS").format(new Date());
}

}

--------------- BlockChainNetworkTest.java ------------------------------------------------------

package com.dharani.blockchain.simplenetwork;


public class BlockChainNetworkTest {
public static void main(String[] args) {
System.out.println("******** Welcome to the demonstration of simple BlockChain Network ******** \n");
BlockChainNetwork blockChainNetwork = new BlockChainNetwork();
blockChainNetwork.addNewBlock(new Block("{Operations : Credit}"));
blockChainNetwork.addNewBlock(new Block("{Operations : Debit}"));
blockChainNetwork.addNewBlock(new Block("{Operations : Transfer}"));

for(Block blocks : BlockChainNetwork.blockChain){
System.out.println(blocks.toString());
}
}
}

-------------------------------------------------------------------------------------------------------

Get the complete source code here,

-------------------------------------------------------------------------------------------------------

Follow the next post to understand the Block chain network validation concept using the java program.

Post Link : Block Chain Network validation using simple java program

Twitter - Sentiment Analysis using R


# Sentiment Analysis using R



The approach followed here is to count the positive and negative words in each tweet and assign a sentiment score. 

This way, we can ascertain how positive or negative a tweet is. 

Also, there are multiple ways to calculate such scores; here is one formula to perform such calculations.

# Score = Number of positive words - Number of negative words
# If Score > 0, means that the tweet has 'positive sentiment'
# If Score < 0, means that the tweet has 'negative sentiment'
# If Score = 0, means that the tweet has 'neutral sentiment'

The below example collects the data from twitter on "RelianceJio" (@reliancejio).

---------------------------------------------------------------------------------------------------------

install.packages("twitteR",repos='http://cran.us.r-project.org')
install.packages("ROAuth",repos='http://cran.us.r-project.org')
install.packages("plyr",repos='http://cran.us.r-project.org')
install.packages("stringr",repos='http://cran.us.r-project.org')

library(twitteR) ### for fetching the tweets
library(plyr) ## for breaking the data into manageable pieces
library(ROAuth) # for R authentication
library(stringr) # for string processing

reqURL <- "https://api.twitter.com/oauth/request_token"
accessURL <- "http://api.twitter.com/oauth/access_token"
authURL <- "http://api.twitter.com/oauth/authorize"

api_key <- "<your api key>"
api_secret <- "<your api secret>"
access_token <- "<your access token>"
access_token_secret <- "<your access token secret>"
setup_twitter_oauth(api_key,api_secret,access_token,access_token_secret)

# get the api keys and access token , token secret from 
# https://apps.twitter.com/
# note: Login with twitter account and create an app to generate the api key, api secret, access token, access token secret.

posText <- read.delim("positive-words.txt", header=FALSE, stringsAsFactors=FALSE)
negText <- read.delim("negative-words.txt", header=FALSE, stringsAsFactors=FALSE)

# the positive-words.txt and negative-words.txt can be downloaded from this link

https://drive.google.com/open?id=1GLLJa_JU5z8u8IBaW7MBqbNeEoF3FVrV

https://drive.google.com/open?id=185pxU8Ew5577B7U_6zkUeKf2XI5Lt5pl

posText <- posText$V1
posText <- unlist(lapply(posText, function(x) { str_split(x, "\n") }))
negText <- negText$V1
negText <- unlist(lapply(negText, function(x) { str_split(x, "\n") }))
pos.words = c(posText, 'upgrade')

neg.words = c(negText, 'wtf', 'wait', 'waiting','epicfail', 'mechanical')

relianceJio_tweets= searchTwitter('@reliancejio', n=3)

relianceJio_tweets_txt = sapply(relianceJio_tweets, function(t) t$getText() )
#  getText() there for grabbing just the text content of each tweet.

noof_jio_tweets = c(length(relianceJio_tweets_txt))

relianceJio_tweets_txt

getScoreForTweets <- function(tweets_txt){
score <- sapply(tweets_txt, 
                       function(eachTweet){
                         eachTweet1 = gsub("[[:punct:]]", "", eachTweet)
                         eachTweet2 = gsub("[[:cntrl:]]", "", eachTweet1)
                         eachTweet3 = gsub("\\d+", "", eachTweet2)
                         eachTweet4 = sapply(eachTweet3,function(x){tolower(x)})
                         word.list = str_split(eachTweet4, "\\s+")
                         words = unlist(word.list)
                         pos.matches = match(words, pos.words)
                         neg.matches = match(words, neg.words)
                         pos.matches_log = !is.na(pos.matches)
                         neg.matches_log = !is.na(neg.matches)
                       
                         return(sum(pos.matches_log)-sum(neg.matches_log))
                       })
return(score)
}

score <- getScoreForTweets(relianceJio_tweets_txt)

senti <- data.frame(tweets=relianceJio_tweets_txt,score=score)

senti$polarity <- ifelse(senti$score >0,"positive",ifelse(senti$score < 0,"negative",ifelse(senti$score==0,"Neutral",0)))
names(senti)
senti$polarity
senti$score