Install oozie 4.3.0

Install oozie 4.3.0

wget http://www-us.apache.org/dist/hadoop/common/hadoop-2.7.3/hadoop-2.7.3.tar.gz

tar -xvf hadoop-2.7.3.tar.gz

cd hadoop-2.7.3/
vim etc/hadoop/core-site.xml

fs.defaultFS
hdfs://localhost:9000

vim etc/hadoop/hdfs-site.xml

dfs.replication
1

dfs.namenode.name.dir
file:///home/your_user_name/data/hadoop/

sudo apt-get install openssh-server
ssh-keygen -t rsa -P ” -f ~/.ssh/id_rsa
cat ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys
chmod 0600 ~/.ssh/authorized_keys

vim etc/hadoop/hadoop-env.sh
export JAVA_HOME=/opt/jdk

bin/hdfs namenode -forma
sbin/start-dfs.sh

wget http://www-eu.apache.org/dist/oozie/4.3.0/oozie-4.3.0.tar.gz

tar -xvf oozie-4.3.0.tar.gz

cd oozie-4.3.0

./bin/mkdistro.sh -P hadoop-2 -DskipTests

cp -R distro/target/oozie-4.3.0-distro/oozie-4.3.0/ ../oozie

cd ../oozie

mkdir libext
cd libext
wget http://extjs.com/deploy/ext-2.2.zip
cd ..

cp $HADOOP_HOME/share/hadoop/**/*.jar libext/
cp $HADOOP_HOME/share/hadoop/common/*.jar libext/
cp $HADOOP_HOME/share/hadoop/common/lib/*.jar libext/
cp $HADOOP_HOME/share/hadoop/hdfs/lib/*.jar libext/
cp $HADOOP_HOME/share/hadoop/hdfs/*.jar libext/
cp $HADOOP_HOME/share/hadoop/mapreduce/*.jar libext/
cp $HADOOP_HOME/share/hadoop/mapreduce/lib/*.jar libext/
cp $HADOOP_HOME/share/hadoop/yarn/lib/*.jar libext/
cp $HADOOP_HOME/share/hadoop/yarn/*.jar libext/

./bin/oozie-setup.sh prepare-war

vim $HADOOP_HOME/etc/hadoop/core-site.xml

hadoop.proxyuser.your_user_name.hosts
*

hadoop.proxyuser.your_user_name.groups
*

$HADOOP_HOME/sbin/stop-dfs.sh
$HADOOP_HOME/sbin/start-dfs.sh

./bin/oozie-setup.sh sharelib create -fs hdfs://localhost:9000

./bin/ooziedb.sh create -sqlfile oozie.sql -run

vim conf/oozie-site.xml

oozie.service.WorkflowAppService.system.libpath
/user/your_user_name/share/lib/

oozie.service.HadoopAccessorService.hadoop.configurations
*=$HAOOP_HOME/etc/hadoop/

./bin/oozied.sh start

tar -xvf oozie-examples.tar.gz

vim examples/apps/map-reduce/job.properties
nameNode=hdfs://localhost:9000
jobTracker=localhost:10020
oozie.use.system.libpath=true

hadoop fs -put examples hdfs://localhost:9000/user/your_username/examples

$HADOOP_HOME/sbin/mr-jobhistory-daemon.sh –config $HADOOP_CONF_DIR start historyserver

jps

./bin/oozie job -oozie http://localhost:11000/oozie -config examples/apps/map-reduce/job.properties -run

./bin/oozie job -oozie http://localhost:11000/oozie -info 0000000-170408113318091-oozie-fars-W
./bin/oozie job -oozie http://localhost:11000/oozie -log 0000000-170408113318091-oozie-fars-W

WrodCount MapReduce with Scalding

git clone https://github.com/scalding-io/ProgrammingWithScalding

cd ProgrammingWithScalding/chapter2/

mvn clean install

hadoop fs -mkdir -p /data/input

hadoop fs -mkdir -p /data/output

echo “This is a happy day. A day to remember” > /tmp/input.txt

hadoop fs -put /tmp/input.txt /data/input

hadoop jar /root/repo/ProgrammingWithScalding/chapter2/target/chapter2-0-jar-with-dependencies.jar com.twitter.scalding.Tool WordCountJob –local –input /data/input/input.txt –output /data/output/output.txt

cat /data/output/output.txt
a 2
day 1
day. 1
happy 1
is 1
remember 1
this 1
to 1

Wordcount Example With Apache Spark

mkdir wordcount-spark
cd wordcount-spark

mkdir -p src/main/scala

cat <<EOF > build.sbt
name := "wordcount"
version := "1.0"
scalaVersion := "2.11.8"
libraryDependencies += "org.apache.spark" %% "spark-core" % "1.6.0"
EOF

touch src/main/scala/SparkWordCount.scala

import org.apache.spark.SparkContext
import org.apache.spark.SparkContext._
import org.apache.spark.SparkConf

object SparkWordCount {
def main(args: Array[String]) {
// create Spark context with Spark configuration
val sc = new SparkContext(new SparkConf().setAppName("Spark Count"))

// get threshold
val threshold = args(1).toInt

// read in text file and split each document into words
val tokenized = sc.textFile(args(0)).flatMap(_.split(" "))

// count the occurrence of each word
val wordCounts = tokenized.map((_, 1)).reduceByKey(_ + _)

// filter out words with fewer than threshold occurrences
val filtered = wordCounts.filter(_._2 >= threshold)

// count characters
val charCounts = filtered.flatMap(_._1.toCharArray).map((_, 1)).reduceByKey(_ + _)

System.out.println(charCounts.collect().mkString(", "))
}
}

sbt package

cat <<EOF > /tmp/wordcount.txt
Hello world, Hello
EOF

cp target/scala-2.11/workcount_2.11-1.0.jar /tmp/

cd $SPARK_HOME
./bin/spark-submit --master "local[*]" --class SparkWordCount /tmp/wordcount_2.11-1.0.jar /tmp/wordcount.txt 1

Apache Sqoop + Mysql + Hadoop


wget http://www-us.apache.org/dist/sqoop/1.99.6/sqoop-1.99.6-bin-hadoop200.tar.gz

tar -xvf sqoop-1.99.6-bin-hadoop200.tar.gz

cd sqoop-1.99.6-bin-hadoop200

vim server/conf/catalina.properties

common.loader=${catalina.base}/lib,${catalina.base}/lib/*.jar,${catalina.home}/lib,${catalina.home}/lib/*.jar,${catalina.home}/../lib/*.jar,/opt/hadoop-2.6.3/share/hadoop/common/*.jar,/opt/hadoop-2.6.3/share/hadoop/common/lib/*.jar,/opt/hadoop-2.6.3/share/hadoop/hdfs/*.jar,/opt/hadoop-2.6.3/share/hadoop/hdfs/lib/*.jar,/opt/hadoop-2.6.3/share/hadoop/mapreduce/*.jar,/opt/hadoop-2.6.3/share/hadoop/mapreduce/lib/*.jar,/opt/hadoop-2.6.3/share/hadoop/yarn/*.jar,/opt/hadoop-2.6.3/share/hadoop/yarn/lib/*.jar,/usr/lib/hive/lib/*.jar

mkdir lib

vim server/conf/sqoop.properties
org.apache.sqoop.submission.engine.mapreduce.configuration.directory=/opt/hadoop-2.6.3/etc/hadoop

./bin/sqoop2-tool verify
...
Verification was successful.

./bin/sqoop2-server start

$HADOOP_HOME/sbin/start-all.sh

sudo apt-get install mysql-server

mysql -p -uroot -e "create database testdb;"

mysql -p -uroot -e "CREATE TABLE testdb.exampletable (id INT,data VARCHAR(100));"

mysql -p -uroot -e "INSERT INTO testdb.exampletable(id,data) VALUES(1,'test data');"

./bin/sqoop2-shell

sqoop:000> create link -c 1
Creating link for connector with id 1
0 [main] WARN org.apache.hadoop.util.NativeCodeLoader - Unable to load native-hadoop library for your platform... using builtin-java classes where applicable
Please fill following values to create new link object
Name: mysql

Link configuration

JDBC Driver Class: com.mysql.jdbc.Driver
JDBC Connection String: jdbc:mysql://localhost/testdb
Username: root
Password: ****
JDBC Connection Properties:
There are currently 0 values in the map:
entry# protocol=tcp
There are currently 1 values in the map:
protocol = tcp
entry#
New link was successfully created with validation status OK and persistent id 1

sqoop:000> create link -c 3
Creating link for connector with id 3
Please fill following values to create new link object
Name: hdfs

Link configuration

HDFS URI: hdfs://localhost:8020/
Hadoop conf directory: /opt/hadoop-2.6.3/etc/hadoop
New link was successfully created with validation status OK and persistent id 2

sqoop:000> create job -f 1 -t 2
Creating job for links with from id 1 and to id 2
Please fill following values to create new job object
Name: sqoopy

From database configuration

Schema name: testdb
Table name: exampletable
Table SQL statement:
Table column names: id,data
Partition column name: id
Null value allowed for the partition column:
Boundary query:

Incremental read

Check column:
Last value:

To HDFS configuration

Override null value:
Null value:
Output format:
0 : TEXT_FILE
1 : SEQUENCE_FILE
Choose: 0
Compression format:
0 : NONE
1 : DEFAULT
2 : DEFLATE
3 : GZIP
4 : BZIP2
5 : LZO
6 : LZ4
7 : SNAPPY
8 : CUSTOM
Choose: 0
Custom compression format:
Output directory: sqoop
Append mode:

Throttling resources

Extractors:
Loaders:
New job was successfully created with validation status OK and persistent id 1

sqoop:000> start job -j 1

$HADOOP_HOME/bin/hadoop dfs -cat /user//sqoop/ca29e7ba-1155-4614-8529-4e11b0260170.txt

Run Wordcount Mapreduce Example with YARN

// download hadoop-2.6.3.tar.gz
tar -xvf ~/Downloads/hadoop-2.6.3.tar.gz -C ~/opt/
cd ~/opt/hadoop-2.6.3
ssh-keygen
cat ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys

mkdir -p /disk1/hdfs/name
mkdir -p /remote/hdfs/name
mkdir -p /disk1/hdfs/data
mkdir -p /disk2/hdfs/data
mkdir -p /disk1/hdfs/namesecondary
mkdir -p /disk2/hdfs/namesecondary
mkdir -p /disk1/nm-local-dir
mkdir -p /disk2/nm-local-dir

vim etc/hadoop/core-site.xml

<configuration>
<property>
<name>fs.defaultFS</name>
<value>hdfs://localhost/</value>
</property>
</configuration>

vim etc/hadoop/hdfs-site.xml
<configuration>
<property>
<name>dfs.namenode.name.dir</name>
<value>/disk1/hdfs/name,/remote/hdfs/name</value>
</property>
<property>
<name>dfs.datanode.data.dir</name>
<value>/disk1/hdfs/data,/disk2/hdfs/data</value>
</property>
<property> <name>dfs.namenode.checkpoint.dir</name>
<value>/disk1/hdfs/namesecondary,/disk2/hdfs/namesecondary</value>
</property>
</configuration>

vim etc/hadoop/yarn-site.xml

<configuration>
<property>
<name>yarn.resourcemanager.hostname</name>
<value>localhost</value>
</property>
<property>
<name>yarn.nodemanager.local-dirs</name>
<value>/disk1/nm-local-dir,/disk2/nm-local-dir</value>
</property>
<property>
<name>yarn.nodemanager.aux-services</name>
<value>mapreduce_shuffle</value>
</property>
<property>
<name>yarn.nodemanager.resource.memory-mb</name>
<value>16384</value>
</property>
<property>
<name>yarn.nodemanager.resource.cpu-vcores</name>
<value>16</value>
</property>
<property>
<name>yarn.scheduler.capacity.maximum-am-resource-percent</name>
<value>100</value>
</property>

<property>
<name>yarn.scheduler.minimum-allocation-mb</name>
<value>1228</value>
</property>
<property>
<name>yarn.scheduler.maximum-allocation-mb</name>
<value>9830</value>
</property>
<property>
<name>yarn.nodemanager.resource.memory-mb</name>
<value>9830</value>
</property>

</configuration>

cp etc/hadoop/mapred-site.xml.template etc/hadoop/mapred-site.xml

vim etc/hadoop/mapred-site.xml

<configuration>
<property>
<name>mapreduce.framework.name</name>
<value>yarn</value>
</property>

<property>
<name>yarn.app.mapreduce.am.resource.mb</name>
<value>1228</value>
</property>
<property>
<name>yarn.app.mapreduce.am.command-opts</name>
<value>-Xmx983m</value>
</property>
<property>
<name>mapreduce.map.memory.mb</name>
<value>1228</value>
</property>
<property>
<name>mapreduce.reduce.memory.mb</name>
<value>1228</value>
</property>
<property>
<name>mapreduce.map.java.opts</name>
<value>-Xmx983m</value>
</property>
<property>
<name>mapreduce.reduce.java.opts</name>
<value>-Xmx983m</value>
</property>

</configuration>

vim etc/hadoop/hadoop-env.sh

export JAVA_HOME=/opt/jdk

./bin/hdfs namenode -format mycluster
./sbin/start-dfs.sh
./sbin/start-yarn.sh
./bin/hadoop dfs -mkdir -p hdfs://localhost/wc/in
echo “Hello world, Hello” > /tmp/input.txt
./bin/hadoop dfs -copyFromLocal /tmp/inout.txt hdfs://localhost/wc/in
./bin/hadoop jar ./share/hadoop/mapreduce/hadoop-mapreduce-examples-2.6.3.jar wordcount hdfs://localhost/wc/in hdfs://localhost/wc/out

Install Apache Tez 0.7.0

// install jdk 1.7
// install hadoop 2.7
// install maven 3.3
// install npm and bower

wget https://github.com/google/protobuf/releases/download/v2.5.0/protobuf-2.5.0.tar.gz

tar -xvf protobuf-2.5.0.tar.gz

cd protobuf-2.5.0/

sudo apt-get install g++
sudo ./configure
sudo make
sudo make check
sudo make install
sudo ldconfig
cd ../

wget http://apache.lauf-forum.at/tez/0.7.0/apache-tez-0.7.0-src.tar.gz

tar -xvf apache-tez-0.7.0-src.tar.gz

cd apache-tez-0.7.0-src

$HADOOP_HOME/bin/hadoop version
Hadoop 2.7.1

// update hadoop.version in pom.xml to 2.7.1 and protobuf.version to 2.5.0

mvn clean package -DskipTests=true -Dmaven.javadoc.skip=true

$HADOOP_HOME/sbin/start-dfs.sh

$HADOOP_HOME/bin/hadoop dfs -mkdir -p hdfs://localhost/apps/tez

$HADOOP_HOME/bin/hadoop dfs -copyFromLocal tez-dist/target/tez-0.7.0.tar.gz hdfs://localhost/apps/tez

mkdir conf
vim conf/tez-site.xml

<?xml version=”1.0″ encoding=”UTF-8″?>
<?xml-stylesheet type=”text/xsl” href=”configuration.xsl”?>
<configuration>
<property>
<name>tez.lib.uris</name>
<value>${fs.defaultFS}/apps/tez/tez-0.7.0.tar.gz</value>
</property>
</configuration>

export TEZ_HOME=$(pwd)
export TEZ_JARS=$TEZ_HOME/tez-dist/target/tez-0.7.0
export TEZ_CONF_DIR=$TEZ_HOME/conf
export HADOOP_CLASSPATH=$TEZ_CONF_DIR:$TEZ_JARS/*:$TEZ_JARS/lib/*:$HADOOP_CLASSPATH

mkdir in
mkdir out

vim in/test.txt
Hello World!

rm $TEZ_HOME/tez-dist/target/tez-0.7.0/lib/slf4j-log4j12-1.7.5.jar
$HADOOP_HOME/sbin/stop-dfs.sh
$HADOOP_HOME/sbin/start-dfs.sh
$HADOOP_HOME/sbin/stop-yarn.sh
$HADOOP_HOME/sbin/start-yarn.sh

$HADOOP_HOME/bin/hadoop dfs -mkdir -p hdfs://localhost/apps/in
$HADOOP_HOME/bin/hadoop dfs -copyFromLocal in/test.txt hdfs://localhost/apps/in

$HADOOP_HOME/bin/hadoop jar $TEZ_HOME/tez-examples/target/tez-examples-0.7.0.jar orderedwordcount hdfs://localhost/apps/in hdfs://localhost/apps/out

Unit Test for WrodCount MapReduce


import java.io.IOException;
import java.util.Arrays;

import org.apache.hadoop.io.*;
import org.apache.hadoop.mrunit.mapreduce.MapDriver;
import org.apache.hadoop.mrunit.mapreduce.ReduceDriver;
import org.junit.*;

public class WordCountTest {

@Test
public void mapperTest() throws IOException, InterruptedException {
Text value = new Text("Hello");
new MapDriver().withMapper(new TokenizerMapper())
.withInput(new IntWritable(), value).withOutput(new Text("Hello"), new IntWritable(1)).runTest();
}

@Test
public void reducerTest() throws IOException, InterruptedException {
new ReduceDriver().withReducer(new IntSumReducer())
.withInput(new Text("Hello"), Arrays.asList(new IntWritable(1), new IntWritable(1)))
.withOutput(new Text("Hello"), new IntWritable(2)).runTest();
}
}